@arex95/vue-core 1.1.38 → 1.1.40

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.
@@ -1,23 +1,11 @@
1
- import { AuthParams, AuthResponse, AuthTokenPaths, LocationPreference } from "@/types";
2
- /**
3
- * @typedef {object} AuthHook
4
- * @property {function(): Promise<number | null>} getTokenExpiry - Retrieves the expiration time of the current token in milliseconds.
5
- * @property {function(): Promise<void>} cleanCredentials - Clears authentication credentials from storage.
6
- * @property {(params?: AuthParams) => Promise<void>} logout - Logs out the user, clears credentials, and reloads the page.
7
- * @property {(params: AuthParams, persistence: SessionPreference, tokenPaths?: AuthTokenPaths) => Promise<AuthResponse>} login - Logs in the user and stores tokens.
8
- * @property {(tokenPaths?: AuthTokenPaths) => Promise<AuthResponse>} refresh - Refreshes authentication tokens.
9
- * @property {function(): Promise<boolean>} verifyAuth - Verifies the validity and expiration of the current authentication token.
10
- * @property {(preference: SessionPreference) => void} setSessionPersistencePreference - Sets the user's preferred storage for authentication data.
11
- * @property {function(): SessionPreference} getSessionPersistence - Retrieves the user's current preferred storage for authentication data.
12
- */
1
+ import { AuthResponse, AuthTokenPaths, LocationPreference } from "@/types";
13
2
  /**
14
3
  * Custom hook for authentication logic, including login, logout, token management, and session preference.
15
4
  *
16
5
  * @param {string} secretKey - The secret key used for token encryption/decryption.
17
6
  * @returns {AuthHook} An object containing authentication functions.
18
7
  */
