@arex95/vue-core 1.1.43 → 3.0.1

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.
Files changed (74) hide show
  1. package/README.md +90 -57
  2. package/dist/composables/auth/useAuth.d.ts +20 -6
  3. package/dist/composables/axios/axiosFetch.d.ts +7 -5
  4. package/dist/composables/axios/index.d.ts +0 -1
  5. package/dist/composables/axios/useFetch.d.ts +14 -5
  6. package/dist/composables/breakpoints/useBreakpoint.d.ts +11 -2
  7. package/dist/composables/filters/useFilter.d.ts +13 -8
  8. package/dist/composables/monitoring/useApiActivity.d.ts +17 -6
  9. package/dist/composables/monitoring/useUserActivity.d.ts +20 -5
  10. package/dist/composables/paginators/usePaginator.d.ts +13 -5
  11. package/dist/composables/sorters/useSorter.d.ts +13 -7
  12. package/dist/config/auth/authFetcher.d.ts +30 -0
  13. package/dist/config/auth/index.d.ts +1 -0
  14. package/dist/config/axios/axiosConfig.d.ts +30 -0
  15. package/dist/config/axios/axiosInstance.d.ts +15 -1
  16. package/dist/config/global/endpointsConfig.d.ts +9 -13
  17. package/dist/config/global/keyConfig.d.ts +7 -10
  18. package/dist/config/global/sessionConfig.d.ts +15 -17
  19. package/dist/config/global/tokenPathsConfig.d.ts +17 -18
  20. package/dist/config/global/tokensConfig.d.ts +9 -9
  21. package/dist/config/index.d.ts +1 -0
  22. package/dist/enums/breakpointsEnums.d.ts +7 -4
  23. package/dist/enums/errorsEnums.d.ts +26 -19
  24. package/dist/enums/fileTypesEnums.d.ts +33 -1
  25. package/dist/enums/httpExceptionsEnums.d.ts +3 -1
  26. package/dist/enums/keyCodesEnums.d.ts +2 -4
  27. package/dist/enums/storageEnums.d.ts +4 -4
  28. package/dist/errors/AuthError.d.ts +10 -0
  29. package/dist/errors/BaseError.d.ts +16 -0
  30. package/dist/errors/NetworkError.d.ts +9 -0
  31. package/dist/errors/ServerError.d.ts +10 -0
  32. package/dist/errors/ValidationError.d.ts +14 -0
  33. package/dist/errors/index.d.ts +5 -0
  34. package/dist/fetchers/axios.d.ts +22 -0
  35. package/dist/fetchers/index.d.ts +2 -0
  36. package/dist/fetchers/ofetch.d.ts +33 -0
  37. package/dist/index.d.ts +8 -6
  38. package/dist/index.mjs +1631 -875
  39. package/dist/rest/RestStd.d.ts +146 -102
  40. package/dist/services/credentials.d.ts +24 -29
  41. package/dist/services/extractTokens.d.ts +7 -6
  42. package/dist/services/refreshTokens.d.ts +11 -12
  43. package/dist/services/storeTokens.d.ts +8 -6
  44. package/dist/types/AppKeyConfig.d.ts +7 -0
  45. package/dist/types/ArexVueCoreOptions.d.ts +20 -0
  46. package/dist/types/Auth.d.ts +15 -0
  47. package/dist/types/AxiosOptionsParameter.d.ts +14 -7
  48. package/dist/types/AxiosServiceOptions.d.ts +9 -0
  49. package/dist/types/DecodedJwtPayload.d.ts +12 -0
  50. package/dist/types/EndpointsConfig.d.ts +7 -0
  51. package/dist/types/ErrorType.d.ts +4 -2
  52. package/dist/types/ExtendedQueryOptions.d.ts +10 -0
  53. package/dist/types/Fetcher.d.ts +24 -0
  54. package/dist/types/RestStdOptions.d.ts +62 -0
  55. package/dist/types/SessionConfig.d.ts +25 -1
  56. package/dist/types/TokenConfig.d.ts +7 -0
  57. package/dist/types/TokenValidationResult.d.ts +7 -0
  58. package/dist/types/index.d.ts +2 -0
  59. package/dist/utils/browser.d.ts +20 -14
  60. package/dist/utils/dates.d.ts +47 -34
  61. package/dist/utils/debounces.d.ts +54 -32
  62. package/dist/utils/encryption.d.ts +28 -24
  63. package/dist/utils/errors.d.ts +27 -8
  64. package/dist/utils/exports.d.ts +24 -19
  65. package/dist/utils/files.d.ts +33 -25
  66. package/dist/utils/index.d.ts +3 -0
  67. package/dist/utils/io.d.ts +70 -54
  68. package/dist/utils/objects.d.ts +78 -60
  69. package/dist/utils/retry.d.ts +8 -0
  70. package/dist/utils/ssr.d.ts +27 -0
  71. package/dist/utils/storage.d.ts +20 -14
  72. package/dist/utils/strings.d.ts +42 -31
  73. package/dist/utils/validations.d.ts +76 -57
  74. package/package.json +7 -16
