flysoft-react-ui 0.2.2 → 0.2.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/index.css +1 -1
- package/dist/index.js.map +1 -1
- package/dist/services/apiClient.d.ts +38 -14
- package/dist/services/apiClient.d.ts.map +1 -1
- package/dist/services/apiClient.js +19 -15
- 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;
|
|
@@ -34,43 +61,40 @@ declare class ApiClientService {
|
|
|
34
61
|
private axiosRequest;
|
|
35
62
|
/**
|
|
36
63
|
* Realiza una petición GET
|
|
37
|
-
* @param url URL del endpoint
|
|
38
|
-
* @param params Parámetros opcionales que se enviarán como query string
|
|
39
|
-
* @param headers Headers opcionales de la petición
|
|
40
64
|
*/
|
|
41
|
-
get<T = unknown>(
|
|
65
|
+
get<T = unknown>(options: GetRequestOptions): Promise<T>;
|
|
42
66
|
/**
|
|
43
67
|
* Realiza una petición POST
|
|
44
68
|
*/
|
|
45
|
-
post<T = unknown>(
|
|
69
|
+
post<T = unknown>(options: PostRequestOptions): Promise<T>;
|
|
46
70
|
/**
|
|
47
71
|
* Realiza una petición PUT
|
|
48
72
|
*/
|
|
49
|
-
put<T = unknown>(
|
|
73
|
+
put<T = unknown>(options: PutRequestOptions): Promise<T>;
|
|
50
74
|
/**
|
|
51
75
|
* Realiza una petición DELETE
|
|
52
76
|
*/
|
|
53
|
-
del<T = unknown>(
|
|
77
|
+
del<T = unknown>(options: DeleteRequestOptions): Promise<T>;
|
|
54
78
|
/**
|
|
55
79
|
* Obtiene un archivo como Blob
|
|
56
80
|
*/
|
|
57
|
-
getFile(
|
|
81
|
+
getFile(options: FileRequestOptions): Promise<FileResponse>;
|
|
58
82
|
/**
|
|
59
83
|
* Obtiene un archivo y retorna su URL como objeto
|
|
60
84
|
*/
|
|
61
|
-
getFileAsUrl(
|
|
85
|
+
getFileAsUrl(options: FileRequestOptions): Promise<string>;
|
|
62
86
|
/**
|
|
63
87
|
* Abre un archivo en una nueva ventana
|
|
64
88
|
*/
|
|
65
|
-
openFile(
|
|
89
|
+
openFile(options: FileRequestOptions): Promise<void>;
|
|
66
90
|
/**
|
|
67
91
|
* Descarga un archivo
|
|
68
92
|
*/
|
|
69
|
-
downloadFile(
|
|
93
|
+
downloadFile(options: FileRequestOptions): Promise<void>;
|
|
70
94
|
/**
|
|
71
95
|
* Sube uno o más archivos usando FormData
|
|
72
96
|
*/
|
|
73
|
-
uploadFile<T = unknown>(
|
|
97
|
+
uploadFile<T = unknown>(options: UploadFileOptions): Promise<T>;
|
|
74
98
|
}
|
|
75
99
|
/**
|
|
76
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,OAAc,EAAsB,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtE,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,KAAK,aAAa,GAAG,MAAM,MAAM,GAAG,SAAS,CAAC;AAE9C,UAAU,YAAY;IACpB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,
|
|
1
|
+
{"version":3,"file":"apiClient.d.ts","sourceRoot":"","sources":["../../src/services/apiClient.ts"],"names":[],"mappings":"AAAA,OAAc,EAAsB,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtE,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,KAAK,aAAa,GAAG,MAAM,MAAM,GAAG,SAAS,CAAC;AAE9C,UAAU,YAAY;IACpB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,UAAU,kBAAkB;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,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AAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAWhE;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,CAAC;IAW9D;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,CAAC,CAAC;IAUjE;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAYjE;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAMhE;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1D;;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"}
|
|
@@ -17,6 +17,7 @@ class ApiClientService {
|
|
|
17
17
|
// Request interceptor para inyectar el token automáticamente
|
|
18
18
|
this.instance.interceptors.request.use((config) => {
|
|
19
19
|
const token = this.tokenProvider?.();
|
|
20
|
+
console.log("PASA POR SETUP", token);
|
|
20
21
|
if (token && config.headers) {
|
|
21
22
|
// Manejo compatible con diferentes versiones de axios
|
|
22
23
|
if ("set" in config.headers &&
|
|
@@ -76,11 +77,9 @@ class ApiClientService {
|
|
|
76
77
|
}
|
|
77
78
|
/**
|
|
78
79
|
* Realiza una petición GET
|
|
79
|
-
* @param url URL del endpoint
|
|
80
|
-
* @param params Parámetros opcionales que se enviarán como query string
|
|
81
|
-
* @param headers Headers opcionales de la petición
|
|
82
80
|
*/
|
|
83
|
-
async get(
|
|
81
|
+
async get(options) {
|
|
82
|
+
const { url, params, headers } = options;
|
|
84
83
|
const response = await this.axiosRequest({
|
|
85
84
|
method: "GET",
|
|
86
85
|
url,
|
|
@@ -92,7 +91,8 @@ class ApiClientService {
|
|
|
92
91
|
/**
|
|
93
92
|
* Realiza una petición POST
|
|
94
93
|
*/
|
|
95
|
-
async post(
|
|
94
|
+
async post(options) {
|
|
95
|
+
const { url, body, headers } = options;
|
|
96
96
|
const response = await this.axiosRequest({
|
|
97
97
|
method: "POST",
|
|
98
98
|
url,
|
|
@@ -104,7 +104,8 @@ class ApiClientService {
|
|
|
104
104
|
/**
|
|
105
105
|
* Realiza una petición PUT
|
|
106
106
|
*/
|
|
107
|
-
async put(
|
|
107
|
+
async put(options) {
|
|
108
|
+
const { url, body, headers } = options;
|
|
108
109
|
const response = await this.axiosRequest({
|
|
109
110
|
method: "PUT",
|
|
110
111
|
url,
|
|
@@ -116,7 +117,8 @@ class ApiClientService {
|
|
|
116
117
|
/**
|
|
117
118
|
* Realiza una petición DELETE
|
|
118
119
|
*/
|
|
119
|
-
async del(
|
|
120
|
+
async del(options) {
|
|
121
|
+
const { url, headers } = options;
|
|
120
122
|
const response = await this.axiosRequest({
|
|
121
123
|
method: "DELETE",
|
|
122
124
|
url,
|
|
@@ -127,7 +129,8 @@ class ApiClientService {
|
|
|
127
129
|
/**
|
|
128
130
|
* Obtiene un archivo como Blob
|
|
129
131
|
*/
|
|
130
|
-
async getFile(
|
|
132
|
+
async getFile(options) {
|
|
133
|
+
const { url, headers = {} } = options;
|
|
131
134
|
const response = await this.instance.get(url, {
|
|
132
135
|
responseType: "blob",
|
|
133
136
|
headers,
|
|
@@ -140,24 +143,24 @@ class ApiClientService {
|
|
|
140
143
|
/**
|
|
141
144
|
* Obtiene un archivo y retorna su URL como objeto
|
|
142
145
|
*/
|
|
143
|
-
async getFileAsUrl(
|
|
144
|
-
const { data } = await this.getFile(
|
|
146
|
+
async getFileAsUrl(options) {
|
|
147
|
+
const { data } = await this.getFile(options);
|
|
145
148
|
const blob = new Blob([data], { type: data.type });
|
|
146
149
|
return URL.createObjectURL(blob);
|
|
147
150
|
}
|
|
148
151
|
/**
|
|
149
152
|
* Abre un archivo en una nueva ventana
|
|
150
153
|
*/
|
|
151
|
-
async openFile(
|
|
152
|
-
const { data } = await this.getFile(
|
|
154
|
+
async openFile(options) {
|
|
155
|
+
const { data } = await this.getFile(options);
|
|
153
156
|
const urlData = URL.createObjectURL(data);
|
|
154
157
|
window.open(urlData);
|
|
155
158
|
}
|
|
156
159
|
/**
|
|
157
160
|
* Descarga un archivo
|
|
158
161
|
*/
|
|
159
|
-
async downloadFile(
|
|
160
|
-
const { data, headers: dataHeaders } = await this.getFile(
|
|
162
|
+
async downloadFile(options) {
|
|
163
|
+
const { data, headers: dataHeaders } = await this.getFile(options);
|
|
161
164
|
const contentDisposition = dataHeaders["content-disposition"] || dataHeaders["Content-Disposition"];
|
|
162
165
|
const fileName = contentDisposition
|
|
163
166
|
?.split("filename=")[1]
|
|
@@ -174,7 +177,8 @@ class ApiClientService {
|
|
|
174
177
|
/**
|
|
175
178
|
* Sube uno o más archivos usando FormData
|
|
176
179
|
*/
|
|
177
|
-
async uploadFile(
|
|
180
|
+
async uploadFile(options) {
|
|
181
|
+
const { url, files, headers } = options;
|
|
178
182
|
const formData = new FormData();
|
|
179
183
|
const { paramName = "file", ...newHeaders } = headers || {};
|
|
180
184
|
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.4",
|
|
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": [
|