@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.
@@ -0,0 +1,26 @@
1
+ export interface ArexVueCoreOptions {
2
+ /**
3
+ * The authentication endpoints.
4
+ */
5
+ endpoints: {
6
+ /** The login endpoint. */
7
+ login: string;
8
+ /** The token refresh endpoint. */
9
+ refresh: string;
10
+ /** The logout endpoint. */
11
+ logout: string;
12
+ };
13
+ /**
14
+ * The key prefixes for storing tokens.
15
+ */
16
+ tokenKeys: {
17
+ /** The access token key prefix. */
18
+ accessToken: string;
19
+ /** The refresh token key prefix. */
20
+ refreshToken: string;
21
+ };
22
+ /**
23
+ * The base URL for the API.
24
+ */
25
+ apiUrl: string;
26
+ }
@@ -0,0 +1,4 @@
1
+ export interface AuthParams {
2
+ username?: string;
3
+ password?: string;
4
+ }
@@ -0,0 +1,5 @@
1
+ export interface AuthResponse {
2
+ access_token: string;
3
+ refresh_token: string;
4
+ [key: string]: unknown;
5
+ }
@@ -0,0 +1,9 @@
1
+ export interface DecodedJwtPayload {
2
+ exp?: number;
3
+ iat?: number;
4
+ nbf?: number;
5
+ iss?: string;
6
+ sub?: string;
7
+ aud?: string | string[];
8
+ [key: string]: unknown;
9
+ }
@@ -5,3 +5,7 @@ export * from './EndpointsConfig';
5
5
  export * from './TokenConfig';
6
6
  export * from './AuthConfig';
7
7
  export * from './SessionConfig';
8
+ export * from './DecodedJwtPayload';
9
+ export * from './AuthResponse';
10
+ export * from './AuthParams';
11
+ export * from './ArexVueCoreOptions';
@@ -0,0 +1,47 @@
1
+ import { SessionPreference } from "@config/global/sessionConfig";
2
+ /**
3
+ * Clears all stored authentication data (access and refresh tokens)
4
+ * from either sessionStorage or localStorage based on the provided preference.
5
+ *
6
+ * @param {SessionPreference} preference - The storage preference ('local' for localStorage, 'session' for sessionStorage).
7
+ * @returns {Promise<void>} A promise that resolves when all relevant storage items are removed.
8
+ */
9
+ export declare const cleanCredentials: (preference: SessionPreference) => 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, preference: SessionPreference) => 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, preference: SessionPreference) => 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, preference: SessionPreference) => 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, preference: SessionPreference) => Promise<void>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Converts an ArrayBuffer or Uint8Array to a hexadecimal string.
3
+ * @param buffer The ArrayBuffer or Uint8Array to convert.
4
+ * @returns The hexadecimal string.
5
+ */
6
+ export declare function ab2hex(buffer: ArrayBuffer | Uint8Array): string;
7
+ /**
8
+ * Converts a hexadecimal string to a Uint8Array.
9
+ * @param hex The hexadecimal string to convert.
10
+ * @returns The Uint8Array.
11
+ */
12
+ export declare function hex2ab(hex: string): Uint8Array;
13
+ /**
14
+ * Derives an encryption key from a secret key.
15
+ * @param secretKey The secret key in plain text.
16
+ * @returns A promise that resolves with the derived CryptoKey.
17
+ */
18
+ export declare function importKey(secretKey: string): Promise<CryptoKey>;
19
+ /**
20
+ * Encrypts a value with the provided secret key.
21
+ * @param value The value to encrypt.
22
+ * @param secretKey The secret key for encryption.
23
+ * @returns A promise that resolves with the IV (hex) + ciphertext (hex) string.
24
+ */
25
+ export declare function encrypt(value: string, secretKey: string): Promise<string>;
26
+ /**
27
+ * Decrypts an encrypted value.
28
+ * @param encryptedValue The encrypted string (IV_hex + ciphertext_hex).
29
+ * @param secretKey The secret key for decryption.
30
+ * @returns A promise that resolves with the decrypted value.
31
+ */
32
+ export declare function decrypt(encryptedValue: string, secretKey: string): Promise<string>;
@@ -7,3 +7,7 @@ export * from './files';
7
7
  export * from './objects';
8
8
  export * from './strings';
9
9
  export * from './validations';
10
+ export * from './credentials';
11
+ export * from './storage';
12
+ export * from './encryption';
13
+ export * from './errors';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Encrypts and stores an item in local or session storage.
3
+ * Assumes the `window` environment is available.
4
+ * @param key The key under which to store the value.
5
+ * @param value The value to encrypt and store.
6
+ * @param secretKey The secret key for encryption.
7
+ * @param isRememberMe If true, uses localStorage; otherwise, uses sessionStorage.
8
+ * @returns A promise that resolves when the item is stored. Throws an error if it fails.
9
+ */
10
+ export declare function storeEncryptedItem(key: string, value: string, secretKey: string, isRememberMe: boolean): Promise<void>;
11
+ /**
12
+ * Retrieves and decrypts a value from local or session storage.
13
+ * Assumes the `window` environment is available.
14
+ * @param key The key of the item to retrieve.
15
+ * @param secretKey The secret key for decryption.
16
+ * @param isRememberMe If true, searches localStorage; otherwise, sessionStorage.
17
+ * @returns A promise that resolves with the decrypted value or null if not found or decryption fails.
18
+ */
19
+ export declare function getDecryptedItem(key: string, secretKey: string, isRememberMe: boolean): Promise<string | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arex95/vue-core",
3
- "version": "1.1.19",
3
+ "version": "1.1.21",
4
4
  "description": "Opinionated Vue Core",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -49,6 +49,7 @@
49
49
  "@rollup/plugin-typescript": "^12.1.2",
50
50
  "@types/crypto-js": "^4.2.2",
51
51
  "@types/node": "^22.13.10",
52
+ "@vitest/spy": "^3.2.3",
52
53
  "@vitest/ui": "^3.2.3",
53
54
  "@vue/test-utils": "^2.4.6",
54
55
  "conventional-changelog-cli": "^5.0.0",