@@ -1,111 +1,155 @@
1
+ import { Fetcher } from "@/types/Fetcher";
2
+ import { GetAllOptions, GetOneOptions, CreateOptions, UpdateOptions, PatchOptions, DeleteOptions, BulkCreateOptions, BulkUpdateOptions, BulkDeleteOptions, UpsertOptions, CustomRequestOptions } from "@/types/RestStdOptions";
3
+ import { RetryConfig } from "@/utils/retry";
4
+ /**
5
+ * A standardized RESTful class that provides a generic interface for performing
6
+ * CRUD (Create, Read, Update, Delete) operations on a specific API resource. It is designed
7
+ * to be extended directly from your models. It supports both JSON and FormData requests.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * export class Role extends RestStd {
12
+ * static override resource = 'roles';
13
+ * static fetchFn = createAxiosFetcher(axiosInstance);
14
+ * }
15
+ *
16
+ * const roles = await Role.getAll();
17
+ * ```
18
+ */
1
19
  export declare class RestStd {
20
+ /**
21
+ * The resource endpoint. MUST be overridden in subclasses.
22
+ * @example static override resource = 'users';
23
+ */
2
24
  static resource: string;
25
+ /** A flag to determine if request data should be sent as FormData. Defaults to `false`. */
3
26
  static isFormData: boolean;
27
+ /** A record of global headers to be sent with every request. */
4
28
  static headers: Record<string, string>;
5
- static fetchFn: Function;
29
+ /** The function used to make the actual HTTP requests. Optional, defaults to Axios fetcher. */
30
+ static fetchFn?: Fetcher;
31
+ /** Retry configuration for failed requests. Optional. */
32
+ static retryConfig?: RetryConfig;
6
33
  /**
7
- * Set global headers for all requests.
8
- * @param headers Object containing headers to be set globally.
34
+ * Validates that the resource property is defined.
35
+ * @throws {Error} If resource is not defined
36
+ */
37
+ protected static validateResource(): void;
38
+ /**
39
+ * Gets the fetcher function, using default if not provided.
40
+ * Creates a default Axios fetcher if not configured, allowing lazy initialization.
41
+ * @returns The fetcher function to use
42
+ */
43
+ private static getFetchFn;
44
+ /**
45
+ * Executes a fetch request with optional retry logic.
46
+ * @param config - The fetcher configuration
47
+ * @returns A promise that resolves with the response data
48
+ */
49
+ private static executeFetch;
50
+ /**
51
+ * Builds a URL by combining base URL and suffix.
52
+ * @param baseUrl - The base URL
53
+ * @param suffix - Optional suffix to append
54
+ * @returns The combined URL
55
+ */
56
+ private static buildUrl;
57
+ /**
58
+ * Sets global headers that will be included in all subsequent requests made by this class.
59
+ * @param headers - An object containing the headers to be set
9
60
  */
10
61
  static setHeaders(headers: Record<string, string>): void;
11
62
  /**
12
- * Convert data to FormData if isFormData is true, otherwise return the data as is.
13
- * @param data Data to be converted.
14
- * @returns Data in FormData format or as is.
15
- */
16
- static transformData(data: any): any;
17
- /**
18
- * Fetch a list of items from the server.
19
- *
20
- * @param params Query parameters for filtering the results.
21
- * @param options Additional options for the fetch function.
22
- * @returns The result of the fetch function (typically a promise).
23
- */
24
- static getAll<T>(params?: Record<string, any>, options?: object): any;
25
- /**
26
- * Fetch a single item by ID from the server.
27
- *
28
- * @param id The ID of the item to fetch.
29
- * @param params Additional query parameters for the request.
30
- * @param options Additional options for the fetch function.
31
- * @returns The result of the fetch function (typically a promise).
32
- */
33
- static getOne<T>(id: string | number, params?: Record<string, any>, options?: object): any;
34
- /**
35
- * Create a new item on the server.
36
- *
37
- * @param data The data for the new item to create.
38
- * @param options Additional options for the fetch function.
39
- * @returns The result of the fetch function (typically a promise).
40
- */
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;
50
- /**
51
- * Update an existing item on the server.
52
- *
53
- * @param id The ID of the item to update.
54
- * @param data The updated data for the item.
55
- * @param options Additional options for the fetch function.
56
- * @returns The result of the fetch function (typically a promise).
57
- */
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;
67
- /**
68
- * Partially update an existing item on the server.
69
- *
70
- * @param id The ID of the item to update.
71
- * @param data The updated data for the item.
72
- * @param options Additional options for the fetch function.
73
- * @returns The result of the fetch function (typically a promise).
74
- */
75
- static patch<T>(id: string | number, data: any, options?: object): any;
76
- /**
77
- * Delete an item from the server.
78
- *
79
- * @param id The ID of the item to delete.
80
- * @param options Additional options for the fetch function.
81
- * @returns The result of the fetch function (typically a promise).
82
- */
83
- static delete<T>(id: string | number, options?: object): any;
84
- /**
85
- * Delete multiple items from the server by their IDs.
86
- *
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.
90
- */
91
- static bulkDelete<T>(ids: (string | number)[], options?: object): any;
92
- /**
93
- * Upsert method that decides whether to create or update based on the presence of 'id'.
94
- *
95
- * @param data The data for the item to create or update.
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).
109
- */
110
- static customRequest<T>(method: string, url: string, params?: Record<string, any>, data?: any, options?: object): any;
63
+ * Conditionally transforms the request data to FormData if `isFormData` is true.
64
+ * @param data - The data to be potentially transformed
65
+ * @returns The transformed data as FormData, or the original data
66
+ */
67
+ static transformData(data: unknown): FormData | unknown;
68
+ /**
69
+ * Fetches a list of items from the resource's endpoint.
70
+ * @template TResponse The expected response type
71
+ * @template TParams The type of query parameters
72
+ * @param options - Options including params, options, and optional url override
73
+ * @returns A promise that resolves with the response data
74
+ */
75
+ static getAll<TResponse = unknown, TParams extends Record<string, unknown> = Record<string, unknown>>(options?: GetAllOptions<TParams>): Promise<TResponse>;
76
+ /**
77
+ * Fetches a single item by its ID.
78
+ * @template TResponse The expected response type
79
+ * @template TParams The type of query parameters
80
+ * @param options - Options including id, params, options, and optional url override
81
+ * @returns A promise that resolves with the response data
82
+ */
83
+ static getOne<TResponse = unknown, TParams extends Record<string, unknown> = Record<string, unknown>>(options: GetOneOptions<TParams>): Promise<TResponse>;
84
+ /**
85
+ * Creates a new item.
86
+ * @template TResponse The expected response type
87
+ * @template TData The type of data to send
88
+ * @param options - Options including data, options, and optional url override
89
+ * @returns A promise that resolves with the response data
90
+ */
91
+ static create<TResponse = unknown, TData = unknown>(options: CreateOptions<TData>): Promise<TResponse>;
92
+ /**
93
+ * Creates multiple new items in a single request.
94
+ * @template TResponse The expected response type
95
+ * @template TData The type of data items to send
96
+ * @param options - Options including data array, options, and optional url override
97
+ * @returns A promise that resolves with the response data
98
+ */
99
+ static bulkCreate<TResponse = unknown, TData = unknown>(options: BulkCreateOptions<TData>): Promise<TResponse>;
100
+ /**
101
+ * Updates an existing item by its ID.
102
+ * @template TResponse The expected response type
103
+ * @template TData The type of data to send
104
+ * @param options - Options including id, data, options, and optional url override
105
+ * @returns A promise that resolves with the response data
106
+ */
107
+ static update<TResponse = unknown, TData = unknown>(options: UpdateOptions<TData>): Promise<TResponse>;
108
+ /**
109
+ * Updates multiple existing items in a single request.
110
+ * @template TResponse The expected response type
111
+ * @template TData The type of data items to send
112
+ * @param options - Options including data array, options, and optional url override
113
+ * @returns A promise that resolves with the response data
114
+ */
115
+ static bulkUpdate<TResponse = unknown, TData = unknown>(options: BulkUpdateOptions<TData>): Promise<TResponse>;
116
+ /**
117
+ * Partially updates an existing item by its ID.
118
+ * @template TResponse The expected response type
119
+ * @template TData The type of data to send (partial)
120
+ * @param options - Options including id, data, options, and optional url override
121
+ * @returns A promise that resolves with the response data
122
+ */
123
+ static patch<TResponse = unknown, TData = unknown>(options: PatchOptions<TData>): Promise<TResponse>;
124
+ /**
125
+ * Deletes an item by its ID.
126
+ * @template TResponse The expected response type
127
+ * @param options - Options including id, options, and optional url override
128
+ * @returns A promise that resolves with the response data
129
+ */
130
+ static delete<TResponse = unknown>(options: DeleteOptions): Promise<TResponse>;
131
+ /**
132
+ * Deletes multiple items by their IDs in a single request.
133
+ * @template TResponse The expected response type
134
+ * @param options - Options including ids array, options, and optional url override
135
+ * @returns A promise that resolves with the response data
136
+ */
137
+ static bulkDelete<TResponse = unknown>(options: BulkDeleteOptions): Promise<TResponse>;
138
+ /**
139
+ * Creates a new item or updates an existing one, based on the presence of an `id` property in the data.
140
+ * @template TResponse The expected response type
141
+ * @template TData The type of data to send (must have optional id)
142
+ * @param options - Options including data, options, and optional url override
143
+ * @returns A promise that resolves with the response data
144
+ */
145
+ static upsert<TResponse = unknown, TData = unknown>(options: UpsertOptions<TData>): Promise<TResponse>;
146
+ /**
147
+ * Makes a custom HTTP request, providing full flexibility over the method, URL, and data.
148
+ * @template TResponse The expected response type
149
+ * @template TParams The type of query parameters
150
+ * @template TData The type of request body data
151
+ * @param options - Options including method, url, params, data, and options
152
+ * @returns A promise that resolves with the response data
153
+ */
154
+ static customRequest<TResponse = unknown, TParams extends Record<string, unknown> = Record<string, unknown>, TData = unknown>(options: CustomRequestOptions<TParams, TData>): Promise<TResponse>;
111
155
  }
