@arex95/vue-core 3.3.0 → 5.1.0
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/README.md +196 -55
- package/dist/config/axios/axiosConfig.d.ts +8 -32
- package/dist/index.mjs +228 -230
- package/dist/services/credentials.d.ts +10 -29
- package/dist/services/refreshTokens.d.ts +11 -8
- package/dist/utils/encryption.d.ts +7 -27
- package/dist/utils/storage.d.ts +29 -18
- package/package.json +1 -1
|
@@ -1,51 +1,32 @@
|
|
|
1
|
-
import { LocationPreference } from
|
|
1
|
+
import { LocationPreference } from '@/types/SessionConfig';
|
|
2
2
|
/**
|
|
3
|
-
* Removes all stored authentication credentials (access
|
|
3
|
+
* Removes all stored authentication credentials (access + refresh tokens)
|
|
4
|
+
* from the specified storage location(s).
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @returns {Promise<void>} A promise that resolves when the credentials have been cleared.
|
|
6
|
+
* With location='any', ALL storage locations are cleared — including cookies.
|
|
7
|
+
* This prevents orphaned tokens surviving a logout.
|
|
8
8
|
*/
|
|
9
9
|
export declare const cleanCredentials: (location: LocationPreference) => Promise<void>;
|
|
10
10
|
/**
|
|
11
11
|
* Retrieves and decrypts the access token from the specified storage location.
|
|
12
|
-
*
|
|
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.
|
|
16
12
|
*/
|
|
17
13
|
export declare const getAuthToken: (secretKey: string, location: LocationPreference) => Promise<string | null>;
|
|
18
14
|
/**
|
|
19
15
|
* Retrieves and decrypts the refresh token from the specified storage location.
|
|
20
|
-
*
|
|
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.
|
|
24
16
|
*/
|
|
25
17
|
export declare const getAuthRefreshToken: (secretKey: string, location: LocationPreference) => Promise<string | null>;
|
|
26
18
|
/**
|
|
27
|
-
* Encrypts and stores the access token
|
|
28
|
-
*
|
|
29
|
-
* @param {string} token - The access token to store.
|
|
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.
|
|
19
|
+
* Encrypts and stores the access token.
|
|
33
20
|
*/
|
|
34
21
|
export declare const storeAuthToken: (token: string, secretKey: string, location: LocationPreference) => Promise<void>;
|
|
35
22
|
/**
|
|
36
|
-
* Encrypts and stores the refresh token
|
|
37
|
-
*
|
|
38
|
-
* @param {string} token - The refresh token to store.
|
|
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.
|
|
23
|
+
* Encrypts and stores the refresh token.
|
|
42
24
|
*/
|
|
43
25
|
export declare const storeAuthRefreshToken: (token: string, secretKey: string, location: LocationPreference) => Promise<void>;
|
|
44
26
|
/**
|
|
45
|
-
* Verifies the current user's authentication status by checking for a
|
|
46
|
-
*
|
|
47
|
-
* If the token is missing, malformed, or expired, it logs the issue, clears credentials, and returns `false`.
|
|
27
|
+
* Verifies the current user's authentication status by checking for a
|
|
28
|
+
* valid, unexpired access token across all storage locations.
|
|
48
29
|
*
|
|
49
|
-
*
|
|
30
|
+
* Returns false (without throwing) if the token is missing, malformed, or expired.
|
|
50
31
|
*/
|
|
51
32
|
export declare const verifyAuth: () => Promise<boolean>;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { AuthResponse, Fetcher } from
|
|
1
|
+
import { AuthResponse, Fetcher } from '@/types';
|
|
2
2
|
/**
|
|
3
|
-
* Refreshes the access and refresh tokens
|
|
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.
|
|
3
|
+
* Refreshes the access and refresh tokens.
|
|
7
4
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* Fixes over the original:
|
|
6
|
+
* 1. Uses `persistence` (the location where tokens were originally stored)
|
|
7
|
+
* instead of hardcoding `"any"` — so cookies / localStorage / sessionStorage
|
|
8
|
+
* are searched in the right place.
|
|
9
|
+
* 2. Sends the refresh token in the request body using the configured
|
|
10
|
+
* `refreshTokenPaths.refreshTokenPath` as the body key, so the backend
|
|
11
|
+
* always receives it regardless of withCredentials or cookie settings.
|
|
12
|
+
*
|
|
13
|
+
* On failure: clears credentials and calls `onRefreshFailed` callback.
|
|
11
14
|
*/
|
|
12
15
|
export declare const refreshTokens: (fetcher?: Fetcher) => Promise<AuthResponse>;
|
|
@@ -1,44 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Converts an `ArrayBuffer` or `Uint8Array` into a hexadecimal string
|
|
3
|
-
*
|
|
4
|
-
* @param {ArrayBuffer | Uint8Array} buffer - The buffer to convert.
|
|
5
|
-
* @returns {string} The resulting hexadecimal string.
|
|
2
|
+
* Converts an `ArrayBuffer` or `Uint8Array` into a hexadecimal string.
|
|
6
3
|
*/
|
|
7
4
|
export declare function ab2hex(buffer: ArrayBuffer | Uint8Array): string;
|
|
8
5
|
/**
|
|
9
6
|
* Converts a hexadecimal string into a `Uint8Array`.
|
|
10
|
-
*
|
|
11
|
-
* @param {string} hex - The hexadecimal string to convert.
|
|
12
|
-
* @returns {Uint8Array} The resulting `Uint8Array`.
|
|
13
|
-
* @throws {TypeError} If the input is not a string.
|
|
14
|
-
* @throws {Error} If the hexadecimal string has an invalid format or an odd length.
|
|
15
7
|
*/
|
|
16
8
|
export declare function hex2ab(hex: string): Uint8Array;
|
|
17
9
|
/**
|
|
18
|
-
* Derives a
|
|
19
|
-
* It uses SHA-256 to hash the secret key, ensuring a fixed-length key suitable for the Web Crypto API.
|
|
10
|
+
* Derives a CryptoKey for AES-CBC-256 from a plain-text secret using SHA-256.
|
|
20
11
|
*
|
|
21
|
-
* @
|
|
22
|
-
* @returns {Promise<CryptoKey>} A promise that resolves with the derived `CryptoKey`.
|
|
23
|
-
* @throws {Error} If the `secretKey` is null or empty.
|
|
12
|
+
* @throws {Error} If secretKey is empty or Web Crypto API is unavailable.
|
|
24
13
|
*/
|
|
25
14
|
export declare function importKey(secretKey: string): Promise<CryptoKey>;
|
|
26
15
|
/**
|
|
27
|
-
* Encrypts a plain-text
|
|
28
|
-
* A
|
|
29
|
-
*
|
|
30
|
-
* @param {string} value - The plain-text string to encrypt.
|
|
31
|
-
* @param {string} secretKey - The secret key to use for encryption.
|
|
32
|
-
* @returns {Promise<string>} A promise that resolves with a concatenated hexadecimal string of the IV and the ciphertext.
|
|
33
|
-
* @throws {Error} If the `secretKey` is null or empty.
|
|
16
|
+
* Encrypts a plain-text string using AES-CBC-256.
|
|
17
|
+
* A unique 16-byte IV is generated per call.
|
|
18
|
+
* Output format: IV_hex (32 chars) + ciphertext_hex.
|
|
34
19
|
*/
|
|
35
20
|
export declare function encrypt(value: string, secretKey: string): Promise<string>;
|
|
36
21
|
/**
|
|
37
|
-
* Decrypts a
|
|
38
|
-
*
|
|
39
|
-
* @param {string} encryptedValue - The concatenated hexadecimal string of the IV and ciphertext.
|
|
40
|
-
* @param {string} secretKey - The secret key to use for decryption.
|
|
41
|
-
* @returns {Promise<string>} A promise that resolves with the decrypted plain-text string.
|
|
42
|
-
* @throws {Error} If the encrypted value is null, empty, or too short, or if the `secretKey` is invalid.
|
|
22
|
+
* Decrypts a hex string (IV_hex + ciphertext_hex) produced by `encrypt()`.
|
|
43
23
|
*/
|
|
44
24
|
export declare function decrypt(encryptedValue: string, secretKey: string): Promise<string>;
|
package/dist/utils/storage.d.ts
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
import { LocationPreference } from
|
|
2
|
-
import { CookieOptions } from
|
|
1
|
+
import { LocationPreference } from '@/types';
|
|
2
|
+
import { CookieOptions } from './ssr';
|
|
3
3
|
/**
|
|
4
|
-
* Encrypts and stores a
|
|
5
|
-
* Cookies are automatically used in SSR environments and can be explicitly requested.
|
|
6
|
-
* Cookies include security options: Secure (HTTPS only), SameSite (CSRF protection), and encryption.
|
|
4
|
+
* Encrypts and stores a value in the requested storage.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
6
|
+
* | location | where it goes | persistence |
|
|
7
|
+
* |-----------|----------------------------|---------------------|
|
|
8
|
+
* | 'cookie' | document.cookie | expires option |
|
|
9
|
+
* | 'local' | localStorage | until explicitly cleared |
|
|
10
|
+
* | 'any' | localStorage | until explicitly cleared |
|
|
11
|
+
* | 'session' | sessionStorage | until tab closes |
|
|
12
|
+
*
|
|
13
|
+
* Note: 'any' stores in localStorage (same as 'local') for maximum
|
|
14
|
+
* persistence. Previously it stored in sessionStorage — that was a bug.
|
|
15
|
+
*
|
|
16
|
+
* In SSR environments cookies are always used regardless of location
|
|
17
|
+
* (localStorage / sessionStorage do not exist on the server).
|
|
14
18
|
*/
|
|
15
19
|
export declare function storeEncryptedItem(key: string, value: string, secretKey: string, location: LocationPreference, cookieOptions?: CookieOptions): Promise<void>;
|
|
16
20
|
/**
|
|
17
|
-
* Retrieves and decrypts
|
|
18
|
-
*
|
|
19
|
-
*
|
|
21
|
+
* Retrieves and decrypts a value from storage.
|
|
22
|
+
*
|
|
23
|
+
* Search order by location:
|
|
24
|
+
*
|
|
25
|
+
* | location | search order |
|
|
26
|
+
* |-----------|-------------------------------------------|
|
|
27
|
+
* | 'cookie' | cookies only |
|
|
28
|
+
* | 'local' | localStorage only |
|
|
29
|
+
* | 'session' | sessionStorage only |
|
|
30
|
+
* | 'any' | sessionStorage → localStorage → cookies |
|
|
31
|
+
*
|
|
32
|
+
* In SSR, cookies are always checked first (localStorage / sessionStorage
|
|
33
|
+
* are not available on the server).
|
|
20
34
|
*
|
|
21
|
-
*
|
|
22
|
-
* @param {string} secretKey - The secret key to use for decryption.
|
|
23
|
-
* @param {LocationPreference} location - The storage location to search: 'local', 'session', 'cookie', or 'any' (checks session, local, cookie in that order).
|
|
24
|
-
* @returns {Promise<string | null>} A promise that resolves with the decrypted value, or `null` if the item is not found or decryption fails.
|
|
35
|
+
* Returns null if the key is not found or decryption fails.
|
|
25
36
|
*/
|
|
26
37
|
export declare function getDecryptedItem(key: string, secretKey: string, location: LocationPreference): Promise<string | null>;
|