@arex95/vue-core 1.1.19 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/composables/auth/useAuth.d.ts +21 -49
- package/dist/config/axios/axiosInstance.d.ts +28 -6
- package/dist/config/global/endpointsConfig.d.ts +14 -4
- package/dist/config/global/sessionConfig.d.ts +22 -5
- package/dist/config/global/tokensConfig.d.ts +13 -4
- package/dist/index.d.ts +22 -6
- package/dist/index.mjs +2560 -2470
- package/dist/types/ArexVueCoreOptions.d.ts +26 -0
- package/dist/types/AuthParams.d.ts +4 -0
- package/dist/types/AuthResponse.d.ts +5 -0
- package/dist/types/DecodedJwtPayload.d.ts +9 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/utils/credentials.d.ts +47 -0
- package/dist/utils/encryption.d.ts +32 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/storage.d.ts +19 -0
- package/package.json +2 -1
|
@@ -1,57 +1,29 @@
|
|
|
1
|
+
import { AuthParams, AuthResponse } from "@/types";
|
|
2
|
+
import { SessionPreference } from "@config/global/sessionConfig";
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
4
|
+
* @typedef {object} AuthHook
|
|
5
|
+
* @property {function(): Promise<string | null>} getJwt - Retrieves the current JWT.
|
|
6
|
+
* @property {function(): Promise<number | null>} getTokenExpiry - Retrieves the expiration time of the current token in milliseconds.
|
|
7
|
+
* @property {function(): Promise<void>} cleanCredentials - Clears authentication credentials from storage.
|
|
8
|
+
* @property {(params?: AuthParams) => Promise<void>} logout - Logs out the user, clears credentials, and reloads the page.
|
|
9
|
+
* @property {(params: AuthParams, persistence: SessionPreference) => Promise<AuthResponse>} login - Logs in the user and stores tokens.
|
|
10
|
+
* @property {function(): Promise<AuthResponse>} refresh - Refreshes authentication tokens.
|
|
11
|
+
* @property {function(): Promise<boolean>} verifyAuth - Verifies the validity and expiration of the current authentication token.
|
|
12
|
+
* @property {(preference: SessionPreference) => void} setSessionPersistencePreference - Sets the user's preferred storage for authentication data.
|
|
13
|
+
* @property {function(): SessionPreference} getSessionPersistencePreference - Retrieves the user's current preferred storage for authentication data.
|
|
5
14
|
*/
|
|
6
|
-
declare function ab2hex(buffer: Uint8Array): string;
|
|
7
15
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
|
|
12
|
-
declare function hex2ab(hex: string): Uint8Array;
|
|
13
|
-
/**
|
|
14
|
-
* Imports a secret key for cryptographic operations.
|
|
15
|
-
* @param {string} secretKey - The string secret key.
|
|
16
|
-
* @returns {Promise<CryptoKey>} A Promise that resolves to the CryptoKey.
|
|
17
|
-
*/
|
|
18
|
-
declare function importKey(secretKey: string): Promise<CryptoKey>;
|
|
19
|
-
/**
|
|
20
|
-
* Interface for the expected structure of a successful login response from the API.
|
|
21
|
-
*/
|
|
22
|
-
interface LoginResponse {
|
|
23
|
-
access_token: string;
|
|
24
|
-
refresh_token: string;
|
|
25
|
-
[key: string]: unknown;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Interface for the expected structure of a successful token refresh response from the API.
|
|
29
|
-
*/
|
|
30
|
-
interface RefreshResponse {
|
|
31
|
-
access_token: string;
|
|
32
|
-
refresh_token: string;
|
|
33
|
-
[key: string]: unknown;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* A Vue composable that provides authentication utilities, enforcing asynchronous access to tokens.
|
|
37
|
-
* All token-related properties and status checks are awaitable functions.
|
|
38
|
-
* @param {string} [secretKey=getSecretKey()] - The encryption/decryption key. Defaults to a globally configured key.
|
|
39
|
-
* @returns {object} An object containing asynchronous authentication methods and properties.
|
|
16
|
+
* Custom hook for authentication logic, including login, logout, token management, and session preference.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} secretKey - The secret key used for token encryption/decryption.
|
|
19
|
+
* @returns {AuthHook} An object containing authentication functions.
|
|
40
20
|
*/
|
|
41
21
|
export declare function useAuth(secretKey?: string): {
|
|
42
22
|
getJwt: () => Promise<string | null>;
|
|
43
|
-
getRefreshToken: () => Promise<string | null>;
|
|
44
|
-
isAuthenticated: () => Promise<boolean>;
|
|
45
23
|
getTokenExpiry: () => Promise<number | null>;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
ab2hex: typeof ab2hex;
|
|
52
|
-
hex2ab: typeof hex2ab;
|
|
53
|
-
importKey: typeof importKey;
|
|
54
|
-
encrypt: (value: string, secretKey: string) => Promise<string>;
|
|
55
|
-
decrypt: (value: string, secretKey: string) => Promise<string>;
|
|
24
|
+
cleanCredentials: (preference: SessionPreference) => Promise<void>;
|
|
25
|
+
logout: (params?: AuthParams) => Promise<void>;
|
|
26
|
+
login: (params: AuthParams, persistence: SessionPreference) => Promise<AuthResponse>;
|
|
27
|
+
refresh: () => Promise<AuthResponse>;
|
|
28
|
+
verifyAuth: () => Promise<boolean>;
|
|
56
29
|
};
|
|
57
|
-
export {};
|
|
@@ -1,19 +1,41 @@
|
|
|
1
|
-
import { AxiosInstance } from
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration object for the Axios instance.
|
|
4
|
+
*/
|
|
5
|
+
interface AxiosConfig {
|
|
6
|
+
baseURL: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Configuration object for a custom Axios instance.
|
|
10
|
+
*/
|
|
11
|
+
interface CustomAxiosConfig {
|
|
12
|
+
baseURL: string;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
}
|
|
2
15
|
/**
|
|
3
16
|
* Configures the global Axios instance with a base URL.
|
|
4
|
-
*
|
|
17
|
+
*
|
|
18
|
+
* @param {AxiosConfig} config - An object containing the base URL for the Axios instance.
|
|
19
|
+
* @param {string} config.baseURL - The base URL for the Axios instance.
|
|
20
|
+
*
|
|
21
|
+
* @returns {void}
|
|
5
22
|
*/
|
|
6
|
-
export declare const configAxios: (
|
|
23
|
+
export declare const configAxios: (config: AxiosConfig) => void;
|
|
7
24
|
/**
|
|
8
25
|
* Retrieves the configured Axios instance.
|
|
26
|
+
*
|
|
9
27
|
* @returns {AxiosService} The configured Axios instance.
|
|
10
28
|
* @throws Will throw an error if the Axios instance is not configured.
|
|
11
29
|
*/
|
|
12
30
|
export declare const getAxiosInstance: () => AxiosInstance;
|
|
13
31
|
/**
|
|
14
32
|
* Creates a new AxiosService instance with custom headers.
|
|
15
|
-
*
|
|
16
|
-
* @param {
|
|
33
|
+
*
|
|
34
|
+
* @param {CustomAxiosConfig} config - An object containing the base URL and optional custom headers.
|
|
35
|
+
* @param {string} config.baseURL - The base URL for the Axios instance.
|
|
36
|
+
* @param {Record<string, string>} [config.headers] - Custom headers to set (optional).
|
|
37
|
+
*
|
|
17
38
|
* @returns {AxiosService} The new AxiosService instance.
|
|
18
39
|
*/
|
|
19
|
-
export declare const createCustomAxiosInstance: (
|
|
40
|
+
export declare const createCustomAxiosInstance: (config: CustomAxiosConfig) => AxiosInstance;
|
|
41
|
+
export {};
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { EndpointsConfig } from "@/types";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration object for authentication endpoints.
|
|
4
|
+
*/
|
|
5
|
+
interface EndpointConfig {
|
|
6
|
+
loginEndpoint: string;
|
|
7
|
+
refreshEndpoint: string;
|
|
8
|
+
logoutEndpoint: string;
|
|
9
|
+
}
|
|
2
10
|
/**
|
|
3
11
|
* Configures authentication endpoint URLs globally.
|
|
4
12
|
* This function freezes the object to prevent further modifications.
|
|
5
13
|
*
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {string}
|
|
8
|
-
* @param {string}
|
|
14
|
+
* @param {EndpointConfig} config - An object containing the authentication endpoint URLs.
|
|
15
|
+
* @param {string} config.loginEndpoint - URL of the login endpoint.
|
|
16
|
+
* @param {string} config.refreshEndpoint - URL of the refresh token endpoint.
|
|
17
|
+
* @param {string} config.logoutEndpoint - URL of the logout endpoint.
|
|
9
18
|
*
|
|
10
19
|
* @returns {void} Does not return anything but freezes the endpoint configuration object.
|
|
11
20
|
*/
|
|
12
|
-
export declare function configEndpoints(
|
|
21
|
+
export declare function configEndpoints(config: EndpointConfig): void;
|
|
13
22
|
/**
|
|
14
23
|
* Retrieves the configured authentication endpoint URLs.
|
|
15
24
|
*
|
|
@@ -19,3 +28,4 @@ export declare function configEndpoints(loginEndpoint: string, refreshEndpoint:
|
|
|
19
28
|
* @property {string} LOGOUT - URL of the logout endpoint.
|
|
20
29
|
*/
|
|
21
30
|
export declare function getEndpointsConfig(): EndpointsConfig;
|
|
31
|
+
export {};
|
|
@@ -1,18 +1,34 @@
|
|
|
1
|
+
export type SessionPreference = "local" | "session";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
3
|
+
* Configuration object for the session.
|
|
4
|
+
*/
|
|
5
|
+
interface SessionConfigObject {
|
|
6
|
+
/** The unique session identifier. */
|
|
7
|
+
sessionId?: string;
|
|
8
|
+
/** The storage preference: 'local' for localStorage, 'session' for sessionStorage. */
|
|
9
|
+
persistencePreference?: SessionPreference;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configures the session identifier and/or the data persistence preference for the active browser session.
|
|
13
|
+
* Once configured, the session ID cannot be modified. The persistence preference can be updated.
|
|
4
14
|
*
|
|
5
|
-
* @param {
|
|
15
|
+
* @param {SessionConfigObject} config - An object containing the unique session identifier and/or persistence preference.
|
|
6
16
|
*
|
|
7
|
-
* @returns {void} Does not return anything, but freezes the session configuration.
|
|
17
|
+
* @returns {void} Does not return anything, but freezes the session configuration (for ID) and updates preference.
|
|
8
18
|
*/
|
|
9
|
-
export declare function configSession(
|
|
19
|
+
export declare function configSession(config: SessionConfigObject): void;
|
|
10
20
|
/**
|
|
11
21
|
* Retrieves the current session identifier configuration.
|
|
12
22
|
*
|
|
13
23
|
* @returns {string} The unique session identifier.
|
|
14
24
|
*/
|
|
15
25
|
export declare function getSessionConfig(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the current data persistence preference.
|
|
28
|
+
*
|
|
29
|
+
* @returns {SessionPreference} The configured persistence preference ('local' or 'session').
|
|
30
|
+
*/
|
|
31
|
+
export declare function getSessionPersistencePreference(): SessionPreference;
|
|
16
32
|
/**
|
|
17
33
|
* Generates a new UUID for the current session.
|
|
18
34
|
*
|
|
@@ -25,3 +41,4 @@ export declare function regenerateSessionId(): void;
|
|
|
25
41
|
* @returns {string} The unique session identifier.
|
|
26
42
|
*/
|
|
27
43
|
export declare function getSessionId(): string;
|
|
44
|
+
export {};
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { TokensConfig } from "@/types";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration object for token keys.
|
|
4
|
+
*/
|
|
5
|
+
interface TokenKeyConfig {
|
|
6
|
+
accessTokenKey: string;
|
|
7
|
+
refreshTokenKey: string;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* Configures the global keys for access and refresh tokens.
|
|
4
11
|
* Once set, they cannot be modified.
|
|
5
12
|
*
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {string}
|
|
13
|
+
* @param {TokenKeyConfig} config - An object containing the token keys.
|
|
14
|
+
* @param {string} config.accessTokenKey - The name of the key for the access token.
|
|
15
|
+
* @param {string} config.refreshTokenKey - The name of the key for the refresh token.
|
|
8
16
|
*
|
|
9
|
-
* @returns {void} Does not return anything but freezes the token configuration object.
|
|
17
|
+
* @returns {void} Does not return anything, but freezes the token configuration object.
|
|
10
18
|
*/
|
|
11
|
-
export declare function configTokenKeys(
|
|
19
|
+
export declare function configTokenKeys(config: TokenKeyConfig): void;
|
|
12
20
|
/**
|
|
13
21
|
* Retrieves the current token configuration.
|
|
14
22
|
*
|
|
@@ -29,3 +37,4 @@ export declare function setSecretKey(key: string): void;
|
|
|
29
37
|
* @returns {string} The configured secret key.
|
|
30
38
|
*/
|
|
31
39
|
export declare function getSecretKey(): string;
|
|
40
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { App } from "vue";
|
|
2
|
+
import { ArexVueCoreOptions } from "./types/ArexVueCoreOptions";
|
|
3
|
+
/**
|
|
4
|
+
* The Vue plugin for @arex95/vue-core.
|
|
5
|
+
* Configures the core functionalities for authentication and API communication.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ArexVueCore: {
|
|
8
|
+
/**
|
|
9
|
+
* The `install` method is the entry point for the Vue plugin.
|
|
10
|
+
* It is automatically called when `app.use(ArexVueCore, options)` is executed.
|
|
11
|
+
*
|
|
12
|
+
* @param app The Vue application instance.
|
|
13
|
+
* @param options The configuration options provided by the user.
|
|
14
|
+
*/
|
|
15
|
+
install: (app: App, options: ArexVueCoreOptions) => void;
|
|
16
|
+
};
|
|
17
|
+
export * from "./rest";
|
|
18
|
+
export * from "./composables";
|
|
19
|
+
export * from "./config";
|
|
20
|
+
export * from "./enums";
|
|
21
|
+
export * from "./types";
|
|
22
|
+
export * from "./utils";
|