@@ -1,56 +1,51 @@
1
1
  import { LocationPreference } from "@/types/SessionConfig";
2
2
  /**
3
- * Clears all stored authentication data (access and refresh tokens)
4
- * from either sessionStorage, localStorage, or both based on the provided location preference.
3
+ * Removes all stored authentication credentials (access and refresh tokens) from the specified storage locations.
5
4
  *
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.
5
+ * @param {LocationPreference} location - The storage location to clear. Can be 'local' for `localStorage`,
6
+ * 'session' for `sessionStorage`, 'cookie' for cookies, or 'any' to clear all.
7
+ * @returns {Promise<void>} A promise that resolves when the credentials have been cleared.
8
8
  */
9
9
  export declare const cleanCredentials: (location: LocationPreference) => Promise<void>;
10
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.
11
+ * Retrieves and decrypts the access token from the specified storage location.
13
12
  *
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.
13
+ * @param {string} secretKey - The secret key to use for decryption.
14
+ * @param {LocationPreference} location - The storage location to search ('local', 'session', 'cookie', or 'any').
15
+ * @returns {Promise<string | null>} A promise that resolves with the decrypted access token, or `null` if it's not found.
17
16
  */
18
17
  export declare const getAuthToken: (secretKey: string, location: LocationPreference) => Promise<string | null>;
