@arex95/vue-core 1.1.40 → 1.1.43
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/LICENSE +21 -21
- package/README.md +63 -63
- package/dist/composables/axios/index.d.ts +1 -1
- package/dist/composables/axios/useFetch.d.ts +9 -0
- package/dist/index.mjs +125 -56
- package/dist/rest/RestStd.d.ts +49 -25
- package/package.json +80 -76
- package/dist/composables/axios/createFetch.d.ts +0 -9
- package/dist/config/global/tokenConfig.d.ts +0 -31
- package/dist/constants/breakpointEnum.d.ts +0 -31
- package/dist/constants/errorsEnum.d.ts +0 -3
- package/dist/constants/exceptionEnum.d.ts +0 -30
- package/dist/constants/fileTypesEnum.d.ts +0 -25
- package/dist/constants/httpEnum.d.ts +0 -21
- package/dist/constants/index.d.ts +0 -7
- package/dist/constants/keyCodeEnum.d.ts +0 -10
- package/dist/constants/storageEnum.d.ts +0 -50
- package/dist/types/AuthConfig.d.ts +0 -5
- package/dist/types/AuthParams.d.ts +0 -4
- package/dist/types/AuthResponse.d.ts +0 -5
- package/dist/utils/credentials.d.ts +0 -56
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 arexdev
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 arexdev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
# @arex95/vue-core
|
|
2
|
-
|
|
3
|
-
Opinionated Vue Core
|
|
4
|
-
|
|
5
|
-
## Descripción
|
|
6
|
-
|
|
7
|
-
Conjunto de composables y utilidades para Vue.js, diseñado para facilitar el desarrollo de aplicaciones Vue. Proporciona herramientas para manejar peticiones HTTP con Axios. Además, incluye wrappers para TanStack Vue Query, que simplifican la gestión de estados de datos asíncronos, y una implementación estándar para interactuar con APIs RESTful, facilitando la creación, lectura, actualización y eliminación de recursos.
|
|
8
|
-
|
|
9
|
-
## Arquitectura Modular Basada en Servicios
|
|
10
|
-
|
|
11
|
-
Esta arquitectura está diseñada para seguir principios sólidos de `separación de responsabilidades` y `modularidad`, implementando una estructura en la que `los servicios gestionan la lógica de negocio` relacionada con la interacción con APIs, mientras que `las vistas se encargan exclusivamente de la presentación`.
|
|
12
|
-
|
|
13
|
-
## Concepto General de la Arquitectura
|
|
14
|
-
|
|
15
|
-
1. **Separación de Responsabilidades**:
|
|
16
|
-
En este diseño, las vistas no tienen que ocuparse de la lógica de obtención o mutación de datos. Esta responsabilidad está delegada a los **servicios**, que gestionan todo el proceso de interactuar con las APIs, realizar solicitudes HTTP y manipular los modelos. Las vistas simplemente se encargan de la **presentación de los datos** y de gestionar las interacciones del usuario, como capturar eventos o mostrar resultados.
|
|
17
|
-
|
|
18
|
-
- `Vistas`: Su tarea principal es mostrar los datos que obtienen de los servicios. Se centran en la parte visual y en las interacciones de usuario.
|
|
19
|
-
- `Servicios`: Son responsables de gestionar cómo y desde dónde se obtienen los datos. Aquí es donde se realiza toda la lógica de acceso a las APIs, manejo de respuestas y errores, y mutación de modelos.
|
|
20
|
-
|
|
21
|
-
Este enfoque reduce la complejidad de las vistas, las cuales permanecen limpias y fáciles de entender. Cualquier cambio en la forma de hacer las solicitudes (como cambiar la estructura de la API o el cliente HTTP) no requiere modificaciones en las vistas, lo que mejora la mantenibilidad.
|
|
22
|
-
|
|
23
|
-
2. **Desacoplamiento de la Lógica de la API**:
|
|
24
|
-
|
|
25
|
-
Los servicios encapsulan completamente la lógica de interacción con las APIs. Las vistas no necesitan saber nada sobre cómo se hace la solicitud a la API o cómo se gestionan las respuestas. Este desacoplamiento permite que las vistas sean **más limpias** y **menos propensas a errores**, ya que no necesitan manejar la lógica de negocio ni los detalles de las peticiones HTTP. Si en el futuro la forma de interactuar con la API cambia (por ejemplo, si se cambia el cliente HTTP o se agrega un middleware), solo será necesario modificar los servicios, no las vistas.
|
|
26
|
-
|
|
27
|
-
Este enfoque también permite que los servicios sean **reutilizables** en diferentes partes de la aplicación. Por ejemplo, si varias vistas necesitan autenticar al usuario, todas pueden utilizar el servicio `AuthService`, sin necesidad de duplicar la lógica de autenticación.
|
|
28
|
-
|
|
29
|
-
3. **Reusabilidad y Modularidad**:
|
|
30
|
-
|
|
31
|
-
Al centralizar la lógica de negocio en servicios, estos pueden ser fácilmente **reutilizados** en diferentes vistas y componentes de la aplicación. Cada servicio está diseñado para encargarse de una única funcionalidad o módulo del sistema, como la autenticación, gestión de productos, gestión de categorías, etc. Este enfoque modular hace que la aplicación sea **más fácil de escalar**.
|
|
32
|
-
|
|
33
|
-
Además, la modularidad permite que cada servicio evolucione y cambie de forma independiente sin afectar a otros módulos o partes de la aplicación. Si un nuevo servicio debe ser agregado, como uno para manejar un módulo adicional (por ejemplo, pagos o notificaciones), se puede hacer sin interrumpir el flujo de trabajo de los demás servicios.
|
|
34
|
-
|
|
35
|
-
4. **Mejora en la Escalabilidad**:
|
|
36
|
-
|
|
37
|
-
Esta arquitectura facilita la escalabilidad, ya que cualquier servicio puede ser **ampliado o modificado de forma independiente** sin necesidad de reestructurar la aplicación completa. Por ejemplo, si el servicio de productos necesita cambios en la lógica de consulta, esto no afectará al servicio de autenticación o a las vistas que consumen esos servicios. Esta flexibilidad es crucial cuando el sistema crece y se añaden nuevas funcionalidades.
|
|
38
|
-
|
|
39
|
-
5. **Facilidad de Pruebas Unitarias**:
|
|
40
|
-
|
|
41
|
-
Al estar los servicios desacoplados de las vistas, es mucho más fácil realizar **pruebas unitarias** de cada servicio de manera aislada. Las vistas no necesitan ser simuladas ni involucradas en las pruebas de negocio, lo que facilita la escritura de pruebas unitarias puras para la lógica de las APIs y el manejo de los datos.
|
|
42
|
-
|
|
43
|
-
Por ejemplo, el servicio `AuthService` puede probarse por separado para verificar si maneja correctamente el proceso de inicio de sesión o si responde correctamente a los errores de autenticación, sin necesidad de preocuparse por el diseño de las vistas o la interacción con el usuario.
|
|
44
|
-
|
|
45
|
-
6. **Mantenimiento Sostenible**:
|
|
46
|
-
|
|
47
|
-
En un proyecto grande o en evolución, esta arquitectura facilita el mantenimiento del código. Si hay un error relacionado con la autenticación, se puede solucionar directamente en el servicio `AuthService`, sin tener que revisar todas las vistas que consumen este servicio. Esto hace que el código sea más fácil de entender y más fácil de depurar.
|
|
48
|
-
|
|
49
|
-
Además, si es necesario cambiar la lógica de la API (como cambiar el formato de las respuestas), solo es necesario modificar los servicios afectados. Las vistas seguirán funcionando de la misma manera, ya que están desacopladas de esta lógica.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
## Estructura del Proyecto
|
|
53
|
-
|
|
54
|
-
- **src/composables**: Contiene composables reutilizables para Axios, filtros, paginadores y ordenadores.
|
|
55
|
-
- **src/config**: Configuraciones para Axios.
|
|
56
|
-
- **src/constants**: Constantes utilizadas en el proyecto, como enumeraciones de breakpoints, excepciones, tipos de archivos, etc.
|
|
57
|
-
- **src/rest**: Implementación estándar de una interfaz REST para operaciones CRUD. Proporciona una forma sencilla y estandarizada de interactuar con APIs RESTful, facilitando la creación de servicios que pueden realizar operaciones como crear, leer, actualizar y eliminar recursos.
|
|
58
|
-
- **src/types**: Tipos TypeScript utilizados en el proyecto.
|
|
59
|
-
- **src/utils**: Utilidades varias, como funciones para manejar fechas, validaciones, manipulación de strings, etc.
|
|
60
|
-
|
|
61
|
-
## Instalación
|
|
62
|
-
|
|
63
|
-
```sh
|
|
1
|
+
# @arex95/vue-core
|
|
2
|
+
|
|
3
|
+
Opinionated Vue Core
|
|
4
|
+
|
|
5
|
+
## Descripción
|
|
6
|
+
|
|
7
|
+
Conjunto de composables y utilidades para Vue.js, diseñado para facilitar el desarrollo de aplicaciones Vue. Proporciona herramientas para manejar peticiones HTTP con Axios. Además, incluye wrappers para TanStack Vue Query, que simplifican la gestión de estados de datos asíncronos, y una implementación estándar para interactuar con APIs RESTful, facilitando la creación, lectura, actualización y eliminación de recursos.
|
|
8
|
+
|
|
9
|
+
## Arquitectura Modular Basada en Servicios
|
|
10
|
+
|
|
11
|
+
Esta arquitectura está diseñada para seguir principios sólidos de `separación de responsabilidades` y `modularidad`, implementando una estructura en la que `los servicios gestionan la lógica de negocio` relacionada con la interacción con APIs, mientras que `las vistas se encargan exclusivamente de la presentación`.
|
|
12
|
+
|
|
13
|
+
## Concepto General de la Arquitectura
|
|
14
|
+
|
|
15
|
+
1. **Separación de Responsabilidades**:
|
|
16
|
+
En este diseño, las vistas no tienen que ocuparse de la lógica de obtención o mutación de datos. Esta responsabilidad está delegada a los **servicios**, que gestionan todo el proceso de interactuar con las APIs, realizar solicitudes HTTP y manipular los modelos. Las vistas simplemente se encargan de la **presentación de los datos** y de gestionar las interacciones del usuario, como capturar eventos o mostrar resultados.
|
|
17
|
+
|
|
18
|
+
- `Vistas`: Su tarea principal es mostrar los datos que obtienen de los servicios. Se centran en la parte visual y en las interacciones de usuario.
|
|
19
|
+
- `Servicios`: Son responsables de gestionar cómo y desde dónde se obtienen los datos. Aquí es donde se realiza toda la lógica de acceso a las APIs, manejo de respuestas y errores, y mutación de modelos.
|
|
20
|
+
|
|
21
|
+
Este enfoque reduce la complejidad de las vistas, las cuales permanecen limpias y fáciles de entender. Cualquier cambio en la forma de hacer las solicitudes (como cambiar la estructura de la API o el cliente HTTP) no requiere modificaciones en las vistas, lo que mejora la mantenibilidad.
|
|
22
|
+
|
|
23
|
+
2. **Desacoplamiento de la Lógica de la API**:
|
|
24
|
+
|
|
25
|
+
Los servicios encapsulan completamente la lógica de interacción con las APIs. Las vistas no necesitan saber nada sobre cómo se hace la solicitud a la API o cómo se gestionan las respuestas. Este desacoplamiento permite que las vistas sean **más limpias** y **menos propensas a errores**, ya que no necesitan manejar la lógica de negocio ni los detalles de las peticiones HTTP. Si en el futuro la forma de interactuar con la API cambia (por ejemplo, si se cambia el cliente HTTP o se agrega un middleware), solo será necesario modificar los servicios, no las vistas.
|
|
26
|
+
|
|
27
|
+
Este enfoque también permite que los servicios sean **reutilizables** en diferentes partes de la aplicación. Por ejemplo, si varias vistas necesitan autenticar al usuario, todas pueden utilizar el servicio `AuthService`, sin necesidad de duplicar la lógica de autenticación.
|
|
28
|
+
|
|
29
|
+
3. **Reusabilidad y Modularidad**:
|
|
30
|
+
|
|
31
|
+
Al centralizar la lógica de negocio en servicios, estos pueden ser fácilmente **reutilizados** en diferentes vistas y componentes de la aplicación. Cada servicio está diseñado para encargarse de una única funcionalidad o módulo del sistema, como la autenticación, gestión de productos, gestión de categorías, etc. Este enfoque modular hace que la aplicación sea **más fácil de escalar**.
|
|
32
|
+
|
|
33
|
+
Además, la modularidad permite que cada servicio evolucione y cambie de forma independiente sin afectar a otros módulos o partes de la aplicación. Si un nuevo servicio debe ser agregado, como uno para manejar un módulo adicional (por ejemplo, pagos o notificaciones), se puede hacer sin interrumpir el flujo de trabajo de los demás servicios.
|
|
34
|
+
|
|
35
|
+
4. **Mejora en la Escalabilidad**:
|
|
36
|
+
|
|
37
|
+
Esta arquitectura facilita la escalabilidad, ya que cualquier servicio puede ser **ampliado o modificado de forma independiente** sin necesidad de reestructurar la aplicación completa. Por ejemplo, si el servicio de productos necesita cambios en la lógica de consulta, esto no afectará al servicio de autenticación o a las vistas que consumen esos servicios. Esta flexibilidad es crucial cuando el sistema crece y se añaden nuevas funcionalidades.
|
|
38
|
+
|
|
39
|
+
5. **Facilidad de Pruebas Unitarias**:
|
|
40
|
+
|
|
41
|
+
Al estar los servicios desacoplados de las vistas, es mucho más fácil realizar **pruebas unitarias** de cada servicio de manera aislada. Las vistas no necesitan ser simuladas ni involucradas en las pruebas de negocio, lo que facilita la escritura de pruebas unitarias puras para la lógica de las APIs y el manejo de los datos.
|
|
42
|
+
|
|
43
|
+
Por ejemplo, el servicio `AuthService` puede probarse por separado para verificar si maneja correctamente el proceso de inicio de sesión o si responde correctamente a los errores de autenticación, sin necesidad de preocuparse por el diseño de las vistas o la interacción con el usuario.
|
|
44
|
+
|
|
45
|
+
6. **Mantenimiento Sostenible**:
|
|
46
|
+
|
|
47
|
+
En un proyecto grande o en evolución, esta arquitectura facilita el mantenimiento del código. Si hay un error relacionado con la autenticación, se puede solucionar directamente en el servicio `AuthService`, sin tener que revisar todas las vistas que consumen este servicio. Esto hace que el código sea más fácil de entender y más fácil de depurar.
|
|
48
|
+
|
|
49
|
+
Además, si es necesario cambiar la lógica de la API (como cambiar el formato de las respuestas), solo es necesario modificar los servicios afectados. Las vistas seguirán funcionando de la misma manera, ya que están desacopladas de esta lógica.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## Estructura del Proyecto
|
|
53
|
+
|
|
54
|
+
- **src/composables**: Contiene composables reutilizables para Axios, filtros, paginadores y ordenadores.
|
|
55
|
+
- **src/config**: Configuraciones para Axios.
|
|
56
|
+
- **src/constants**: Constantes utilizadas en el proyecto, como enumeraciones de breakpoints, excepciones, tipos de archivos, etc.
|
|
57
|
+
- **src/rest**: Implementación estándar de una interfaz REST para operaciones CRUD. Proporciona una forma sencilla y estandarizada de interactuar con APIs RESTful, facilitando la creación de servicios que pueden realizar operaciones como crear, leer, actualizar y eliminar recursos.
|
|
58
|
+
- **src/types**: Tipos TypeScript utilizados en el proyecto.
|
|
59
|
+
- **src/utils**: Utilidades varias, como funciones para manejar fechas, validaciones, manipulación de strings, etc.
|
|
60
|
+
|
|
61
|
+
## Instalación
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
64
|
npm install @arex95/vue-core
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { UseQueryOptions } from '@tanstack/vue-query';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a fetchFn for Axios requests with an optional custom instance.
|
|
5
|
+
* @param fetchComposable - The fn to use for the request (can be any fetch function).
|
|
6
|
+
* @param axiosCustomInstance - An optional custom Axios instance to use for the request.
|
|
7
|
+
* @returns A function that handles the request using the provided fn.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useFetch(fetchFn: Function, axiosCustomInstance?: AxiosInstance): (axiosRequestConfig: AxiosRequestConfig, options?: UseQueryOptions) => any;
|
package/dist/index.mjs
CHANGED
|
@@ -2926,7 +2926,7 @@ class RestStd {
|
|
|
2926
2926
|
static resource;
|
|
2927
2927
|
static isFormData = false;
|
|
2928
2928
|
static headers = {};
|
|
2929
|
-
static
|
|
2929
|
+
static fetchFn;
|
|
2930
2930
|
/**
|
|
2931
2931
|
* Set global headers for all requests.
|
|
2932
2932
|
* @param headers Object containing headers to be set globally.
|
|
@@ -2950,12 +2950,12 @@ class RestStd {
|
|
|
2950
2950
|
* Fetch a list of items from the server.
|
|
2951
2951
|
*
|
|
2952
2952
|
* @param params Query parameters for filtering the results.
|
|
2953
|
-
* @param options Additional options for the fetch
|
|
2954
|
-
* @returns The result of the fetch
|
|
2953
|
+
* @param options Additional options for the fetch function.
|
|
2954
|
+
* @returns The result of the fetch function (typically a promise).
|
|
2955
2955
|
*/
|
|
2956
2956
|
static getAll(params, options = {}) {
|
|
2957
|
-
return this.
|
|
2958
|
-
method:
|
|
2957
|
+
return this.fetchFn({
|
|
2958
|
+
method: "GET",
|
|
2959
2959
|
url: this.resource,
|
|
2960
2960
|
params,
|
|
2961
2961
|
headers: this.headers,
|
|
@@ -2966,12 +2966,12 @@ class RestStd {
|
|
|
2966
2966
|
*
|
|
2967
2967
|
* @param id The ID of the item to fetch.
|
|
2968
2968
|
* @param params Additional query parameters for the request.
|
|
2969
|
-
* @param options Additional options for the fetch
|
|
2970
|
-
* @returns The result of the fetch
|
|
2969
|
+
* @param options Additional options for the fetch function.
|
|
2970
|
+
* @returns The result of the fetch function (typically a promise).
|
|
2971
2971
|
*/
|
|
2972
2972
|
static getOne(id, params, options = {}) {
|
|
2973
|
-
return this.
|
|
2974
|
-
method:
|
|
2973
|
+
return this.fetchFn({
|
|
2974
|
+
method: "GET",
|
|
2975
2975
|
url: `${this.resource}/${id}`,
|
|
2976
2976
|
params,
|
|
2977
2977
|
headers: this.headers,
|
|
@@ -2981,18 +2981,43 @@ class RestStd {
|
|
|
2981
2981
|
* Create a new item on the server.
|
|
2982
2982
|
*
|
|
2983
2983
|
* @param data The data for the new item to create.
|
|
2984
|
-
* @param options Additional options for the fetch
|
|
2985
|
-
* @returns The result of the fetch
|
|
2984
|
+
* @param options Additional options for the fetch function.
|
|
2985
|
+
* @returns The result of the fetch function (typically a promise).
|
|
2986
2986
|
*/
|
|
2987
2987
|
static create(data, options = {}) {
|
|
2988
2988
|
const transformedData = this.transformData(data);
|
|
2989
|
-
return this.
|
|
2990
|
-
method:
|
|
2989
|
+
return this.fetchFn({
|
|
2990
|
+
method: "POST",
|
|
2991
2991
|
url: this.resource,
|
|
2992
2992
|
data: transformedData,
|
|
2993
2993
|
headers: {
|
|
2994
2994
|
...this.headers,
|
|
2995
|
-
|
|
2995
|
+
"Content-Type": this.isFormData
|
|
2996
|
+
? ContentTypeEnum.FORM_DATA
|
|
2997
|
+
: ContentTypeEnum.JSON,
|
|
2998
|
+
},
|
|
2999
|
+
}, options);
|
|
3000
|
+
}
|
|
3001
|
+
/**
|
|
3002
|
+
* Create multiple new items on the server.
|
|
3003
|
+
*
|
|
3004
|
+
* @param data An array of data for the items to create.
|
|
3005
|
+
* @param options Additional options for the fetch function.
|
|
3006
|
+
* @returns The result of the fetch function.
|
|
3007
|
+
*/
|
|
3008
|
+
static bulkCreate(data, options = {}) {
|
|
3009
|
+
const transformedData = this.isFormData
|
|
3010
|
+
? data.map((item) => this.transformData(item))
|
|
3011
|
+
: data;
|
|
3012
|
+
return this.fetchFn({
|
|
3013
|
+
method: "POST",
|
|
3014
|
+
url: `${this.resource}/bulk`,
|
|
3015
|
+
data: transformedData,
|
|
3016
|
+
headers: {
|
|
3017
|
+
...this.headers,
|
|
3018
|
+
"Content-Type": this.isFormData
|
|
3019
|
+
? ContentTypeEnum.FORM_DATA
|
|
3020
|
+
: ContentTypeEnum.JSON,
|
|
2996
3021
|
},
|
|
2997
3022
|
}, options);
|
|
2998
3023
|
}
|
|
@@ -3001,18 +3026,43 @@ class RestStd {
|
|
|
3001
3026
|
*
|
|
3002
3027
|
* @param id The ID of the item to update.
|
|
3003
3028
|
* @param data The updated data for the item.
|
|
3004
|
-
* @param options Additional options for the fetch
|
|
3005
|
-
* @returns The result of the fetch
|
|
3029
|
+
* @param options Additional options for the fetch function.
|
|
3030
|
+
* @returns The result of the fetch function (typically a promise).
|
|
3006
3031
|
*/
|
|
3007
3032
|
static update(id, data, options = {}) {
|
|
3008
3033
|
const transformedData = this.transformData(data);
|
|
3009
|
-
return this.
|
|
3010
|
-
method:
|
|
3034
|
+
return this.fetchFn({
|
|
3035
|
+
method: "PUT",
|
|
3011
3036
|
url: `${this.resource}/${id}`,
|
|
3012
3037
|
data: transformedData,
|
|
3013
3038
|
headers: {
|
|
3014
3039
|
...this.headers,
|
|
3015
|
-
|
|
3040
|
+
"Content-Type": this.isFormData
|
|
3041
|
+
? ContentTypeEnum.FORM_DATA
|
|
3042
|
+
: ContentTypeEnum.JSON,
|
|
3043
|
+
},
|
|
3044
|
+
}, options);
|
|
3045
|
+
}
|
|
3046
|
+
/**
|
|
3047
|
+
* Update multiple existing items on the server.
|
|
3048
|
+
*
|
|
3049
|
+
* @param data An array of data for the items to update (each object should have an ID).
|
|
3050
|
+
* @param options Additional options for the fetch function.
|
|
3051
|
+
* @returns The result of the fetch function.
|
|
3052
|
+
*/
|
|
3053
|
+
static bulkUpdate(data, options = {}) {
|
|
3054
|
+
const transformedData = this.isFormData
|
|
3055
|
+
? data.map((item) => this.transformData(item))
|
|
3056
|
+
: data;
|
|
3057
|
+
return this.fetchFn({
|
|
3058
|
+
method: "PUT",
|
|
3059
|
+
url: `${this.resource}/bulk`,
|
|
3060
|
+
data: transformedData,
|
|
3061
|
+
headers: {
|
|
3062
|
+
...this.headers,
|
|
3063
|
+
"Content-Type": this.isFormData
|
|
3064
|
+
? ContentTypeEnum.FORM_DATA
|
|
3065
|
+
: ContentTypeEnum.JSON,
|
|
3016
3066
|
},
|
|
3017
3067
|
}, options);
|
|
3018
3068
|
}
|
|
@@ -3021,18 +3071,20 @@ class RestStd {
|
|
|
3021
3071
|
*
|
|
3022
3072
|
* @param id The ID of the item to update.
|
|
3023
3073
|
* @param data The updated data for the item.
|
|
3024
|
-
* @param options Additional options for the fetch
|
|
3025
|
-
* @returns The result of the fetch
|
|
3074
|
+
* @param options Additional options for the fetch function.
|
|
3075
|
+
* @returns The result of the fetch function (typically a promise).
|
|
3026
3076
|
*/
|
|
3027
3077
|
static patch(id, data, options = {}) {
|
|
3028
3078
|
const transformedData = this.transformData(data);
|
|
3029
|
-
return this.
|
|
3030
|
-
method:
|
|
3079
|
+
return this.fetchFn({
|
|
3080
|
+
method: "PATCH",
|
|
3031
3081
|
url: `${this.resource}/${id}`,
|
|
3032
3082
|
data: transformedData,
|
|
3033
3083
|
headers: {
|
|
3034
3084
|
...this.headers,
|
|
3035
|
-
|
|
3085
|
+
"Content-Type": this.isFormData
|
|
3086
|
+
? ContentTypeEnum.FORM_DATA
|
|
3087
|
+
: ContentTypeEnum.JSON,
|
|
3036
3088
|
},
|
|
3037
3089
|
}, options);
|
|
3038
3090
|
}
|
|
@@ -3040,47 +3092,39 @@ class RestStd {
|
|
|
3040
3092
|
* Delete an item from the server.
|
|
3041
3093
|
*
|
|
3042
3094
|
* @param id The ID of the item to delete.
|
|
3043
|
-
* @param options Additional options for the fetch
|
|
3044
|
-
* @returns The result of the fetch
|
|
3095
|
+
* @param options Additional options for the fetch function.
|
|
3096
|
+
* @returns The result of the fetch function (typically a promise).
|
|
3045
3097
|
*/
|
|
3046
3098
|
static delete(id, options = {}) {
|
|
3047
|
-
return this.
|
|
3048
|
-
method:
|
|
3099
|
+
return this.fetchFn({
|
|
3100
|
+
method: "DELETE",
|
|
3049
3101
|
url: `${this.resource}/${id}`,
|
|
3050
3102
|
headers: this.headers,
|
|
3051
3103
|
}, options);
|
|
3052
3104
|
}
|
|
3053
3105
|
/**
|
|
3054
|
-
*
|
|
3106
|
+
* Delete multiple items from the server by their IDs.
|
|
3055
3107
|
*
|
|
3056
|
-
* @param
|
|
3057
|
-
* @param
|
|
3058
|
-
* @
|
|
3059
|
-
* @param options Additional options for the fetch composable.
|
|
3060
|
-
* @returns The result of the fetch composable (typically a promise).
|
|
3108
|
+
* @param ids An array of IDs of the items to delete.
|
|
3109
|
+
* @param options Additional options for the fetch function.
|
|
3110
|
+
* @returns The result of the fetch function.
|
|
3061
3111
|
*/
|
|
3062
|
-
static
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
data: transformedData,
|
|
3069
|
-
headers: {
|
|
3070
|
-
...this.headers,
|
|
3071
|
-
'Content-Type': this.isFormData ? ContentTypeEnum.FORM_DATA : ContentTypeEnum.JSON,
|
|
3072
|
-
},
|
|
3112
|
+
static bulkDelete(ids, options = {}) {
|
|
3113
|
+
return this.fetchFn({
|
|
3114
|
+
method: "DELETE",
|
|
3115
|
+
url: `${this.resource}/bulk`,
|
|
3116
|
+
data: { ids },
|
|
3117
|
+
headers: this.headers,
|
|
3073
3118
|
}, options);
|
|
3074
3119
|
}
|
|
3075
3120
|
/**
|
|
3076
|
-
*
|
|
3077
|
-
* It calls either create or update based on the data.
|
|
3121
|
+
* Upsert method that decides whether to create or update based on the presence of 'id'.
|
|
3078
3122
|
*
|
|
3079
3123
|
* @param data The data for the item to create or update.
|
|
3080
|
-
* @param options Additional options for the fetch
|
|
3081
|
-
* @returns The result of the fetch
|
|
3124
|
+
* @param options Additional options for the fetch function.
|
|
3125
|
+
* @returns The result of the fetch function (typically a promise).
|
|
3082
3126
|
*/
|
|
3083
|
-
static
|
|
3127
|
+
static upsert(data, options = {}) {
|
|
3084
3128
|
if (data.id) {
|
|
3085
3129
|
return this.update(data.id, data, options);
|
|
3086
3130
|
}
|
|
@@ -3088,6 +3132,31 @@ class RestStd {
|
|
|
3088
3132
|
return this.create(data, options);
|
|
3089
3133
|
}
|
|
3090
3134
|
}
|
|
3135
|
+
/**
|
|
3136
|
+
* Custom request method for more flexibility.
|
|
3137
|
+
*
|
|
3138
|
+
* @param method HTTP method (GET, POST, etc.).
|
|
3139
|
+
* @param url The custom URL for the request.
|
|
3140
|
+
* @param params Query parameters.
|
|
3141
|
+
* @param data Request body data.
|
|
3142
|
+
* @param options Additional options for the fetch function.
|
|
3143
|
+
* @returns The result of the fetch function (typically a promise).
|
|
3144
|
+
*/
|
|
3145
|
+
static customRequest(method, url, params, data, options = {}) {
|
|
3146
|
+
const transformedData = this.transformData(data);
|
|
3147
|
+
return this.fetchFn({
|
|
3148
|
+
method: method,
|
|
3149
|
+
url: url,
|
|
3150
|
+
params: params,
|
|
3151
|
+
data: transformedData,
|
|
3152
|
+
headers: {
|
|
3153
|
+
...this.headers,
|
|
3154
|
+
"Content-Type": this.isFormData
|
|
3155
|
+
? ContentTypeEnum.FORM_DATA
|
|
3156
|
+
: ContentTypeEnum.JSON,
|
|
3157
|
+
},
|
|
3158
|
+
}, options);
|
|
3159
|
+
}
|
|
3091
3160
|
}
|
|
3092
3161
|
|
|
3093
3162
|
/**
|
|
@@ -3107,15 +3176,15 @@ async function axiosFetch(axios, axiosRequest) {
|
|
|
3107
3176
|
}
|
|
3108
3177
|
|
|
3109
3178
|
/**
|
|
3110
|
-
* Creates a
|
|
3111
|
-
* @param fetchComposable - The
|
|
3179
|
+
* Creates a fetchFn for Axios requests with an optional custom instance.
|
|
3180
|
+
* @param fetchComposable - The fn to use for the request (can be any fetch function).
|
|
3112
3181
|
* @param axiosCustomInstance - An optional custom Axios instance to use for the request.
|
|
3113
|
-
* @returns A function that handles the request using the provided
|
|
3182
|
+
* @returns A function that handles the request using the provided fn.
|
|
3114
3183
|
*/
|
|
3115
|
-
function
|
|
3184
|
+
function useFetch(fetchFn, axiosCustomInstance) {
|
|
3116
3185
|
const instance = axiosCustomInstance || getConfiguredAxiosInstance();
|
|
3117
3186
|
return (axiosRequestConfig, options) => {
|
|
3118
|
-
return
|
|
3187
|
+
return fetchFn(instance, axiosRequestConfig, options);
|
|
3119
3188
|
};
|
|
3120
3189
|
}
|
|
3121
3190
|
|
|
@@ -3579,4 +3648,4 @@ const ArexVueCore = {
|
|
|
3579
3648
|
},
|
|
3580
3649
|
};
|
|
3581
3650
|
|
|
3582
|
-
export { AppTypes, ArchiveTypes, ArexVueCore, AudioTypes, AxiosService, ContentTypeEnum, DocumentTypes, ERROR_MESSAGES, ERROR_STYLES, ErrorEnum, ErrorMessages, ErrorStyles, ExceptionEnum, FontTypes, ImageTypes, KeyCodeEnum, OtherTypes, RestStd, ScreenBreakpoint, ScreenSize, StorageKeyEnum, StorageTypeEnum, TextTypes, VideoTypes, ab2hex, addCustomKeyboardShortcut, addDays, addDoubleClickListener, addKeyListener, ageAtDate, axiosFetch, blobToFormData, bufferToBlob, calculateAge, cleanCredentials, clickOutside, compareObject, configAppKey, configAxios, configEndpoints, configRefreshTokenPaths, configSession, configTokenKeys, configTokenPaths, copyToClipboard, countWords,
|
|
3651
|
+
export { AppTypes, ArchiveTypes, ArexVueCore, AudioTypes, AxiosService, ContentTypeEnum, DocumentTypes, ERROR_MESSAGES, ERROR_STYLES, ErrorEnum, ErrorMessages, ErrorStyles, ExceptionEnum, FontTypes, ImageTypes, KeyCodeEnum, OtherTypes, RestStd, ScreenBreakpoint, ScreenSize, StorageKeyEnum, StorageTypeEnum, TextTypes, VideoTypes, ab2hex, addCustomKeyboardShortcut, addDays, addDoubleClickListener, addKeyListener, ageAtDate, axiosFetch, blobToFormData, bufferToBlob, calculateAge, cleanCredentials, clickOutside, compareObject, configAppKey, configAxios, configEndpoints, configRefreshTokenPaths, configSession, configTokenKeys, configTokenPaths, copyToClipboard, countWords, createKeyMap, customShortcut, daysBetween, daysToNextBirthday, debounce, debounceAsync, debounceAsyncValidator, debounceAsyncWithImmediate, debounceLeading, debounceLeadingTrailing, debounceTrailing, decrypt, deepClone, deepEqual, deepMerge, detectKeyHold, disableCopy, disableF12Key, disableMouseButtons, disableRightClick, disableSpecificKeys, downloadBlob, enableMouseButtons, enableRightClick, enableSpecificKeys, encrypt, exportToCSV, exportToExcel, exportToJSON, exportToText, exportToXML, extractAndValidateTokens, filterObjectByKeys, flattenObject, formDataToObject, formatDate, generateRandomString, getAppKey, getAuthRefreshToken, getAuthToken, getConfiguredAxiosInstance, getDecryptedItem, getEndOfMonth, getEndpointsConfig, getObjectDifferences, getObjectKeys, getQueryParam, getRefreshTokenPathsConfig, getSessionConfig, getSessionId, getSessionPersistence, getStartOfMonth, getTokenConfig, getTokenPathsConfig, handleError, hasNestedProperties, hex2ab, importKey, isEmptyObject, isLeapYear, isStrongPassword, isValidAge, isValidCreditCard, isValidDate, isValidEmail, isValidExpiryDate, isValidHexColor, isValidHexColorAlpha, isValidHexNumber, isValidIP, isValidPhoneNumber, isValidSSN, isValidTime, isValidURL, isValidUsername, isValidZIP, lowerFirst, objectToFormData, objectToFormDataEnhanced, objectToQueryString, openWindow, parseDate, proxyToPlainObject, readFileAsDataURL, readFileAsText, refreshTokens, registerKeyboardShortcuts, removeAccent, removeClickOutside, removeCustomKeyboardShortcut, removeCustomShortcuts, removeDoubleClickListener, removeEmptyProperties, removeKeyListeners, replaceAll, reverseString, safeGet, screenMap, scrollToTop, simulateKeyPress, stopDetectingKeyHold, storeAuthRefreshToken, storeAuthToken, storeEncryptedItem, storeTokens, stringToBlob, subtractDays, throttle, toCamelCase, toKebabCase, toggleTabNavigation, truncateString, unregisterKeyboardShortcuts, upperFirst, useAuth, useBreakpoint, useFetch, useFilter, usePagination, useSorter, useVueQuery, validateAlphanumeric, validateLetters, validateNumbers, verifyAuth };
|
package/dist/rest/RestStd.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export declare class RestStd {
|
|
|
2
2
|
static resource: string;
|
|
3
3
|
static isFormData: boolean;
|
|
4
4
|
static headers: Record<string, string>;
|
|
5
|
-
static
|
|
5
|
+
static fetchFn: Function;
|
|
6
6
|
/**
|
|
7
7
|
* Set global headers for all requests.
|
|
8
8
|
* @param headers Object containing headers to be set globally.
|
|
@@ -18,8 +18,8 @@ export declare class RestStd {
|
|
|
18
18
|
* Fetch a list of items from the server.
|
|
19
19
|
*
|
|
20
20
|
* @param params Query parameters for filtering the results.
|
|
21
|
-
* @param options Additional options for the fetch
|
|
22
|
-
* @returns The result of the fetch
|
|
21
|
+
* @param options Additional options for the fetch function.
|
|
22
|
+
* @returns The result of the fetch function (typically a promise).
|
|
23
23
|
*/
|
|
24
24
|
static getAll<T>(params?: Record<string, any>, options?: object): any;
|
|
25
25
|
/**
|
|
@@ -27,61 +27,85 @@ export declare class RestStd {
|
|
|
27
27
|
*
|
|
28
28
|
* @param id The ID of the item to fetch.
|
|
29
29
|
* @param params Additional query parameters for the request.
|
|
30
|
-
* @param options Additional options for the fetch
|
|
31
|
-
* @returns The result of the fetch
|
|
30
|
+
* @param options Additional options for the fetch function.
|
|
31
|
+
* @returns The result of the fetch function (typically a promise).
|
|
32
32
|
*/
|
|
33
33
|
static getOne<T>(id: string | number, params?: Record<string, any>, options?: object): any;
|
|
34
34
|
/**
|
|
35
35
|
* Create a new item on the server.
|
|
36
36
|
*
|
|
37
37
|
* @param data The data for the new item to create.
|
|
38
|
-
* @param options Additional options for the fetch
|
|
39
|
-
* @returns The result of the fetch
|
|
38
|
+
* @param options Additional options for the fetch function.
|
|
39
|
+
* @returns The result of the fetch function (typically a promise).
|
|
40
40
|
*/
|
|
41
41
|
static create<T>(data: any, options?: object): any;
|
|
42
|
+
/**
|
|
43
|
+
* Create multiple new items on the server.
|
|
44
|
+
*
|
|
45
|
+
* @param data An array of data for the items to create.
|
|
46
|
+
* @param options Additional options for the fetch function.
|
|
47
|
+
* @returns The result of the fetch function.
|
|
48
|
+
*/
|
|
49
|
+
static bulkCreate<T>(data: any[], options?: object): any;
|
|
42
50
|
/**
|
|
43
51
|
* Update an existing item on the server.
|
|
44
52
|
*
|
|
45
53
|
* @param id The ID of the item to update.
|
|
46
54
|
* @param data The updated data for the item.
|
|
47
|
-
* @param options Additional options for the fetch
|
|
48
|
-
* @returns The result of the fetch
|
|
55
|
+
* @param options Additional options for the fetch function.
|
|
56
|
+
* @returns The result of the fetch function (typically a promise).
|
|
49
57
|
*/
|
|
50
58
|
static update<T>(id: string | number, data: any, options?: object): any;
|
|
59
|
+
/**
|
|
60
|
+
* Update multiple existing items on the server.
|
|
61
|
+
*
|
|
62
|
+
* @param data An array of data for the items to update (each object should have an ID).
|
|
63
|
+
* @param options Additional options for the fetch function.
|
|
64
|
+
* @returns The result of the fetch function.
|
|
65
|
+
*/
|
|
66
|
+
static bulkUpdate<T>(data: any[], options?: object): any;
|
|
51
67
|
/**
|
|
52
68
|
* Partially update an existing item on the server.
|
|
53
69
|
*
|
|
54
70
|
* @param id The ID of the item to update.
|
|
55
71
|
* @param data The updated data for the item.
|
|
56
|
-
* @param options Additional options for the fetch
|
|
57
|
-
* @returns The result of the fetch
|
|
72
|
+
* @param options Additional options for the fetch function.
|
|
73
|
+
* @returns The result of the fetch function (typically a promise).
|
|
58
74
|
*/
|
|
59
75
|
static patch<T>(id: string | number, data: any, options?: object): any;
|
|
60
76
|
/**
|
|
61
77
|
* Delete an item from the server.
|
|
62
78
|
*
|
|
63
79
|
* @param id The ID of the item to delete.
|
|
64
|
-
* @param options Additional options for the fetch
|
|
65
|
-
* @returns The result of the fetch
|
|
80
|
+
* @param options Additional options for the fetch function.
|
|
81
|
+
* @returns The result of the fetch function (typically a promise).
|
|
66
82
|
*/
|
|
67
83
|
static delete<T>(id: string | number, options?: object): any;
|
|
68
84
|
/**
|
|
69
|
-
*
|
|
85
|
+
* Delete multiple items from the server by their IDs.
|
|
70
86
|
*
|
|
71
|
-
* @param
|
|
72
|
-
* @param
|
|
73
|
-
* @
|
|
74
|
-
* @param options Additional options for the fetch composable.
|
|
75
|
-
* @returns The result of the fetch composable (typically a promise).
|
|
87
|
+
* @param ids An array of IDs of the items to delete.
|
|
88
|
+
* @param options Additional options for the fetch function.
|
|
89
|
+
* @returns The result of the fetch function.
|
|
76
90
|
*/
|
|
77
|
-
static
|
|
91
|
+
static bulkDelete<T>(ids: (string | number)[], options?: object): any;
|
|
78
92
|
/**
|
|
79
|
-
*
|
|
80
|
-
* It calls either create or update based on the data.
|
|
93
|
+
* Upsert method that decides whether to create or update based on the presence of 'id'.
|
|
81
94
|
*
|
|
82
95
|
* @param data The data for the item to create or update.
|
|
83
|
-
* @param options Additional options for the fetch
|
|
84
|
-
* @returns The result of the fetch
|
|
96
|
+
* @param options Additional options for the fetch function.
|
|
97
|
+
* @returns The result of the fetch function (typically a promise).
|
|
98
|
+
*/
|
|
99
|
+
static upsert<T>(data: any, options?: object): any;
|
|
100
|
+
/**
|
|
101
|
+
* Custom request method for more flexibility.
|
|
102
|
+
*
|
|
103
|
+
* @param method HTTP method (GET, POST, etc.).
|
|
104
|
+
* @param url The custom URL for the request.
|
|
105
|
+
* @param params Query parameters.
|
|
106
|
+
* @param data Request body data.
|
|
107
|
+
* @param options Additional options for the fetch function.
|
|
108
|
+
* @returns The result of the fetch function (typically a promise).
|
|
85
109
|
*/
|
|
86
|
-
static
|
|
110
|
+
static customRequest<T>(method: string, url: string, params?: Record<string, any>, data?: any, options?: object): any;
|
|
87
111
|
}
|
package/package.json
CHANGED
|
@@ -1,76 +1,80 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@arex95/vue-core",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Opinionated Vue Core",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"exports": {
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
},
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
|
|
76
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@arex95/vue-core",
|
|
3
|
+
"version": "1.1.43",
|
|
4
|
+
"description": "Opinionated Vue Core",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rollup -c",
|
|
21
|
+
"changelog": "conventional-changelog -p angular -o CHANGELOG.md -r 0",
|
|
22
|
+
"release": "npm version patch && npm run changelog && git add CHANGELOG.md package.json pnpm-lock.yaml && git commit -m \"chore(release): update changelog\" && git push && npm publish --access public",
|
|
23
|
+
"test": "vitest",
|
|
24
|
+
"test:watch": "vitest --watch",
|
|
25
|
+
"test:ui": "vitest --ui"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/Arex95/npm-arex-core.git"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"vue",
|
|
33
|
+
"composables",
|
|
34
|
+
"core",
|
|
35
|
+
"npm"
|
|
36
|
+
],
|
|
37
|
+
"author": "Arturo Rafael Serrano Girón",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@tanstack/vue-query": ">=5.0.0",
|
|
41
|
+
"@vueuse/core": ">=12.8.2",
|
|
42
|
+
"axios": ">=1.6.0",
|
|
43
|
+
"jwt-decode": "^4.0.0",
|
|
44
|
+
"uuid": ">=11.1.0",
|
|
45
|
+
"vue": ">=3.0.0",
|
|
46
|
+
"vue-router": ">=4.5.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@eslint/js": "^9.23.0",
|
|
50
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
51
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
52
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
53
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
54
|
+
"@types/crypto-js": "^4.2.2",
|
|
55
|
+
"@types/node": "^22.13.10",
|
|
56
|
+
"@vitest/spy": "^3.2.3",
|
|
57
|
+
"@vitest/ui": "^3.2.3",
|
|
58
|
+
"@vue/test-utils": "^2.4.6",
|
|
59
|
+
"conventional-changelog-cli": "^5.0.0",
|
|
60
|
+
"eslint": "^9.23.0",
|
|
61
|
+
"eslint-plugin-vue": "^10.0.0",
|
|
62
|
+
"globals": "^16.0.0",
|
|
63
|
+
"jsdom": "^26.1.0",
|
|
64
|
+
"rollup": "^4.35.0",
|
|
65
|
+
"ts-node": "^10.9.2",
|
|
66
|
+
"tslib": "^2.8.1",
|
|
67
|
+
"typescript": "^5.8.2",
|
|
68
|
+
"typescript-eslint": "^8.28.0",
|
|
69
|
+
"vitest": "^3.2.3"
|
|
70
|
+
},
|
|
71
|
+
"dependencies": {
|
|
72
|
+
"@tanstack/vue-query": ">=5.0.0",
|
|
73
|
+
"@vueuse/core": ">=12.8.2",
|
|
74
|
+
"axios": ">=1.6.0",
|
|
75
|
+
"jwt-decode": "^4.0.0",
|
|
76
|
+
"uuid": ">=11.1.0",
|
|
77
|
+
"vue": ">=3.0.0",
|
|
78
|
+
"vue-router": ">=4.5.0"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { UseQueryOptions } from '@tanstack/vue-query';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a fetchComposable for Axios requests with an optional custom instance.
|
|
5
|
-
* @param fetchComposable - The composable to use for the request (can be any fetch function).
|
|
6
|
-
* @param axiosCustomInstance - An optional custom Axios instance to use for the request.
|
|
7
|
-
* @returns A function that handles the request using the provided composable.
|
|
8
|
-
*/
|
|
9
|
-
export declare function createFetch(fetchComposable: Function, axiosCustomInstance?: AxiosInstance): (axiosRequestConfig: AxiosRequestConfig, options?: UseQueryOptions) => any;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { TokenConfig } from "@/types";
|
|
2
|
-
/**
|
|
3
|
-
* Configures the global keys for access and refresh tokens.
|
|
4
|
-
* Once set, they cannot be modified.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} accessTokenKey - The name of the access token key.
|
|
7
|
-
* @param {string} refreshTokenKey - The name of the refresh token key.
|
|
8
|
-
*
|
|
9
|
-
* @returns {void} Does not return anything but freezes the token configuration object.
|
|
10
|
-
*/
|
|
11
|
-
export declare function configTokens(accessTokenKey: string, refreshTokenKey: string): void;
|
|
12
|
-
/**
|
|
13
|
-
* Retrieves the current token configuration.
|
|
14
|
-
*
|
|
15
|
-
* @returns {TokenConfig} The configuration of the access and refresh token keys.
|
|
16
|
-
*/
|
|
17
|
-
export declare function getTokenConfig(): TokenConfig;
|
|
18
|
-
/**
|
|
19
|
-
* Sets the secret key for use in authentication.
|
|
20
|
-
*
|
|
21
|
-
* @param {string} key - The new secret key.
|
|
22
|
-
*
|
|
23
|
-
* @returns {void} Does not return anything, but updates the secret key.
|
|
24
|
-
*/
|
|
25
|
-
export declare function setSecretKey(key: string): void;
|
|
26
|
-
/**
|
|
27
|
-
* Retrieves the current secret key.
|
|
28
|
-
*
|
|
29
|
-
* @returns {string} The configured secret key.
|
|
30
|
-
*/
|
|
31
|
-
export declare function getSecretKey(): string;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Object defining available screen sizes as constants.
|
|
3
|
-
* @readonly
|
|
4
|
-
*/
|
|
5
|
-
export declare const sizeEnum: {
|
|
6
|
-
readonly XS: "XS";
|
|
7
|
-
readonly SM: "SM";
|
|
8
|
-
readonly MD: "MD";
|
|
9
|
-
readonly LG: "LG";
|
|
10
|
-
readonly XL: "XL";
|
|
11
|
-
readonly XXL: "XXL";
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Object defining breakpoints for design based on screen width.
|
|
15
|
-
* Values are in pixels.
|
|
16
|
-
* @readonly
|
|
17
|
-
*/
|
|
18
|
-
export declare const screenEnum: {
|
|
19
|
-
readonly XS: 480;
|
|
20
|
-
readonly SM: 576;
|
|
21
|
-
readonly MD: 768;
|
|
22
|
-
readonly LG: 992;
|
|
23
|
-
readonly XL: 1200;
|
|
24
|
-
readonly XXL: 1600;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Map that associates each screen size defined in `sizeEnum` with its corresponding pixel value from `screenEnum`.
|
|
28
|
-
* @type {Map<typeof sizeEnum[keyof typeof sizeEnum], number>}
|
|
29
|
-
*/
|
|
30
|
-
declare const screenMap: Map<"XS" | "SM" | "MD" | "LG" | "XL" | "XXL", number>;
|
|
31
|
-
export { screenMap };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Object defining various exception codes.
|
|
3
|
-
* @readonly
|
|
4
|
-
*/
|
|
5
|
-
export declare const ExceptionEnum: {
|
|
6
|
-
/**
|
|
7
|
-
* HTTP status code for page access forbidden.
|
|
8
|
-
*/
|
|
9
|
-
readonly PAGE_NOT_ACCESS: 403;
|
|
10
|
-
/**
|
|
11
|
-
* HTTP status code for page not found.
|
|
12
|
-
*/
|
|
13
|
-
readonly PAGE_NOT_FOUND: 404;
|
|
14
|
-
/**
|
|
15
|
-
* HTTP status code for general server error.
|
|
16
|
-
*/
|
|
17
|
-
readonly ERROR: 500;
|
|
18
|
-
/**
|
|
19
|
-
* HTTP status code for bad request.
|
|
20
|
-
*/
|
|
21
|
-
readonly BAD_REQUEST: 406;
|
|
22
|
-
/**
|
|
23
|
-
* Custom error code for network errors.
|
|
24
|
-
*/
|
|
25
|
-
readonly NET_WORK_ERROR: 10000;
|
|
26
|
-
/**
|
|
27
|
-
* Custom code indicating no data on the page, not actually an exception page.
|
|
28
|
-
*/
|
|
29
|
-
readonly PAGE_NOT_DATA: 10100;
|
|
30
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Object defining various image MIME types.
|
|
3
|
-
* @readonly
|
|
4
|
-
*/
|
|
5
|
-
export declare const ImageTypes: {
|
|
6
|
-
readonly apng: "image/apng";
|
|
7
|
-
readonly bmp: "image/bmp";
|
|
8
|
-
readonly gif: "image/gif";
|
|
9
|
-
readonly jpeg: "image/jpeg";
|
|
10
|
-
readonly pjpeg: "image/pjpeg";
|
|
11
|
-
readonly png: "image/png";
|
|
12
|
-
readonly svg: "image/svg+xml";
|
|
13
|
-
readonly tiff: "image/tiff";
|
|
14
|
-
readonly webp: "image/webp";
|
|
15
|
-
readonly xicon: "image/x-icon";
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Object defining various file meta types.
|
|
19
|
-
* @readonly
|
|
20
|
-
*/
|
|
21
|
-
export declare const FileMetaTypes: {
|
|
22
|
-
readonly images: "image/*";
|
|
23
|
-
readonly audios: "audio/*";
|
|
24
|
-
readonly videos: "video/*";
|
|
25
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Object representing different content types for HTTP headers.
|
|
3
|
-
* @readonly
|
|
4
|
-
*/
|
|
5
|
-
export declare const ContentTypeEnum: {
|
|
6
|
-
/**
|
|
7
|
-
* Content type for JSON.
|
|
8
|
-
* @constant
|
|
9
|
-
*/
|
|
10
|
-
readonly JSON: "application/json;charset=UTF-8";
|
|
11
|
-
/**
|
|
12
|
-
* Content type for URL-encoded form data.
|
|
13
|
-
* @constant
|
|
14
|
-
*/
|
|
15
|
-
readonly FORM_URLENCODED: "application/x-www-form-urlencoded;charset=UTF-8";
|
|
16
|
-
/**
|
|
17
|
-
* Content type for multipart form data with file uploads.
|
|
18
|
-
* @constant
|
|
19
|
-
*/
|
|
20
|
-
readonly FORM_DATA: "multipart/form-data;charset=UTF-8";
|
|
21
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Key used for storing the authentication token.
|
|
3
|
-
* @constant {string}
|
|
4
|
-
*/
|
|
5
|
-
export declare const TOKEN_KEY = "TOKEN__";
|
|
6
|
-
/**
|
|
7
|
-
* Key used for storing the locale information.
|
|
8
|
-
* @constant {string}
|
|
9
|
-
*/
|
|
10
|
-
export declare const LOCALE_KEY = "LOCALE__";
|
|
11
|
-
/**
|
|
12
|
-
* Key used for storing user information.
|
|
13
|
-
* @constant {string}
|
|
14
|
-
*/
|
|
15
|
-
export declare const USER_INFO_KEY = "USER__INFO__";
|
|
16
|
-
/**
|
|
17
|
-
* Key used for storing role information.
|
|
18
|
-
* @constant {string}
|
|
19
|
-
*/
|
|
20
|
-
export declare const ROLES_KEY = "ROLES__KEY__";
|
|
21
|
-
/**
|
|
22
|
-
* Key used for storing project configuration.
|
|
23
|
-
* @constant {string}
|
|
24
|
-
*/
|
|
25
|
-
export declare const PROJ_CFG_KEY = "PROJ__CFG__KEY__";
|
|
26
|
-
/**
|
|
27
|
-
* Key used for storing lock information.
|
|
28
|
-
* @constant {string}
|
|
29
|
-
*/
|
|
30
|
-
export declare const LOCK_INFO_KEY = "LOCK__INFO__KEY__";
|
|
31
|
-
/**
|
|
32
|
-
* Key used for base global local cache.
|
|
33
|
-
* @constant {string}
|
|
34
|
-
*/
|
|
35
|
-
export declare const APP_LOCAL_CACHE_KEY = "COMMON__LOCAL__KEY";
|
|
36
|
-
/**
|
|
37
|
-
* Key used for base global session cache.
|
|
38
|
-
* @constant {string}
|
|
39
|
-
*/
|
|
40
|
-
export declare const APP_SESSION_CACHE_KEY = "COMMON__SESSION__KEY";
|
|
41
|
-
/**
|
|
42
|
-
* Object defining types of cache storage.
|
|
43
|
-
* @readonly
|
|
44
|
-
*/
|
|
45
|
-
export declare const CacheTypeEnum: {
|
|
46
|
-
/** Represents session storage */
|
|
47
|
-
readonly SESSION: 0;
|
|
48
|
-
/** Represents local storage */
|
|
49
|
-
readonly LOCAL: 1;
|
|
50
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { LocationPreference } from "@/types/SessionConfig";
|
|
2
|
-
/**
|
|
3
|
-
* Clears all stored authentication data (access and refresh tokens)
|
|
4
|
-
* from either sessionStorage, localStorage, or both based on the provided location preference.
|
|
5
|
-
*
|
|
6
|
-
* @param {LocationPreference} location - The storage preference ('local' for localStorage, 'session' for sessionStorage, 'any' for both).
|
|
7
|
-
* @returns {Promise<void>} A promise that resolves when all relevant storage items are removed.
|
|
8
|
-
*/
|
|
9
|
-
export declare const cleanCredentials: (location: LocationPreference) => Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
* Retrieves the authentication token (access token) from storage, decrypting it
|
|
12
|
-
* using the provided secret key and based on the specified session preference.
|
|
13
|
-
*
|
|
14
|
-
* @param {string} secretKey - The secret key used for decryption.
|
|
15
|
-
* @param {SessionPreference} preference - The storage preference ('local' for localStorage, 'session' for sessionStorage).
|
|
16
|
-
* @returns {Promise<string | null>} A promise that resolves with the decrypted access token, or null if not found.
|
|
17
|
-
*/
|
|
18
|
-
export declare const getAuthToken: (secretKey: string, location: LocationPreference) => Promise<string | null>;
|
|
19
|
-
/**
|
|
20
|
-
* Retrieves the authentication refresh token from storage, decrypting it
|
|
21
|
-
* using the provided secret key and based on the specified session preference.
|
|
22
|
-
*
|
|
23
|
-
* @param {string} secretKey - The secret key used for decryption.
|
|
24
|
-
* @param {SessionPreference} preference - The storage preference ('local' for localStorage, 'session' for sessionStorage).
|
|
25
|
-
* @returns {Promise<string | null>} A promise that resolves with the decrypted refresh token, or null if not found.
|
|
26
|
-
*/
|
|
27
|
-
export declare const getAuthRefreshToken: (secretKey: string, location: LocationPreference) => Promise<string | null>;
|
|
28
|
-
/**
|
|
29
|
-
* Stores the authentication token (access token) in storage after encrypting it,
|
|
30
|
-
* based on the specified session preference.
|
|
31
|
-
*
|
|
32
|
-
* @param {string} token - The access token to store.
|
|
33
|
-
* @param {string} secretKey - The secret key used for encryption.
|
|
34
|
-
* @param {SessionPreference} preference - The storage preference ('local' for localStorage, 'session' for sessionStorage).
|
|
35
|
-
* @returns {Promise<void>} A promise that resolves when the token is successfully stored.
|
|
36
|
-
*/
|
|
37
|
-
export declare const storeAuthToken: (token: string, secretKey: string, location: LocationPreference) => Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Stores the authentication refresh token in storage after encrypting it,
|
|
40
|
-
* based on the specified session preference.
|
|
41
|
-
*
|
|
42
|
-
* @param {string} token - The refresh token to store.
|
|
43
|
-
* @param {string} secretKey - The secret key used for encryption.
|
|
44
|
-
* @param {SessionPreference} preference - The storage preference ('local' for localStorage, 'session' for sessionStorage).
|
|
45
|
-
* @returns {Promise<void>} A promise that resolves when the token is successfully stored.
|
|
46
|
-
*/
|
|
47
|
-
export declare const storeAuthRefreshToken: (token: string, secretKey: string, location: LocationPreference) => Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* Verifies the validity and expiration of the current authentication token.
|
|
50
|
-
* If the token is missing, invalid, or expired, appropriate errors are thrown and credentials are cleaned.
|
|
51
|
-
*
|
|
52
|
-
* @returns {Promise<boolean>} True if the token is valid and unexpired.
|
|
53
|
-
* @throws {Error} "TOKEN_MISSING" if no token is found, "TOKEN_EXPIRED" if the token has expired,
|
|
54
|
-
* "TOKEN_INVALID" if the token format is invalid.
|
|
55
|
-
*/
|
|
56
|
-
export declare const verifyAuth: () => Promise<boolean>;
|