19
- export declare function useAuth(secretKey?: string): {
20
- logout: (params?: AuthParams) => Promise<void>;
21
- login: (params: AuthParams, persistence: LocationPreference, tokenPaths?: AuthTokenPaths) => Promise<AuthResponse>;
22
- refresh: (tokenPaths?: AuthTokenPaths) => Promise<AuthResponse>;
8
+ export declare function useAuth(): {
9
+ logout: (params?: any) => Promise<void>;
10
+ login: (params: any | undefined, persistence: LocationPreference, tokenPaths?: AuthTokenPaths) => Promise<AuthResponse>;
23
11
  };
@@ -10,10 +10,9 @@ export declare class AxiosService {
10
10
  private cancelTokenSource;
11
11
  private activeRequests;
12
12
  private readonly refreshTokenUrl;
13
- private readonly refreshAuth;
14
13
  private isRefreshing;
15
14
  private failedQueue;
16
- constructor(options: AxiosServiceOptions, refreshAuth: () => Promise<void>);
15
+ constructor(options: AxiosServiceOptions);
17
16
  private processQueue;
18
17
  private setAuthHeader;
19
18
  private initializeInterceptors;
@@ -1,12 +1,4 @@
1
+ import { AxiosServiceOptions } from "@/types/AxiosServiceOptions";
1
2
  import { AxiosInstance } from "axios";
2
- interface AxiosConfig {
3
- baseURL: string;
4
- }
5
- interface CustomAxiosConfig {
6
- baseURL: string;
7
- headers?: Record<string, string>;
8
- }
9
- export declare const configAxios: (config: AxiosConfig) => void;
10
- export declare const getAxiosInstance: () => AxiosInstance;
11
- export declare const createCustomAxiosInstance: (config: CustomAxiosConfig) => AxiosInstance;
12
- export {};
3
+ export declare const configAxios: (config: AxiosServiceOptions) => void;
4
+ export declare const getConfiguredAxiosInstance: () => AxiosInstance;
@@ -2,3 +2,4 @@ export * from './tokensConfig';
2
2
  export * from './endpointsConfig';
3
3
  export * from './sessionConfig';
4
4
  export * from './keyConfig';
5
+ export * from './tokenPathsConfig';
@@ -0,0 +1,36 @@
1
+ interface TokenPathsConfig {
2
+ accessTokenPath?: string;
3
+ refreshTokenPath?: string;
4
+ }
5
+ /**
6
+ * Configures the paths for access and refresh tokens in the authentication response.
7
+ * This function freezes the object to prevent further modifications.
8
+ *
9
+ * @param {TokenPathsConfig} config - An object containing the paths for access and refresh tokens.
10
+ * @param {string} [config.accessTokenPath="data.access_token"] - Path to the access token in the response.
11
+ * @param {string} [config.refreshTokenPath="data.refresh_token"] - Path to the refresh token in the response.
12
+ *
13
+ * @returns {void} Does not return anything but freezes the token paths configuration object.
14
+ */
15
+ export declare function configTokenPaths(config: TokenPathsConfig): void;
16
+ /**
17
+ * Configures the paths for access and refresh tokens in the refresh response.
18
+ * This function freezes the object to prevent further modifications.
19
+ *
20
+ * @param {TokenPathsConfig} config - An object containing the paths for access and refresh tokens.
21
+ * @param {string} [config.accessTokenPath="data.access_token"] - Path to the access token in the response.
22
+ * @param {string} [config.refreshTokenPath="data.refresh_token"] - Path to the refresh token in the response.
23
+ *
24
+ * @returns {void} Does not return anything but freezes the refresh token paths configuration object.
25
+ */
26
+ export declare function configRefreshTokenPaths(config: TokenPathsConfig): void;
27
+ /**
28
+ * Retrieves the configured authentication token paths.
29
+ *
30
+ * @returns {AuthTokenPaths} An object containing the configured authentication token paths.
31
+ * @property {string} accessTokenPath - Path to the access token in the response.
32
+ * @property {string} refreshTokenPath - Path to the refresh token in the response.
33
+ */
34
+ export declare function getTokenPathsConfig(): TokenPathsConfig;
35
+ export declare function getRefreshTokenPathsConfig(): TokenPathsConfig;
36
+ export {};
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export declare const ArexVueCore: {
12
12
  * @param app The Vue application instance.
13
13
  * @param options The configuration options provided by the user.
14
14
  */
15
- install: (app: App, options: ArexVueCoreOptions) => Promise<void>;
15
+ install: (app: App, options: ArexVueCoreOptions) => void;
16
16
  };
17
17
  export * from "./rest";
18
18
  export * from "./composables";
@@ -20,3 +20,4 @@ export * from "./config";
20
20
  export * from "./enums";
21
21
  export * from "./types";
22
22
  export * from "./utils";
23
+ export * from "./services";
package/dist/index.mjs CHANGED
@@ -881,6 +881,60 @@ async function getSessionConfig() {
881
881
  return _sessionConfig;
882
882
  }
883
883
 
884
+ let tokenPathsConfig = {
885
+ accessTokenPath: "data.access_token",
886
+ refreshTokenPath: "data.refresh_token",
887
+ };
888
+ let refreshTokenPathsConfig = {
889
+ accessTokenPath: "data.access_token",
890
+ refreshTokenPath: "data.refresh_token",
891
+ };
892
+ /**
893
+ * Configures the paths for access and refresh tokens in the authentication response.
894
+ * This function freezes the object to prevent further modifications.
895
+ *
896
+ * @param {TokenPathsConfig} config - An object containing the paths for access and refresh tokens.
897
+ * @param {string} [config.accessTokenPath="data.access_token"] - Path to the access token in the response.
898
+ * @param {string} [config.refreshTokenPath="data.refresh_token"] - Path to the refresh token in the response.
899
+ *
900
+ * @returns {void} Does not return anything but freezes the token paths configuration object.
901
+ */
902
+ function configTokenPaths(config) {
903
+ tokenPathsConfig = Object.freeze({
904
+ accessTokenPath: config.accessTokenPath || "data.access_token",
905
+ refreshTokenPath: config.refreshTokenPath || "data.refresh_token",
906
+ });
907
+ }
908
+ /**
909
+ * Configures the paths for access and refresh tokens in the refresh response.
910
+ * This function freezes the object to prevent further modifications.
911
+ *
912
+ * @param {TokenPathsConfig} config - An object containing the paths for access and refresh tokens.
913
+ * @param {string} [config.accessTokenPath="data.access_token"] - Path to the access token in the response.
914
+ * @param {string} [config.refreshTokenPath="data.refresh_token"] - Path to the refresh token in the response.
915
+ *
916
+ * @returns {void} Does not return anything but freezes the refresh token paths configuration object.
917
+ */
918
+ function configRefreshTokenPaths(config) {
919
+ refreshTokenPathsConfig = Object.freeze({
920
+ accessTokenPath: config.accessTokenPath || "data.access_token",
921
+ refreshTokenPath: config.refreshTokenPath || "data.refresh_token",
922
+ });
923
+ }
924
+ /**
925
+ * Retrieves the configured authentication token paths.
926
+ *
927
+ * @returns {AuthTokenPaths} An object containing the configured authentication token paths.
928
+ * @property {string} accessTokenPath - Path to the access token in the response.
929
+ * @property {string} refreshTokenPath - Path to the refresh token in the response.
930
+ */
931
+ function getTokenPathsConfig() {
932
+ return tokenPathsConfig;
933
+ }
934
+ function getRefreshTokenPathsConfig() {
935
+ return refreshTokenPathsConfig;
936
+ }
937
+
884
938
  /**
885
939
  * Clears all stored authentication data (access and refresh tokens)
886
940
  * from either sessionStorage, localStorage, or both based on the provided location preference.
@@ -993,132 +1047,6 @@ const verifyAuth = async () => {
993
1047
  }
994
1048
  };
995
1049
 
996
- class AxiosService {
997
- instance;
998
- cancelTokenSource;
999
- activeRequests = 0;
1000
- refreshTokenUrl;
1001
- refreshAuth;
1002
- isRefreshing = false;
1003
- failedQueue = [];
1004
- constructor(options, refreshAuth) {
1005
- this.cancelTokenSource = axios.CancelToken.source();
1006
- this.refreshAuth = refreshAuth;
1007
- const endpointsConfig = getEndpointsConfig();
1008
- this.refreshTokenUrl = endpointsConfig.REFRESH;
1009
- this.instance = axios.create({
1010
- baseURL: options.baseURL ?? "",
1011
- timeout: options.timeout ?? 30000,
1012
- headers: {
1013
- Accept: "application/json",
1014
- "Content-Type": "application/json",
1015
- ...options.headers,
1016
- },
1017
- withCredentials: options.withCredentials ?? false,
1018
- });
1019
- this.initializeInterceptors();
1020
- }
1021
- processQueue(error, token = null) {
1022
- this.failedQueue.forEach((prom) => {
1023
- if (error) {
1024
- prom.reject(error);
1025
- }
1026
- else if (token) {
1027
- prom.resolve(token);
1028
- }
1029
- });
1030
- this.failedQueue = [];
1031
- }
1032
- setAuthHeader(config, token) {
1033
- if (config.headers) {
1034
- config.headers.Authorization = `Bearer ${token}`;
1035
- }
1036
- }
1037
- initializeInterceptors() {
1038
- this.instance.interceptors.request.use(async (config) => {
1039
- const token = await getAuthToken(getAppKey(), "any");
1040
- if (token) {
1041
- this.setAuthHeader(config, token);
1042
- }
1043
- config.cancelToken = this.cancelTokenSource.token;
1044
- this.activeRequests++;
1045
- return config;
1046
- }, (error) => {
1047
- handleError(error, false);
1048
- return Promise.reject(error);
1049
- });
1050
- this.instance.interceptors.response.use((response) => {
1051
- this.activeRequests--;
1052
- return response;
1053
- }, async (error) => {
1054
- this.activeRequests--;
1055
- const originalRequest = error.config;
1056
- const isAuthError = axios.isAxiosError(error) && error.response?.status === 401;
1057
- const isRefreshCall = originalRequest?.url === this.refreshTokenUrl;
1058
- const isRetry = originalRequest?._retry === true;
1059
- if (!isAuthError || isRefreshCall || isRetry) {
1060
- handleError(error, false);
1061
- return Promise.reject(error);
1062
- }
1063
- if (!originalRequest) {
1064
- handleError(error, false);
1065
- return Promise.reject(error);
1066
- }
1067
- if (this.isRefreshing) {
1068
- return new Promise((resolve, reject) => {
1069
- this.failedQueue.push({ resolve, reject });
1070
- })
1071
- .then((newToken) => {
1072
- this.setAuthHeader(originalRequest, newToken);
1073
- return this.instance(originalRequest);
1074
- })
1075
- .catch((err) => {
1076
- return Promise.reject(err);
1077
- });
1078
- }
1079
- this.isRefreshing = true;
1080
- originalRequest._retry = true;
1081
- try {
1082
- await this.refreshAuth();
1083
- const newToken = await getAuthToken(getAppKey(), "any");
1084
- if (newToken) {
1085
- this.processQueue(null, newToken);
1086
- this.setAuthHeader(originalRequest, newToken);
1087
- }
1088
- else {
1089
- const refreshError = new Error("New token not found after refresh.");
1090
- this.processQueue(refreshError, null);
1091
- throw refreshError;
1092
- }
1093
- this.isRefreshing = false;
1094
- return this.instance(originalRequest);
1095
- }
1096
- catch (refreshError) {
1097
- this.processQueue(refreshError, null);
1098
- this.isRefreshing = false;
1099
- handleError(refreshError, false);
1100
- return Promise.reject(error);
1101
- }
1102
- });
1103
- }
1104
- getActiveRequests() {
1105
- return this.activeRequests;
1106
- }
1107
- getAxiosInstance() {
1108
- return this.instance;
1109
- }
1110
- cancelAllRequests() {
1111
- this.cancelTokenSource.cancel("Operation canceled by the user.");
1112
- this.cancelTokenSource = axios.CancelToken.source();
1113
- }
1114
- setHeader(key, value) {
1115
- this.instance.defaults.headers.common[key] = value;
1116
- }
1117
- removeHeader(key) {
1118
- delete this.instance.defaults.headers.common[key];
1119
- }
1120
- }
1121
-
1122
1050
  /**
1123
1051
  * Converts a Proxy object to a plain object.
1124
1052
  * @param {ProxyConstructor} proxy The Proxy object to convert.
@@ -1401,157 +1329,216 @@ function flattenObject(obj, parentKey = '', result = {}) {
1401
1329
  // flattenObject({ a: 1, b: { c: 2, d: { e: 3 } } }); // { 'a': 1, 'b.c': 2, 'b.d.e': 3 }
1402
1330
 
1403
1331
  /**
1404
- * @typedef {object} AuthHook
1405
- * @property {function(): Promise<number | null>} getTokenExpiry - Retrieves the expiration time of the current token in milliseconds.
1406
- * @property {function(): Promise<void>} cleanCredentials - Clears authentication credentials from storage.
1407
- * @property {(params?: AuthParams) => Promise<void>} logout - Logs out the user, clears credentials, and reloads the page.
1408
- * @property {(params: AuthParams, persistence: SessionPreference, tokenPaths?: AuthTokenPaths) => Promise<AuthResponse>} login - Logs in the user and stores tokens.
1409
- * @property {(tokenPaths?: AuthTokenPaths) => Promise<AuthResponse>} refresh - Refreshes authentication tokens.
1410
- * @property {function(): Promise<boolean>} verifyAuth - Verifies the validity and expiration of the current authentication token.
1411
- * @property {(preference: SessionPreference) => void} setSessionPersistencePreference - Sets the user's preferred storage for authentication data.
1412
- * @property {function(): SessionPreference} getSessionPersistence - Retrieves the user's current preferred storage for authentication data.
1413
- */
1414
- /**
1415
- * Custom hook for authentication logic, including login, logout, token management, and session preference.
1332
+ * Extracts and validates the access and refresh tokens from a response object.
1333
+ * Throws an error if the tokens are not found or are invalid.
1416
1334
  *
1417
- * @param {string} secretKey - The secret key used for token encryption/decryption.
1418
- * @returns {AuthHook} An object containing authentication functions.
1419
- */
1420
- function useAuth(secretKey = getAppKey()) {
1421
- const axiosInstance = getAxiosInstance();
1335
+ * @param {any} data - The API response object.
1336
+ * @param {AuthTokenPaths} tokenPaths - The paths for the tokens.
1337
+ * @param {string} errorSource - A prefix for the error message ("LOGIN" or "REFRESH").
1338
+ * @returns {TokenValidationResult} An object with the validated tokens.
1339
+ */
1340
+ const extractAndValidateTokens = (data, tokenPaths, errorSource) => {
1341
+ const accessTokenPath = tokenPaths?.accessTokenPath || "access_token";
1342
+ const refreshTokenPath = tokenPaths?.refreshTokenPath || "refresh_token";
1343
+ if (!data) {
1344
+ throw new Error(`${errorSource}_ERROR: No data received.`);
1345
+ }
1346
+ const accessToken = safeGet(data, accessTokenPath.split("."));
1347
+ const refreshToken = safeGet(data, refreshTokenPath.split("."));
1348
+ if (!accessToken || typeof accessToken !== "string") {
1349
+ throw new Error(`${errorSource}_ERROR: Access token not found or invalid at path '${accessTokenPath}' in response.`);
1350
+ }
1351
+ if (!refreshToken || typeof refreshToken !== "string") {
1352
+ throw new Error(`${errorSource}_ERROR: Refresh token not found or invalid at path '${refreshTokenPath}' in response.`);
1353
+ }
1354
+ return { accessToken, refreshToken };
1355
+ };
1356
+
1357
+ /**
1358
+ * Stores the access and refresh tokens in the appropriate storage based on the user's preference.
1359
+ *
1360
+ * @param {string} accessToken - El token de acceso.
1361
+ * @param {string} refreshToken - El token de refresco.
1362
+ * @param {LocationPreference} persistence - La preferencia de almacenamiento.
1363
+ */
1364
+ const storeTokens = async (accessToken, refreshToken, persistence) => {
1365
+ await storeAuthToken(accessToken, getAppKey(), persistence);
1366
+ await storeAuthRefreshToken(refreshToken, getAppKey(), persistence);
1367
+ };
1368
+
1369
+ /**
1370
+ * Refreshes the authentication tokens using the stored refresh token.
1371
+ * This function can also accept optional token paths if the refresh endpoint
1372
+ * returns tokens with a different structure than the default login.
1373
+ * If no refresh token is found, it throws an error and initiates a logout.
1374
+ *
1375
+ * @param {AuthTokenPaths} [tokenPaths] - Optional configuration for the paths (in dot notation) of the access and refresh tokens in the refresh endpoint response.
1376
+ * @returns {Promise<AuthResponse>} The new authentication response with refreshed tokens.
1377
+ * @throws {Error} If the refresh token is missing or the refresh request fails.
1378
+ */
1379
+ const refreshTokens = async (axiosInstance) => {
1380
+ const tokenPaths = getRefreshTokenPathsConfig();
1422
1381
  const endpoints = getEndpointsConfig();
1423
- /**
1424
- * Logs out the user by making a POST request to the logout endpoint,
1425
- * cleaning all stored credentials, and reloading the page.
1426
- * The session persistence preference is NOT reset here; it persists across logouts.
1427
- *
1428
- * @param {AuthParams} [params={}] - Optional parameters to send with the logout request.
1429
- * @returns {Promise<void>}
1430
- */
1431
- const logout = async (params = {}) => {
1432
- try {
1433
- await axiosInstance.post(endpoints.LOGOUT, params);
1434
- }
1435
- catch (error) {
1436
- handleError(error, false);
1382
+ const secretKey = getAppKey();
1383
+ const persistence = await getSessionPersistence();
1384
+ try {
1385
+ const refreshTokenFromStorage = await getAuthRefreshToken(secretKey, "any");
1386
+ if (!refreshTokenFromStorage) {
1387
+ throw new Error("TOKEN_MISSING: No refresh token found in storage.");
1437
1388
  }
1438
- finally {
1439
- await cleanCredentials(await getSessionPersistence());
1389
+ const { data } = await axiosInstance.post(endpoints.REFRESH);
1390
+ const { accessToken, refreshToken } = extractAndValidateTokens(data, tokenPaths, "REFRESH");
1391
+ await storeTokens(accessToken, refreshToken, persistence);
1392
+ return data;
1393
+ }
1394
+ catch (error) {
1395
+ handleError(error, false);
1396
+ await cleanCredentials(persistence);
1397
+ if (window) {
1440
1398
  window.location.reload();
1441
1399
  }
1442
- };
1443
- /**
1444
- * Authenticates the user by making a POST request to the login endpoint,
1445
- * stores the received access and refresh tokens, and sets the session persistence preference.
1446
- *
1447
- * @param {AuthParams} params - The authentication parameters (e.g., username, password).
1448
- * @param {SessionPreference} persistence - The storage preference: 'local' for localStorage, 'session' for sessionStorage.
1449
- * @param {AuthTokenPaths} [tokenPaths] - Configuración opcional para las rutas (en notación de punto) donde se encuentran los tokens en la respuesta de la API.
1450
- * @returns {Promise<AuthResponse>} La respuesta de autenticación que contiene los tokens e información del usuario.
1451
- * @throws {Error} Si la solicitud de login falla, o si los tokens de acceso/refresco no se encuentran o no son válidos en la respuesta.
1452
- */
1453
- const login = async (params, persistence, tokenPaths) => {
1454
- try {
1455
- const { data } = await axiosInstance.post(endpoints.LOGIN, params);
1456
- const accessTokenPath = tokenPaths?.accessTokenPath || "access_token";
1457
- const refreshTokenPath = tokenPaths?.refreshTokenPath || "refresh_token";
1458
- const accessTokenPathArray = accessTokenPath.split(".");
1459
- const refreshTokenPathArray = refreshTokenPath.split(".");
1460
- if (!data) {
1461
- throw new Error("LOGIN_ERROR: No data received from login endpoint.");
1462
- }
1463
- const accessToken = safeGet(data, accessTokenPathArray);
1464
- const refreshToken = safeGet(data, refreshTokenPathArray);
1465
- if (!accessToken || typeof accessToken !== "string") {
1466
- throw new Error(`LOGIN_ERROR: Access token not found or invalid at path '${accessTokenPath}' in response.`);
1400
+ throw error;
1401
+ }
1402
+ };
1403
+
1404
+ class AxiosService {
1405
+ instance;
1406
+ cancelTokenSource;
1407
+ activeRequests = 0;
1408
+ refreshTokenUrl;
1409
+ isRefreshing = false;
1410
+ failedQueue = [];
1411
+ constructor(options) {
1412
+ this.cancelTokenSource = axios.CancelToken.source();
1413
+ const endpointsConfig = getEndpointsConfig();
1414
+ this.refreshTokenUrl = endpointsConfig.REFRESH;
1415
+ this.instance = axios.create({
1416
+ baseURL: options.baseURL ?? "",
1417
+ timeout: options.timeout ?? 30000,
1418
+ headers: {
1419
+ Accept: "application/json",
1420
+ "Content-Type": "application/json",
1421
+ ...options.headers,
1422
+ },
1423
+ withCredentials: options.withCredentials ?? false,
1424
+ });
1425
+ this.initializeInterceptors();
1426
+ }
1427
+ processQueue(error, token = null) {
1428
+ this.failedQueue.forEach((prom) => {
1429
+ if (error) {
1430
+ prom.reject(error);
1467
1431
  }
1468
- if (!refreshToken || typeof refreshToken !== "string") {
1469
- throw new Error(`LOGIN_ERROR: Refresh token not found or invalid at path '${refreshTokenPath}' in response.`);
1432
+ else if (token) {
1433
+ prom.resolve(token);
1470
1434
  }
1471
- configSession({
1472
- persistencePreference: persistence,
1473
- });
1474
- await storeAuthToken(accessToken, secretKey, persistence);
1475
- await storeAuthRefreshToken(refreshToken, secretKey, persistence);
1476
- return data;
1435
+ });
1436
+ this.failedQueue = [];
1437
+ }
1438
+ setAuthHeader(config, token) {
1439
+ if (config.headers) {
1440
+ config.headers.Authorization = `Bearer ${token}`;
1477
1441
  }
1478
- catch (error) {
1442
+ }
1443
+ initializeInterceptors() {
1444
+ this.instance.interceptors.request.use(async (config) => {
1445
+ const token = await getAuthToken(getAppKey(), "any");
1446
+ if (token) {
1447
+ this.setAuthHeader(config, token);
1448
+ }
1449
+ config.cancelToken = this.cancelTokenSource.token;
1450
+ this.activeRequests++;
1451
+ return config;
1452
+ }, (error) => {
1479
1453
  handleError(error, false);
1480
- throw error;
1481
- }
1482
- };
1483
- /**
1484
- * Refreshes the authentication tokens using the stored refresh token.
1485
- * This function can also accept optional token paths if the refresh endpoint
1486
- * returns tokens with a different structure than the default login.
1487
- * If no refresh token is found, it throws an error and initiates a logout.
1488
- *
1489
- * @param {AuthTokenPaths} [tokenPaths] - Configuración opcional para las rutas (en notación de punto) de los tokens de acceso y refresco en la respuesta del endpoint de refresco.
1490
- * @returns {Promise<AuthResponse>} The new authentication response with refreshed tokens.
1491
- * @throws {Error} If the refresh token is missing or the refresh request fails.
1492
- */
1493
- const refresh = async (tokenPaths) => {
1494
- try {
1495
- const refreshTokenFromStorage = await getAuthRefreshToken(secretKey, 'any');
1496
- if (!refreshTokenFromStorage) {
1497
- throw new Error("TOKEN_MISSING: No refresh token found in storage.");
1454
+ return Promise.reject(error);
1455
+ });
1456
+ this.instance.interceptors.response.use((response) => {
1457
+ this.activeRequests--;
1458
+ return response;
1459
+ }, async (error) => {
1460
+ this.activeRequests--;
1461
+ const originalRequest = error.config;
1462
+ const isAuthError = axios.isAxiosError(error) && error.response?.status === 401;
1463
+ const isRefreshCall = originalRequest?.url === this.refreshTokenUrl;
1464
+ const isRetry = originalRequest?._retry === true;
1465
+ if (!isAuthError || isRefreshCall || isRetry) {
1466
+ handleError(error, false);
1467
+ return Promise.reject(error);
1498
1468
  }
1499
- const { data } = await axiosInstance.post(endpoints.REFRESH, { refresh_token: refreshTokenFromStorage });
1500
- const accessTokenPath = tokenPaths?.accessTokenPath || "access_token";
1501
- const refreshTokenPath = tokenPaths?.refreshTokenPath || "refresh_token";
1502
- const accessTokenPathArray = accessTokenPath.split(".");
1503
- const refreshTokenPathArray = refreshTokenPath.split(".");
1504
- if (!data) {
1505
- throw new Error("REFRESH_ERROR: No data received from refresh endpoint.");
1469
+ if (!originalRequest) {
1470
+ handleError(error, false);
1471
+ return Promise.reject(error);
1506
1472
  }
1507
- const accessTokenAfterRefresh = safeGet(data, accessTokenPathArray);
1508
- const refreshTokenAfterRefresh = safeGet(data, refreshTokenPathArray);
1509
- if (!accessTokenAfterRefresh ||
1510
- typeof accessTokenAfterRefresh !== "string") {
1511
- throw new Error(`REFRESH_ERROR: Access token not found or invalid at path '${accessTokenPath}' in refresh response.`);
1473
+ if (this.isRefreshing) {
1474
+ return new Promise((resolve, reject) => {
1475
+ this.failedQueue.push({ resolve, reject });
1476
+ })
1477
+ .then((newToken) => {
1478
+ this.setAuthHeader(originalRequest, newToken);
1479
+ return this.instance(originalRequest);
1480
+ })
1481
+ .catch((err) => {
1482
+ return Promise.reject(err);
1483
+ });
1512
1484
  }
1513
- if (!refreshTokenAfterRefresh ||
1514
- typeof refreshTokenAfterRefresh !== "string") {
1515
- throw new Error(`REFRESH_ERROR: Refresh token not found or invalid at path '${refreshTokenPath}' in refresh response.`);
1485
+ this.isRefreshing = true;
1486
+ originalRequest._retry = true;
1487
+ try {
1488
+ await refreshTokens(this.instance);
1489
+ const newToken = await getAuthToken(getAppKey(), "any");
1490
+ if (newToken) {
1491
+ this.processQueue(null, newToken);
1492
+ this.setAuthHeader(originalRequest, newToken);
1493
+ }
1494
+ else {
1495
+ const refreshError = new Error("New token not found after refresh.");
1496
+ this.processQueue(refreshError, null);
1497
+ throw refreshError;
1498
+ }
1499
+ this.isRefreshing = false;
1500
+ return this.instance(originalRequest);
1516
1501
  }
1517
- await storeAuthToken(accessTokenAfterRefresh, secretKey, await getSessionPersistence());
1518
- await storeAuthRefreshToken(refreshTokenAfterRefresh, secretKey, await getSessionPersistence());
1519
- return data;
1520
- }
1521
- catch (error) {
1522
- handleError(error, false);
1523
- await logout();
1524
- throw error;
1525
- }
1526
- };
1527
- return {
1528
- logout,
1529
- login,
1530
- refresh,
1531
- };
1502
+ catch (refreshError) {
1503
+ this.processQueue(refreshError, null);
1504
+ this.isRefreshing = false;
1505
+ handleError(refreshError, false);
1506
+ return Promise.reject(error);
1507
+ }
1508
+ });
1509
+ }
1510
+ getActiveRequests() {
1511
+ return this.activeRequests;
1512
+ }
1513
+ getAxiosInstance() {
1514
+ return this.instance;
1515
+ }
1516
+ cancelAllRequests() {
1517
+ this.cancelTokenSource.cancel("Operation canceled by the user.");
1518
+ this.cancelTokenSource = axios.CancelToken.source();
1519
+ }
1520
+ setHeader(key, value) {
1521
+ this.instance.defaults.headers.common[key] = value;
1522
+ }
1523
+ removeHeader(key) {
1524
+ delete this.instance.defaults.headers.common[key];
1525
+ }
1532
1526
  }
1533
1527
 
1534
- let axiosInstance;
1535
- const auth = useAuth();
1536
- const refreshAndForget = async () => {
1537
- await auth.refresh();
1538
- };
1528
+ let axiosServiceInstance;
1539
1529
  const configAxios = (config) => {
1540
- axiosInstance = new AxiosService({
1530
+ axiosServiceInstance = new AxiosService({
1541
1531
  baseURL: config.baseURL,
1542
- }, refreshAndForget);
1532
+ headers: config.headers,
1533
+ timeout: config.timeout,
1534
+ withCredentials: config.withCredentials
1535
+ });
1543
1536
  };
1544
- const getAxiosInstance = () => {
1545
- if (!axiosInstance) {
1537
+ const getConfiguredAxiosInstance = () => {
1538
+ if (!axiosServiceInstance) {
1546
1539
  throw new Error("Axios instance not configured. Call configAxios first.");
1547
1540
  }
1548
- return axiosInstance.getAxiosInstance();
1549
- };
1550
- const createCustomAxiosInstance = (config) => {
1551
- return new AxiosService({
1552
- baseURL: config.baseURL,
1553
- headers: config.headers,
1554
- }, refreshAndForget).getAxiosInstance();
1541
+ return axiosServiceInstance.getAxiosInstance();
1555
1542
  };
1556
1543
 
1557
1544
  /**
@@ -3126,7 +3113,7 @@ async function axiosFetch(axios, axiosRequest) {
3126
3113
  * @returns A function that handles the request using the provided composable.
3127
3114
  */
3128
3115
  function createFetch(fetchComposable, axiosCustomInstance) {
3129
- const instance = axiosCustomInstance || getAxiosInstance();
3116
+ const instance = axiosCustomInstance || getConfiguredAxiosInstance();
3130
3117
  return (axiosRequestConfig, options) => {
3131
3118
  return fetchComposable(instance, axiosRequestConfig, options);
3132
3119
  };
@@ -3486,6 +3473,66 @@ function useSorter(items, criteriaList, selectedCriteria) {
3486
3473
  }).value;
3487
3474
  }
3488
3475
 
3476
+ /**
3477
+ * Custom hook for authentication logic, including login, logout, token management, and session preference.
3478
+ *
3479
+ * @param {string} secretKey - The secret key used for token encryption/decryption.
3480
+ * @returns {AuthHook} An object containing authentication functions.
3481
+ */
3482
+ function useAuth() {
3483
+ const axiosInstance = getConfiguredAxiosInstance();
3484
+ const endpoints = getEndpointsConfig();
3485
+ /**
3486
+ * Logs out the user by making a POST request to the logout endpoint,
3487
+ * cleaning all stored credentials, and reloading the page.
3488
+ * The session persistence preference is NOT reset here; it persists across logouts.
3489
+ *
3490
+ * @param {AuthParams} [params={}] - Optional parameters to send with the logout request.
3491
+ * @returns {Promise<void>}
3492
+ */
3493
+ const logout = async (params = {}) => {
3494
+ try {
3495
+ await axiosInstance.post(endpoints.LOGOUT, params);
3496
+ }
3497
+ catch (error) {
3498
+ handleError(error, false);
3499
+ }
3500
+ finally {
3501
+ await cleanCredentials(await getSessionPersistence());
3502
+ window.location.reload();
3503
+ }
3504
+ };
3505
+ /**
3506
+ * Authenticates the user by making a POST request to the login endpoint,
3507
+ * stores the received access and refresh tokens, and sets the session persistence preference.
3508
+ *
3509
+ * @param {AuthParams} params - The authentication parameters (e.g., username, password).
3510
+ * @param {LocationPreference} persistence - The storage preference: 'local' for localStorage, 'session' for sessionStorage.
3511
+ * @param {AuthTokenPaths} [tokenPaths] - Optional configuration for the paths (in dot notation) where the tokens are located in the API response.
3512
+ * @returns {Promise<AuthResponse>} The authentication response containing the tokens and user information.
3513
+ * @throws {Error} If the login request fails, or if the access/refresh tokens are not found or are invalid in the response.
3514
+ */
3515
+ const login = async (params = {}, persistence, tokenPaths = getTokenPathsConfig()) => {
3516
+ try {
3517
+ const { data } = await axiosInstance.post(endpoints.LOGIN, params);
3518
+ const { accessToken, refreshToken } = extractAndValidateTokens(data, tokenPaths, "LOGIN");
3519
+ configSession({
3520
+ persistencePreference: persistence,
3521
+ });
3522
+ await storeTokens(accessToken, refreshToken, persistence);
3523
+ return data;
3524
+ }
3525
+ catch (error) {
3526
+ handleError(error, false);
3527
+ throw error;
3528
+ }
3529
+ };
3530
+ return {
3531
+ logout,
3532
+ login
3533
+ };
3534
+ }
3535
+
3489
3536
  /**
3490
3537
  * The Vue plugin for @arex95/vue-core.
3491
3538
  * Configures the core functionalities for authentication and API communication.
@@ -3498,38 +3545,38 @@ const ArexVueCore = {
3498
3545
  * @param app The Vue application instance.
3499
3546
  * @param options The configuration options provided by the user.
3500
3547
  */
3501
- install: async (app, options) => {
3548
+ install: (app, options) => {
3502
3549
  if (!options) {
3503
3550
  console.warn("ArexVueCore: No configuration options were provided. The library may not function correctly.");
3504
3551
  return;
3505
3552
  }
3506
- try {
3507
- console.log("Starting configuration process...");
3508
- await configAppKey({
3509
- appKey: options.appKey
3510
- });
3511
- console.log("[1/4]-configAppKey executed successfully.");
3512
- await configTokenKeys({
3513
- accessTokenKey: options.tokenKeys.accessToken,
3514
- refreshTokenKey: options.tokenKeys.refreshToken
3515
- });
3516
- console.log("[2/4]-configTokenKeys executed successfully.");
3517
- await configEndpoints({
3518
- loginEndpoint: options.endpoints.login,
3519
- refreshEndpoint: options.endpoints.refresh,
3520
- logoutEndpoint: options.endpoints.logout,
3521
- });
3522
- console.log("[3/4]-configEndpoints executed successfully.");
3523
- await configAxios({
3524
- baseURL: options.apiUrl,
3525
- });
3526
- console.log("[4/4]-configAxios executed successfully.");
3527
- console.log("All configurations completed in the correct order.");
3528
- }
3529
- catch (error) {
3530
- console.error("Configuration failed:", error);
3531
- }
3553
+ configAppKey({
3554
+ appKey: options.appKey
3555
+ });
3556
+ configTokenKeys({
3557
+ accessTokenKey: options.tokenKeys.accessToken,
3558
+ refreshTokenKey: options.tokenKeys.refreshToken,
3559
+ });
3560
+ configEndpoints({
3561
+ loginEndpoint: options.endpoints.login,
3562
+ refreshEndpoint: options.endpoints.refresh,
3563
+ logoutEndpoint: options.endpoints.logout,
3564
+ });
3565
+ configTokenPaths({
3566
+ accessTokenPath: options.tokenPaths.accessToken,
3567
+ refreshTokenPath: options.tokenPaths.refreshToken,
3568
+ });
3569
+ configRefreshTokenPaths({
3570
+ accessTokenPath: options.refreshTokenPaths.accessToken,
3571
+ refreshTokenPath: options.refreshTokenPaths.refreshToken,
3572
+ });
3573
+ configAxios({
3574
+ baseURL: options.axios.baseURL,
3575
+ headers: options.axios.headers,
3576
+ timeout: options.axios.timeout,
3577
+ withCredentials: options.axios.withCredentials
3578
+ });
3532
3579
  },
3533
3580
  };
3534
3581
 
3535
- 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, configSession, configTokenKeys, copyToClipboard, countWords, createCustomAxiosInstance, createFetch, 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, filterObjectByKeys, flattenObject, formDataToObject, formatDate, generateRandomString, getAppKey, getAuthRefreshToken, getAuthToken, getAxiosInstance, getDecryptedItem, getEndOfMonth, getEndpointsConfig, getObjectDifferences, getObjectKeys, getQueryParam, getSessionConfig, getSessionId, getSessionPersistence, getStartOfMonth, getTokenConfig, 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, registerKeyboardShortcuts, removeAccent, removeClickOutside, removeCustomKeyboardShortcut, removeCustomShortcuts, removeDoubleClickListener, removeEmptyProperties, removeKeyListeners, replaceAll, reverseString, safeGet, screenMap, scrollToTop, simulateKeyPress, stopDetectingKeyHold, storeAuthRefreshToken, storeAuthToken, storeEncryptedItem, stringToBlob, subtractDays, throttle, toCamelCase, toKebabCase, toggleTabNavigation, truncateString, unregisterKeyboardShortcuts, upperFirst, useAuth, useBreakpoint, useFilter, usePagination, useSorter, useVueQuery, validateAlphanumeric, validateLetters, validateNumbers, verifyAuth };
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, createFetch, 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, useFilter, usePagination, useSorter, useVueQuery, validateAlphanumeric, validateLetters, validateNumbers, verifyAuth };
@@ -0,0 +1,56 @@
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>;
@@ -0,0 +1,12 @@
1
+ import { AuthTokenPaths } from "@/types";
2
+ import { TokenValidationResult } from '@/types';
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.
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.
11
+ */
12
+ export declare const extractAndValidateTokens: (data: any, tokenPaths: AuthTokenPaths, errorSource: string) => TokenValidationResult;
@@ -0,0 +1,4 @@
1
+ export * from './extractTokens';
2
+ export * from './refreshTokens';
3
+ export * from "./storeTokens";
4
+ export * from './credentials';
@@ -0,0 +1,13 @@
1
+ import { AuthResponse } from "@/types";
2
+ import { AxiosInstance } from 'axios';
3
+ /**
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>;
@@ -0,0 +1,9 @@
1
+ import { LocationPreference } from "@/types";
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
+ */
9
+ export declare const storeTokens: (accessToken: string, refreshToken: string, persistence: LocationPreference) => Promise<void>;
@@ -1,3 +1,4 @@
1
+ import { AxiosServiceOptions } from "./AxiosServiceOptions";
1
2
  export interface ArexVueCoreOptions {
2
3
  appKey: string;
3
4
  endpoints: {
@@ -9,5 +10,13 @@ export interface ArexVueCoreOptions {
9
10
  accessToken: string;
10
11
  refreshToken: string;
11
12
  };
12
- apiUrl: string;
13
+ tokenPaths: {
14
+ accessToken: string;
15
+ refreshToken: string;
16
+ };
17
+ refreshTokenPaths: {
18
+ accessToken: string;
19
+ refreshToken: string;
20
+ };
21
+ axios: AxiosServiceOptions;
13
22
  }
@@ -3,10 +3,6 @@ export type AuthConfig = {
3
3
  endpoints: EndpointsConfig;
4
4
  storageKeys: TokensConfig;
5
5
  };
6
- export interface AuthParams {
7
- username?: string;
8
- password?: string;
9
- }
10
6
  export interface AuthTokenPaths {
11
7
  accessTokenPath?: string;
12
8
  refreshTokenPath?: string;
@@ -0,0 +1,4 @@
1
+ export type TokenValidationResult = {
2
+ accessToken: string;
3
+ refreshToken: string;
4
+ };
@@ -9,3 +9,4 @@ export * from './DecodedJwtPayload';
9
9
  export * from './ArexVueCoreOptions';
10
10
  export * from './AppKeyConfig';
11
11
  export * from './AxiosServiceOptions';
12
+ export * from './TokenValidationResult';
@@ -7,7 +7,7 @@ export * from './files';
7
7
  export * from './objects';
8
8
  export * from './strings';
9
9
  export * from './validations';
10
- export * from './credentials';
10
+ export * from '../services/credentials';
11
11
  export * from './storage';
12
12
  export * from './encryption';
13
13
  export * from './errors';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arex95/vue-core",
3
- "version": "1.1.38",
3
+ "version": "1.1.40",
4
4
  "description": "Opinionated Vue Core",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",