19
18
  /**
20
- * Retrieves the authentication refresh token from storage, decrypting it
21
- * using the provided secret key and based on the specified session preference.
19
+ * Retrieves and decrypts the refresh token from the specified storage location.
22
20
  *
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.
21
+ * @param {string} secretKey - The secret key to use for decryption.
22
+ * @param {LocationPreference} location - The storage location to search ('local', 'session', 'cookie', or 'any').
23
+ * @returns {Promise<string | null>} A promise that resolves with the decrypted refresh token, or `null` if it's not found.
26
24
  */
27
25
  export declare const getAuthRefreshToken: (secretKey: string, location: LocationPreference) => Promise<string | null>;
28
26
  /**
29
- * Stores the authentication token (access token) in storage after encrypting it,
30
- * based on the specified session preference.
27
+ * Encrypts and stores the access token in the specified storage location.
31
28
  *
32
29
  * @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.
30
+ * @param {string} secretKey - The secret key to use for encryption.
31
+ * @param {LocationPreference} location - The storage location ('local', 'session', or 'cookie').
32
+ * @returns {Promise<void>} A promise that resolves when the token has been stored.
36
33
  */
37
34
  export declare const storeAuthToken: (token: string, secretKey: string, location: LocationPreference) => Promise<void>;
38
35
  /**
39
- * Stores the authentication refresh token in storage after encrypting it,
40
- * based on the specified session preference.
36
+ * Encrypts and stores the refresh token in the specified storage location.
41
37
  *
42
38
  * @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.
39
+ * @param {string} secretKey - The secret key to use for encryption.
40
+ * @param {LocationPreference} location - The storage location ('local', 'session', or 'cookie').
41
+ * @returns {Promise<void>} A promise that resolves when the token has been stored.
46
42
  */
