flysoft-react-ui 0.2.1 → 0.2.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/index.css +1 -1
- package/dist/index.js.map +1 -1
- package/dist/services/apiClient.d.ts +38 -11
- package/dist/services/apiClient.d.ts.map +1 -1
- package/dist/services/apiClient.js +23 -14
- package/package.json +1 -1
|
@@ -9,9 +9,36 @@ interface FileResponse {
|
|
|
9
9
|
data: Blob;
|
|
10
10
|
headers: AxiosResponse["headers"];
|
|
11
11
|
}
|
|
12
|
+
interface GetRequestOptions {
|
|
13
|
+
url: string;
|
|
14
|
+
params?: Record<string, unknown>;
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
interface PostRequestOptions {
|
|
18
|
+
url: string;
|
|
19
|
+
body?: unknown;
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
interface PutRequestOptions {
|
|
23
|
+
url: string;
|
|
24
|
+
body?: unknown;
|
|
25
|
+
headers?: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
interface DeleteRequestOptions {
|
|
28
|
+
url: string;
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
}
|
|
31
|
+
interface FileRequestOptions {
|
|
32
|
+
url: string;
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
}
|
|
12
35
|
interface UploadFileOptions {
|
|
13
|
-
|
|
14
|
-
|
|
36
|
+
url: string;
|
|
37
|
+
files: FileList | File[];
|
|
38
|
+
headers?: {
|
|
39
|
+
paramName?: string;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
};
|
|
15
42
|
}
|
|
16
43
|
declare class ApiClientService {
|
|
17
44
|
private instance;
|
|
@@ -35,39 +62,39 @@ declare class ApiClientService {
|
|
|
35
62
|
/**
|
|
36
63
|
* Realiza una petición GET
|
|
37
64
|
*/
|
|
38
|
-
get<T = unknown>(
|
|
65
|
+
get<T = unknown>(options: GetRequestOptions): Promise<T>;
|
|
39
66
|
/**
|
|
40
67
|
* Realiza una petición POST
|
|
41
68
|
*/
|
|
42
|
-
post<T = unknown>(
|
|
69
|
+
post<T = unknown>(options: PostRequestOptions): Promise<T>;
|
|
43
70
|
/**
|
|
44
71
|
* Realiza una petición PUT
|
|
45
72
|
*/
|
|
46
|
-
put<T = unknown>(
|
|
73
|
+
put<T = unknown>(options: PutRequestOptions): Promise<T>;
|
|
47
74
|
/**
|
|
48
75
|
* Realiza una petición DELETE
|
|
49
76
|
*/
|
|
50
|
-
del<T = unknown>(
|
|
77
|
+
del<T = unknown>(options: DeleteRequestOptions): Promise<T>;
|
|
51
78
|
/**
|
|
52
79
|
* Obtiene un archivo como Blob
|
|
53
80
|
*/
|
|
54
|
-
getFile(
|
|
81
|
+
getFile(options: FileRequestOptions): Promise<FileResponse>;
|
|
55
82
|
/**
|
|
56
83
|
* Obtiene un archivo y retorna su URL como objeto
|
|
57
84
|
*/
|
|
58
|
-
getFileAsUrl(
|
|
85
|
+
getFileAsUrl(options: FileRequestOptions): Promise<string>;
|
|
59
86
|
/**
|
|
60
87
|
* Abre un archivo en una nueva ventana
|
|
61
88
|
*/
|
|
62
|
-
openFile(
|
|
89
|
+
openFile(options: FileRequestOptions): Promise<void>;
|
|
63
90
|
/**
|
|
64
91
|
* Descarga un archivo
|
|
65
92
|
*/
|
|
66
|
-
downloadFile(
|
|
93
|
+
downloadFile(options: FileRequestOptions): Promise<void>;
|
|
67
94
|
/**
|
|
68
95
|
* Sube uno o más archivos usando FormData
|
|
69
96
|
*/
|
|
70
|
-
uploadFile<T = unknown>(
|
|
97
|
+
uploadFile<T = unknown>(options: UploadFileOptions): Promise<T>;
|
|
71
98
|
}
|
|
72
99
|
/**
|
|
73
100
|
* Cliente de API compartido con todas las funciones de HTTP
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiClient.d.ts","sourceRoot":"","sources":["../../src/services/apiClient.ts"],"names":[],"mappings":"AAAA,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OAEG;IACG,YAAY,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB9D;;OAEG;IACG,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,CAAC;CAgBtE;AAKD;;GAEG;AACH,eAAO,MAAM,SAAS,kBAAe,CAAC;AAEtC;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,eAAe,KAAG,gBAE1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,yBAAyB,GACpC,UAAU,aAAa,GAAG,SAAS,KAClC,IAEF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,QAAO,IAE9C,CAAC"}
|
|
@@ -19,7 +19,8 @@ class ApiClientService {
|
|
|
19
19
|
const token = this.tokenProvider?.();
|
|
20
20
|
if (token && config.headers) {
|
|
21
21
|
// Manejo compatible con diferentes versiones de axios
|
|
22
|
-
if ("set" in config.headers &&
|
|
22
|
+
if ("set" in config.headers &&
|
|
23
|
+
typeof config.headers.set === "function") {
|
|
23
24
|
config.headers.set("Authorization", `Bearer ${token}`);
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
@@ -64,21 +65,24 @@ class ApiClientService {
|
|
|
64
65
|
Object.assign(this.instance.defaults.headers.common || {}, config.headers);
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
|
-
async axiosRequest({ method, url, headers, body, }) {
|
|
68
|
+
async axiosRequest({ method, url, headers, body, params, }) {
|
|
68
69
|
return await this.instance({
|
|
69
70
|
method,
|
|
70
71
|
headers,
|
|
71
72
|
url,
|
|
72
73
|
data: body,
|
|
74
|
+
params,
|
|
73
75
|
});
|
|
74
76
|
}
|
|
75
77
|
/**
|
|
76
78
|
* Realiza una petición GET
|
|
77
79
|
*/
|
|
78
|
-
async get(
|
|
80
|
+
async get(options) {
|
|
81
|
+
const { url, params, headers } = options;
|
|
79
82
|
const response = await this.axiosRequest({
|
|
80
83
|
method: "GET",
|
|
81
84
|
url,
|
|
85
|
+
params,
|
|
82
86
|
headers,
|
|
83
87
|
});
|
|
84
88
|
return response.data;
|
|
@@ -86,7 +90,8 @@ class ApiClientService {
|
|
|
86
90
|
/**
|
|
87
91
|
* Realiza una petición POST
|
|
88
92
|
*/
|
|
89
|
-
async post(
|
|
93
|
+
async post(options) {
|
|
94
|
+
const { url, body, headers } = options;
|
|
90
95
|
const response = await this.axiosRequest({
|
|
91
96
|
method: "POST",
|
|
92
97
|
url,
|
|
@@ -98,7 +103,8 @@ class ApiClientService {
|
|
|
98
103
|
/**
|
|
99
104
|
* Realiza una petición PUT
|
|
100
105
|
*/
|
|
101
|
-
async put(
|
|
106
|
+
async put(options) {
|
|
107
|
+
const { url, body, headers } = options;
|
|
102
108
|
const response = await this.axiosRequest({
|
|
103
109
|
method: "PUT",
|
|
104
110
|
url,
|
|
@@ -110,7 +116,8 @@ class ApiClientService {
|
|
|
110
116
|
/**
|
|
111
117
|
* Realiza una petición DELETE
|
|
112
118
|
*/
|
|
113
|
-
async del(
|
|
119
|
+
async del(options) {
|
|
120
|
+
const { url, headers } = options;
|
|
114
121
|
const response = await this.axiosRequest({
|
|
115
122
|
method: "DELETE",
|
|
116
123
|
url,
|
|
@@ -121,7 +128,8 @@ class ApiClientService {
|
|
|
121
128
|
/**
|
|
122
129
|
* Obtiene un archivo como Blob
|
|
123
130
|
*/
|
|
124
|
-
async getFile(
|
|
131
|
+
async getFile(options) {
|
|
132
|
+
const { url, headers = {} } = options;
|
|
125
133
|
const response = await this.instance.get(url, {
|
|
126
134
|
responseType: "blob",
|
|
127
135
|
headers,
|
|
@@ -134,24 +142,24 @@ class ApiClientService {
|
|
|
134
142
|
/**
|
|
135
143
|
* Obtiene un archivo y retorna su URL como objeto
|
|
136
144
|
*/
|
|
137
|
-
async getFileAsUrl(
|
|
138
|
-
const { data } = await this.getFile(
|
|
145
|
+
async getFileAsUrl(options) {
|
|
146
|
+
const { data } = await this.getFile(options);
|
|
139
147
|
const blob = new Blob([data], { type: data.type });
|
|
140
148
|
return URL.createObjectURL(blob);
|
|
141
149
|
}
|
|
142
150
|
/**
|
|
143
151
|
* Abre un archivo en una nueva ventana
|
|
144
152
|
*/
|
|
145
|
-
async openFile(
|
|
146
|
-
const { data } = await this.getFile(
|
|
153
|
+
async openFile(options) {
|
|
154
|
+
const { data } = await this.getFile(options);
|
|
147
155
|
const urlData = URL.createObjectURL(data);
|
|
148
156
|
window.open(urlData);
|
|
149
157
|
}
|
|
150
158
|
/**
|
|
151
159
|
* Descarga un archivo
|
|
152
160
|
*/
|
|
153
|
-
async downloadFile(
|
|
154
|
-
const { data, headers: dataHeaders } = await this.getFile(
|
|
161
|
+
async downloadFile(options) {
|
|
162
|
+
const { data, headers: dataHeaders } = await this.getFile(options);
|
|
155
163
|
const contentDisposition = dataHeaders["content-disposition"] || dataHeaders["Content-Disposition"];
|
|
156
164
|
const fileName = contentDisposition
|
|
157
165
|
?.split("filename=")[1]
|
|
@@ -168,7 +176,8 @@ class ApiClientService {
|
|
|
168
176
|
/**
|
|
169
177
|
* Sube uno o más archivos usando FormData
|
|
170
178
|
*/
|
|
171
|
-
async uploadFile(
|
|
179
|
+
async uploadFile(options) {
|
|
180
|
+
const { url, files, headers } = options;
|
|
172
181
|
const formData = new FormData();
|
|
173
182
|
const { paramName = "file", ...newHeaders } = headers || {};
|
|
174
183
|
const fileArray = Array.from(files);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flysoft-react-ui",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A modern React UI component library with Tailwind CSS, TypeScript, and FontAwesome 5. Includes forms, layouts, themes, and templates for rapid development.",
|
|
7
7
|
"keywords": [
|