47
43
  export declare const storeAuthRefreshToken: (token: string, secretKey: string, location: LocationPreference) => Promise<void>;
48
44
  /**
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.
45
+ * Verifies the current user's authentication status by checking for a valid, unexpired access token.
46
+ * It searches for the token in all storage locations (sessionStorage, localStorage, cookies).
47
+ * If the token is missing, malformed, or expired, it logs the issue, clears credentials, and returns `false`.
51
48
  *
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.
49
+ * @returns {Promise<boolean>} A promise that resolves to `true` if the user is authenticated, and `false` otherwise.
55
50
  */
56
51
  export declare const verifyAuth: () => Promise<boolean>;
@@ -1,12 +1,13 @@
1
1
  import { AuthTokenPaths } from "@/types";
2
2
  import { TokenValidationResult } from '@/types';
3
3
  /**
4
- * Extracts and validates the access and refresh tokens from a response object.
5
- * Throws an error if the tokens are not found or are invalid.
4
+ * Extracts access and refresh tokens from a response object using specified dot-notation paths
5
+ * and validates their existence and type.
6
6
  *
7
- * @param {any} data - The API response object.
8
- * @param {AuthTokenPaths} tokenPaths - The paths for the tokens.
9
- * @param {string} errorSource - A prefix for the error message ("LOGIN" or "REFRESH").
10
- * @returns {TokenValidationResult} An object with the validated tokens.
7
+ * @param {any} data - The response object from which to extract the tokens.
8
+ * @param {AuthTokenPaths} tokenPaths - An object containing the dot-notation paths for the access and refresh tokens.
9
+ * @param {string} errorSource - A string to identify the source of the operation (e.g., "LOGIN", "REFRESH") for error messages.
10
+ * @returns {TokenValidationResult} An object containing the extracted `accessToken` and `refreshToken`.
11
+ * @throws {Error} If the data object is missing, or if the access or refresh tokens cannot be found at the specified paths or are not strings.
11
12
  */
12
13
  export declare const extractAndValidateTokens: (data: any, tokenPaths: AuthTokenPaths, errorSource: string) => TokenValidationResult;
@@ -1,13 +1,12 @@
1
- import { AuthResponse } from "@/types";
2
- import { AxiosInstance } from 'axios';
1
+ import { AuthResponse, Fetcher } from "@/types";
3
2
  /**
4
- * Refreshes the authentication tokens using the stored refresh token.
5
- * This function can also accept optional token paths if the refresh endpoint
6
- * returns tokens with a different structure than the default login.
7
- * If no refresh token is found, it throws an error and initiates a logout.
8
- *
9
- * @param {AuthTokenPaths} [tokenPaths] - Optional configuration for the paths (in dot notation) of the access and refresh tokens in the refresh endpoint response.
10
- * @returns {Promise<AuthResponse>} The new authentication response with refreshed tokens.
11
- * @throws {Error} If the refresh token is missing or the refresh request fails.
12
- */
13
- export declare const refreshTokens: (axiosInstance: AxiosInstance) => Promise<AuthResponse>;
3
+ * Refreshes the access and refresh tokens by making a POST request to the refresh endpoint.
4
+ * It retrieves the current refresh token from storage, sends it to the refresh endpoint,
5
+ * and then stores the new tokens upon a successful response. If the refresh process fails
6
+ * or no refresh token is found, it clears all credentials and reloads the page.
7
+ *
8
+ * @param {Fetcher} [fetcher] - Optional fetcher function to use for the refresh request. If not provided, uses the default configured fetcher.
9
+ * @returns {Promise<AuthResponse>} A promise that resolves with the new authentication response containing the refreshed tokens.
10
+ * @throws {Error} Throws an error if the refresh token is missing or if the refresh request fails, which is then caught to trigger a logout.
11
+ */
12
+ export declare const refreshTokens: (fetcher?: Fetcher) => Promise<AuthResponse>;
@@ -1,9 +1,11 @@
1
1
  import { LocationPreference } from "@/types";
2
2
  /**
3
- * Stores the access and refresh tokens in the appropriate storage based on the user's preference.
4
- *
5
- * @param {string} accessToken - El token de acceso.
6
- * @param {string} refreshToken - El token de refresco.
7
- * @param {LocationPreference} persistence - La preferencia de almacenamiento.
8
- */
3
+ * Encrypts and stores both the access and refresh tokens in the specified storage location.
4
+ * Supports localStorage, sessionStorage, and cookies (with encryption and security options).
5
+ *
6
+ * @param {string} accessToken - The access token to be stored.
7
+ * @param {string} refreshToken - The refresh token to be stored.
8
+ * @param {LocationPreference} persistence - The desired storage location: 'local' for `localStorage`, 'session' for `sessionStorage`, or 'cookie' for cookies.
9
+ * @returns {Promise<void>} A promise that resolves when both tokens have been successfully stored.
10
+ */
9
11
  export declare const storeTokens: (accessToken: string, refreshToken: string, persistence: LocationPreference) => Promise<void>;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Defines the structure for the application key configuration object.
3
+ * This interface is used to ensure that the application key is provided in the correct format.
4
+ */
1
5
  export interface AppKeyConfig {
6
+ /**
7
+ * The application key, used for encryption and other security-related operations.
8
+ */
2
9
  appKey: string;
3
10
  }
@@ -1,22 +1,42 @@
1
1
  import { AxiosServiceOptions } from "./AxiosServiceOptions";
2
+ /**
3
+ * Defines the comprehensive configuration object for initializing the Arex-Vue-Core library.
4
+ * This interface gathers all the necessary settings, from API endpoints and token configurations
5
+ * to the application key and Axios-specific options, providing a single point of configuration.
6
+ */
2
7
  export interface ArexVueCoreOptions {
8
+ /** The secret key for encryption and decryption operations. */
3
9
  appKey: string;
10
+ /** An object containing the authentication-related API endpoints. */
4
11
  endpoints: {
12
+ /** The endpoint for user login. */
5
13
  login: string;
14
+ /** The endpoint for refreshing authentication tokens. */
6
15
  refresh: string;
16
+ /** The endpoint for user logout. */
7
17
  logout: string;
8
18
  };
19
+ /** An object defining the keys for storing tokens in local/session storage. */
9
20
  tokenKeys: {
21
+ /** The storage key for the access token. */
10
22
  accessToken: string;
23
+ /** The storage key for the refresh token. */
11
24
  refreshToken: string;
12
25
  };
26
+ /** An object specifying the dot-notation paths to find tokens in the login response. */
13
27
  tokenPaths: {
28
+ /** The path to the access token in the login response data. */
14
29
  accessToken: string;
30
+ /** The path to the refresh token in the login response data. */
15
31
  refreshToken: string;
16
32
  };
33
+ /** An object specifying the dot-notation paths to find tokens in the refresh token response. */
17
34
  refreshTokenPaths: {
35
+ /** The path to the access token in the refresh response data. */
18
36
  accessToken: string;
37
+ /** The path to the refresh token in the refresh response data. */
19
38
  refreshToken: string;
20
39
  };
40
+ /** The configuration options for the underlying Axios instance. */
21
41
  axios: AxiosServiceOptions;
22
42
  }
@@ -1,12 +1,27 @@
1
1
  import { TokensConfig, EndpointsConfig } from "@/types";
2
+ /**
3
+ * Defines the configuration for authentication-related settings, including API endpoints and storage keys.
4
+ */
2
5
  export type AuthConfig = {
6
+ /** The API endpoints for login, refresh, and logout operations. */
3
7
  endpoints: EndpointsConfig;
8
+ /** The keys used to store authentication tokens in local or session storage. */
4
9
  storageKeys: TokensConfig;
5
10
  };
11
+ /**
12
+ * Defines the structure for specifying the dot-notation paths to the access and refresh tokens
13
+ * within an API response. This allows for flexibility in handling different response structures.
14
+ */
6
15
  export interface AuthTokenPaths {
16
+ /** The path to the access token in the response data (e.g., 'data.accessToken'). */
7
17
  accessTokenPath?: string;
18
+ /** The path to the refresh token in the response data (e.g., 'data.refreshToken'). */
8
19
  refreshTokenPath?: string;
9
20
  }
21
+ /**
22
+ * Represents a generic authentication response from the API.
23
+ * Since the structure of the response can vary, it allows for any number of properties of any type.
24
+ */
10
25
  export interface AuthResponse {
11
26
  [key: string]: any;
12
27
  }
@@ -1,31 +1,38 @@
1
1
  import { MaybeRef } from 'vue';
2
2
  import { AxiosRequestConfig } from 'axios';
3
3
  /**
4
- * Type for options passed to an Axios fetch request.
4
+ * Defines a set of advanced options for controlling the behavior of an Axios-based fetch request.
5
+ * This includes features like immediate execution, default values, debouncing, and retry logic.
6
+ *
7
+ * @template T The expected type of the `defaultValue`.
5
8
  */
6
9
  export type AxiosOptionsParameter<T = any> = {
7
10
  /**
8
- * A boolean or a reactive reference to a boolean indicating if the request is enabled by default.
11
+ * If `true`, the request is executed immediately upon creation. Can be a reactive `Ref`.
12
+ * @default false
9
13
  */
10
14
  immediate?: MaybeRef<boolean>;
11
15
  /**
12
- * A default value to be used if the request does not return data.
16
+ * A default value to be used for the response data before the request completes or if it fails.
13
17
  */
14
18
  defaultValue?: T;
15
19
  /**
16
- * Axios configuration options for the request.
20
+ * Additional Axios-specific configuration for the request, such as headers, params, etc.
17
21
  */
18
22
  axiosOptionFetch?: AxiosRequestConfig;
19
23
  /**
20
- * Delay in milliseconds to debounce the request.
24
+ * The debounce interval in milliseconds. If provided, the request will be delayed until
25
+ * this amount of time has passed without any new calls.
21
26
  */
22
27
  debounce?: number;
23
28
  /**
24
- * Maximum number of retries for the request on failure.
29
+ * The maximum number of times to retry the request if it fails.
30
+ * @default 0
25
31
  */
26
32
  maxRetries?: number;
27
33
  /**
28
- * Delay in milliseconds between retry attempts.
34
+ * The delay in milliseconds between retry attempts.
35
+ * @default 1000
29
36
  */
30
37
  retryDelay?: number;
31
38
  };
@@ -1,6 +1,15 @@
1
+ /**
2
+ * Defines the configuration options for creating a new `AxiosService` instance.
3
+ * This interface allows for setting the base URL, default headers, request timeout,
4
+ * and credential handling for all requests made by the instance.
5
+ */
1
6
  export interface AxiosServiceOptions {
7
+ /** The base URL that will be prepended to all request URLs. */
2
8
  baseURL: string;
9
+ /** A record of default headers to be sent with every request. */
3
10
  headers?: Record<string, string>;
11
+ /** The request timeout in milliseconds. */
4
12
  timeout?: number;
13
+ /** A boolean indicating whether cross-site Access-Control requests should be made using credentials. */
5
14
  withCredentials?: boolean;
6
15
  }
@@ -1,9 +1,21 @@
1
+ /**
2
+ * Represents the payload of a decoded JSON Web Token (JWT).
3
+ * This interface includes the standard registered claims (`exp`, `iat`, etc.)
4
+ * as well as an index signature to allow for any custom claims.
5
+ */
1
6
  export interface DecodedJwtPayload {
7
+ /** The expiration time of the token, as a Unix timestamp. */
2
8
  exp?: number;
9
+ /** The time the token was issued, as a Unix timestamp. */
3
10
  iat?: number;
11
+ /** The time before which the token must not be accepted for processing, as a Unix timestamp. */
4
12
  nbf?: number;
13
+ /** The issuer of the token. */
5
14
  iss?: string;
15
+ /** The subject of the token. */
6
16
  sub?: string;
17
+ /** The audience of the token. */
7
18
  aud?: string | string[];
19
+ /** Allows for any other custom claims to be present in the payload. */
8
20
  [key: string]: unknown;
9
21
  }
@@ -1,5 +1,12 @@
1
+ /**
2
+ * Defines the structure for the authentication endpoints configuration object.
3
+ * This type ensures that the necessary endpoints for login, token refresh, and logout are defined.
4
+ */
1
5
  export type EndpointsConfig = {
6
+ /** The URL for the login endpoint. */
2
7
  LOGIN: string;
8
+ /** The URL for the token refresh endpoint. */
3
9
  REFRESH: string;
10
+ /** The URL for the logout endpoint. */
4
11
  LOGOUT: string;
5
12
  };
@@ -1,8 +1,10 @@
1
1
  /**
2
- * Tipos de errores permitidos
2
+ * Defines a union type of allowed error categories. This provides a standardized set of
3
+ * error types that can be used throughout the application for consistent error handling and logging.
3
4
  */
4
5
  export type ErrorType = 'warning' | 'error' | 'critical' | 'validation' | 'component' | 'network' | 'authentication' | 'runtime' | 'type' | 'reference' | 'syntax' | 'range' | 'eval' | 'uri';
5
6
  /**
6
- * Métodos disponibles para pasar errores a la ruta
7
+ * Defines the available methods for passing error information between routes or components.
8
+ * This can be done via URL query parameters, or by using `localStorage` or `sessionStorage`.
7
9
  */
8
10
  export type ErrorPassMethod = 'query' | 'localStorage' | 'sessionStorage';