@temboplus/afloat 0.1.77-beta.2 → 0.1.77-beta.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/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/api/base-repository.d.ts +3 -1
- package/dist/lib/query/query.builder.d.ts +5 -1
- package/dist/modules/auth/auth.contract.d.ts +2 -2
- package/dist/modules/auth/company-membership.model.d.ts +122 -9
- package/dist/modules/auth/index.d.ts +0 -1
- package/dist/modules/auth/user.model.d.ts +238 -15
- package/dist/modules/contact/contact-info.model.d.ts +183 -533
- package/dist/modules/contact/contact.api-contract.d.ts +8 -8
- package/dist/modules/contact/contact.dtos.d.ts +2 -2
- package/dist/modules/contact/contact.model.d.ts +309 -32
- package/dist/modules/login/login.api-contract.d.ts +2 -2
- package/dist/modules/login/login.dtos.d.ts +4 -4
- package/dist/modules/login/login.model.d.ts +54 -24
- package/dist/modules/payout/payout.api-contract.d.ts +37 -37
- package/dist/modules/payout/payout.dtos.d.ts +47 -39
- package/dist/modules/payout/payout.model.d.ts +242 -2
- package/dist/modules/payout/payout.query.d.ts +11 -3
- package/dist/modules/payout/payout.repository.d.ts +48 -25
- package/dist/modules/profile/profile.model.d.ts +65 -30
- package/dist/modules/team-member/role.model.d.ts +49 -1
- package/dist/modules/team-member/team-member.contract.d.ts +44 -44
- package/dist/modules/team-member/team-member.dtos.d.ts +14 -14
- package/dist/modules/team-member/team-member.model.d.ts +106 -6
- package/dist/modules/wallet/index.d.ts +0 -1
- package/dist/modules/wallet/narration.model.d.ts +34 -38
- package/dist/modules/wallet/statement-entry.model.d.ts +172 -73
- package/dist/modules/wallet/wallet.contract.d.ts +6 -6
- package/dist/modules/wallet/wallet.dtos.d.ts +12 -12
- package/dist/modules/wallet/wallet.model.d.ts +56 -19
- package/dist/modules/wallet/wallet.query.d.ts +95 -0
- package/dist/modules/wallet/wallet.repository.d.ts +45 -13
- package/package.json +2 -2
- package/dist/modules/auth/auth.manager.d.ts +0 -249
- package/dist/modules/auth/auth.store.d.ts +0 -139
- package/dist/modules/auth/storage/client-store.d.ts +0 -29
- package/dist/modules/auth/storage/client-token-handler.d.ts +0 -31
- package/dist/modules/auth/storage/types.d.ts +0 -41
- package/dist/modules/wallet/wallet-manager.session.d.ts +0 -143
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { QueryBuilder } from "@/lib/query/index.js";
|
|
2
|
+
import { WalletQueryDTO } from "./wallet.dtos.js";
|
|
3
|
+
/**
|
|
4
|
+
* Wallet-specific query builder that extends the base QueryBuilder
|
|
5
|
+
* and handles all possible input conversions (DTOs, URL params, etc.)
|
|
6
|
+
*/
|
|
7
|
+
export declare class WalletQuery extends QueryBuilder {
|
|
8
|
+
/**
|
|
9
|
+
* Create empty wallet query with defaults
|
|
10
|
+
*/
|
|
11
|
+
static create(): WalletQuery;
|
|
12
|
+
/**
|
|
13
|
+
* Create from typed DTO/filters object
|
|
14
|
+
*/
|
|
15
|
+
static fromFilters(filters: WalletQueryDTO): WalletQuery;
|
|
16
|
+
/**
|
|
17
|
+
* Create from URL search parameters (strings)
|
|
18
|
+
*/
|
|
19
|
+
static fromUrlParams(params: Record<string, string>): WalletQuery;
|
|
20
|
+
/**
|
|
21
|
+
* Create from URLSearchParams object
|
|
22
|
+
*/
|
|
23
|
+
static fromSearchParams(searchParams: URLSearchParams): WalletQuery;
|
|
24
|
+
/**
|
|
25
|
+
* Create from Next.js Request object
|
|
26
|
+
*/
|
|
27
|
+
static fromRequest(request: Request): WalletQuery;
|
|
28
|
+
/**
|
|
29
|
+
* Create from any supported input type
|
|
30
|
+
*/
|
|
31
|
+
static from(input: QueryBuilder | WalletQueryDTO | Record<string, string> | URLSearchParams | null | undefined): WalletQuery;
|
|
32
|
+
/**
|
|
33
|
+
* Type guard for string records
|
|
34
|
+
*/
|
|
35
|
+
private static isStringRecord;
|
|
36
|
+
whereId(id: string): this;
|
|
37
|
+
whereProfileId(profileId: string): this;
|
|
38
|
+
whereAccountNo(accountNo: string): this;
|
|
39
|
+
whereAccountName(accountName: string): this;
|
|
40
|
+
whereChannel(channel: string): this;
|
|
41
|
+
whereCountryCode(countryCode: string): this;
|
|
42
|
+
whereCurrencyCode(currencyCode: string): this;
|
|
43
|
+
/**
|
|
44
|
+
* Apply all filters from WalletQueryDTO object
|
|
45
|
+
*/
|
|
46
|
+
private applyFilters;
|
|
47
|
+
/**
|
|
48
|
+
* Convert to WalletQueryDTO
|
|
49
|
+
*/
|
|
50
|
+
toFilters(): WalletQueryDTO;
|
|
51
|
+
/**
|
|
52
|
+
* Convert to URL-safe string parameters
|
|
53
|
+
*/
|
|
54
|
+
toUrlParams(): Record<string, string>;
|
|
55
|
+
/**
|
|
56
|
+
* Convert to URLSearchParams
|
|
57
|
+
*/
|
|
58
|
+
toSearchParams(): URLSearchParams;
|
|
59
|
+
/**
|
|
60
|
+
* Convert to query string
|
|
61
|
+
*/
|
|
62
|
+
toQueryString(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Create new instance with wallet ID filter
|
|
65
|
+
*/
|
|
66
|
+
withId(id: string): WalletQuery;
|
|
67
|
+
/**
|
|
68
|
+
* Create new instance with profile ID filter
|
|
69
|
+
*/
|
|
70
|
+
withProfileId(profileId: string): WalletQuery;
|
|
71
|
+
/**
|
|
72
|
+
* Create new instance with account number filter
|
|
73
|
+
*/
|
|
74
|
+
withAccountNo(accountNo: string): WalletQuery;
|
|
75
|
+
/**
|
|
76
|
+
* Create new instance with country code filter
|
|
77
|
+
*/
|
|
78
|
+
withCountryCode(countryCode: string): WalletQuery;
|
|
79
|
+
/**
|
|
80
|
+
* Create new instance with currency code filter
|
|
81
|
+
*/
|
|
82
|
+
withCurrencyCode(currencyCode: string): WalletQuery;
|
|
83
|
+
/**
|
|
84
|
+
* Check if any filters are applied
|
|
85
|
+
*/
|
|
86
|
+
hasFilters(): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Get human-readable filter descriptions
|
|
89
|
+
*/
|
|
90
|
+
getActiveFilters(): string[];
|
|
91
|
+
/**
|
|
92
|
+
* Extract filter values from QueryBuilder options
|
|
93
|
+
*/
|
|
94
|
+
private extractFilterValues;
|
|
95
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Amount } from "@temboplus/frontend-core";
|
|
2
2
|
import { WalletStatementEntry } from "./statement-entry.model.js";
|
|
3
3
|
import { Wallet } from "./wallet.model.js";
|
|
4
|
-
import { WalletDTOSchemas } from "./wallet.dtos.js";
|
|
5
|
-
import { z } from "zod";
|
|
6
4
|
import { contract } from "./wallet.contract.js";
|
|
7
5
|
import { BaseRepository } from "@/lib/api/base-repository.js";
|
|
6
|
+
import { WalletQuery } from "./wallet.query.js";
|
|
7
|
+
import { WalletQueryDTO } from "./wallet.dtos.js";
|
|
8
|
+
/**
|
|
9
|
+
* Flexible query input type - supports the class, filters interface, URL params, etc.
|
|
10
|
+
*/
|
|
11
|
+
export type WalletQueryInput = WalletQuery | WalletQueryDTO | Record<string, string> | URLSearchParams | null | undefined;
|
|
8
12
|
/**
|
|
9
13
|
* Repository class for managing wallet operations including balance checking,
|
|
10
14
|
* statement generation, and wallet information retrieval.
|
|
@@ -87,13 +91,9 @@ export declare class WalletRepository extends BaseRepository<typeof contract> {
|
|
|
87
91
|
/**
|
|
88
92
|
* Retrieves all wallets associated with the authenticated user.
|
|
89
93
|
*
|
|
90
|
-
* Supports
|
|
91
|
-
* status, or currency filtering.
|
|
94
|
+
* Supports flexible filtering through WalletQuery or plain filter objects.
|
|
92
95
|
*
|
|
93
96
|
* @param query - Optional query parameters for filtering wallets
|
|
94
|
-
* @param query.accountNo - Filter by specific account number
|
|
95
|
-
* @param query.status - Filter by wallet status (active, inactive, etc.)
|
|
96
|
-
* @param query.currencyCode - Filter by currency code
|
|
97
97
|
* @returns Promise that resolves to an array of validated Wallet instances
|
|
98
98
|
* @throws {Error} If the wallet fetch operation fails or data is invalid
|
|
99
99
|
*
|
|
@@ -105,14 +105,38 @@ export declare class WalletRepository extends BaseRepository<typeof contract> {
|
|
|
105
105
|
* // Get specific wallet by account number
|
|
106
106
|
* const specificWallet = await repo.getWallets({ accountNo: '123456789' });
|
|
107
107
|
*
|
|
108
|
-
* // Get wallets with multiple filters
|
|
109
|
-
* const
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
108
|
+
* // Get wallets with multiple filters using WalletQuery
|
|
109
|
+
* const query = WalletQuery.create()
|
|
110
|
+
* .whereCountryCode('TZ')
|
|
111
|
+
* .whereCurrencyCode('TZS');
|
|
112
|
+
* const tzWallets = await repo.getWallets(query);
|
|
113
|
+
*
|
|
114
|
+
* // Get wallets with filters object
|
|
115
|
+
* const usdWallets = await repo.getWallets({ currencyCode: 'USD' });
|
|
113
116
|
* ```
|
|
114
117
|
*/
|
|
115
|
-
getWallets(query?:
|
|
118
|
+
getWallets(query?: WalletQueryInput): Promise<Wallet[]>;
|
|
119
|
+
/**
|
|
120
|
+
* Retrieves a single wallet by its ID.
|
|
121
|
+
*
|
|
122
|
+
* Since the API doesn't have a dedicated /id endpoint, this method queries
|
|
123
|
+
* the list endpoint with the ID filter and returns the first result.
|
|
124
|
+
*
|
|
125
|
+
* @param id - The unique identifier of the wallet to retrieve
|
|
126
|
+
* @returns Promise that resolves to the wallet if found, undefined otherwise
|
|
127
|
+
* @throws {Error} If the fetch operation fails
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const wallet = await repo.getByID("wallet-id");
|
|
132
|
+
* if (wallet) {
|
|
133
|
+
* console.log(`Wallet: ${wallet.accountName}`);
|
|
134
|
+
* } else {
|
|
135
|
+
* console.log('Wallet not found');
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
getByID(id: string): Promise<Wallet | undefined>;
|
|
116
140
|
/**
|
|
117
141
|
* Retrieves wallet statement entries for a specified date range.
|
|
118
142
|
*
|
|
@@ -170,4 +194,12 @@ export declare class WalletRepository extends BaseRepository<typeof contract> {
|
|
|
170
194
|
wallet?: Wallet;
|
|
171
195
|
accountNo?: string;
|
|
172
196
|
}): Promise<WalletStatementEntry[]>;
|
|
197
|
+
/**
|
|
198
|
+
* Check if a wallet exists with the given query
|
|
199
|
+
*/
|
|
200
|
+
exists(query?: WalletQueryInput): Promise<boolean>;
|
|
201
|
+
/**
|
|
202
|
+
* Get count of wallets matching a query
|
|
203
|
+
*/
|
|
204
|
+
count(query?: WalletQueryInput): Promise<number>;
|
|
173
205
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temboplus/afloat",
|
|
3
|
-
"version": "0.1.77-beta.
|
|
3
|
+
"version": "0.1.77-beta.21",
|
|
4
4
|
"description": "A foundational library for Temboplus-Afloat projects.",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -58,6 +58,6 @@
|
|
|
58
58
|
"typescript": "^5.8.3"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@temboplus/frontend-core": "^0.2.
|
|
61
|
+
"@temboplus/frontend-core": "^0.2.20-beta.5"
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { Permission } from "@/modules/login/permission.type.js";
|
|
2
|
-
import { User } from "@/modules/auth/user.model.js";
|
|
3
|
-
/**
|
|
4
|
-
* Clean authentication manager for client-side usage only.
|
|
5
|
-
*
|
|
6
|
-
* This class provides a centralized way to manage user authentication state,
|
|
7
|
-
* including login, logout, and permission checking. It uses a singleton pattern
|
|
8
|
-
* for client-side usage and directly interfaces with the unified auth store.
|
|
9
|
-
*
|
|
10
|
-
* **Architecture:**
|
|
11
|
-
* - **Client-side**: Use the singleton instance via `AfloatAuth.instance`
|
|
12
|
-
* - **Server-side**: Pass tokens directly to repositories (no auth manager needed)
|
|
13
|
-
*
|
|
14
|
-
* **Features:**
|
|
15
|
-
* - Direct integration with unified auth store
|
|
16
|
-
* - React hooks for reactive UI updates
|
|
17
|
-
* - Permission checking utilities
|
|
18
|
-
* - Automatic wallet session management
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* // Client-side usage
|
|
23
|
-
* const auth = AfloatAuth.instance;
|
|
24
|
-
* const user = await auth.logIn(email, password);
|
|
25
|
-
*
|
|
26
|
-
* // Server-side usage (no auth manager needed)
|
|
27
|
-
* const walletRepo = new WalletRepository({ token: extractedToken });
|
|
28
|
-
* const balance = await walletRepo.getBalance({ wallet });
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare class AfloatAuth {
|
|
32
|
-
/** Client-side singleton instance */
|
|
33
|
-
private static _instance;
|
|
34
|
-
/**
|
|
35
|
-
* Private constructor to control instantiation.
|
|
36
|
-
* Use the static instance getter instead.
|
|
37
|
-
*
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
private constructor();
|
|
41
|
-
/**
|
|
42
|
-
* Gets or creates the client-side singleton instance.
|
|
43
|
-
*
|
|
44
|
-
* @returns The client-side singleton instance
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* const auth = AfloatAuth.instance;
|
|
49
|
-
* if (auth.currentUser) {
|
|
50
|
-
* console.log("User is logged in");
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
static get instance(): AfloatAuth;
|
|
55
|
-
/**
|
|
56
|
-
* Gets the authentication repository for API operations.
|
|
57
|
-
*
|
|
58
|
-
* @private
|
|
59
|
-
* @returns The auth repository instance with current token
|
|
60
|
-
*/
|
|
61
|
-
private get repo();
|
|
62
|
-
/**
|
|
63
|
-
* Gets the current authentication token.
|
|
64
|
-
*
|
|
65
|
-
* @returns The current authentication token, or undefined if not authenticated
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const token = auth.getUserToken();
|
|
70
|
-
* if (token) {
|
|
71
|
-
* const apiClient = new SomeRepository({ token });
|
|
72
|
-
* }
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
getUserToken(): string | undefined;
|
|
76
|
-
/**
|
|
77
|
-
* Gets the currently authenticated user.
|
|
78
|
-
*
|
|
79
|
-
* @returns The current user instance, or undefined if not authenticated
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* const user = auth.currentUser;
|
|
84
|
-
* if (user) {
|
|
85
|
-
* console.log(`Welcome, ${user.name}!`);
|
|
86
|
-
* }
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
get currentUser(): User | undefined;
|
|
90
|
-
/**
|
|
91
|
-
* Checks if a user is currently authenticated.
|
|
92
|
-
*
|
|
93
|
-
* @returns True if user is authenticated, false otherwise
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```typescript
|
|
97
|
-
* if (auth.isAuthenticated) {
|
|
98
|
-
* // User is logged in
|
|
99
|
-
* showDashboard();
|
|
100
|
-
* } else {
|
|
101
|
-
* // User needs to log in
|
|
102
|
-
* showLoginForm();
|
|
103
|
-
* }
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
get isAuthenticated(): boolean;
|
|
107
|
-
/**
|
|
108
|
-
* React hook for accessing the current user in client-side components.
|
|
109
|
-
*
|
|
110
|
-
* This hook provides reactive updates when the user state changes,
|
|
111
|
-
* making it perfect for React components that need to respond to
|
|
112
|
-
* authentication state changes.
|
|
113
|
-
*
|
|
114
|
-
* @returns The current user with reactive updates, or undefined if not authenticated
|
|
115
|
-
* @throws {Error} If called in a server environment
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```typescript
|
|
119
|
-
* function UserProfile() {
|
|
120
|
-
* const user = AfloatAuth.instance.useCurrentUser();
|
|
121
|
-
*
|
|
122
|
-
* if (!user) {
|
|
123
|
-
* return <LoginForm />;
|
|
124
|
-
* }
|
|
125
|
-
*
|
|
126
|
-
* return <div>Hello, {user.name}!</div>;
|
|
127
|
-
* }
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
useCurrentUser(): User | undefined;
|
|
131
|
-
/**
|
|
132
|
-
* Checks if the current user has a specific permission.
|
|
133
|
-
*
|
|
134
|
-
* @param perm - The permission to check
|
|
135
|
-
* @returns True if the user has the permission, false otherwise
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```typescript
|
|
139
|
-
* if (auth.checkPermission(Permission.ViewBalance)) {
|
|
140
|
-
* // User can view wallet balance
|
|
141
|
-
* const walletRepo = new WalletRepository({ token: auth.getUserToken() });
|
|
142
|
-
* const balance = await walletRepo.getBalance(wallet);
|
|
143
|
-
* } else {
|
|
144
|
-
* console.log("User doesn't have permission to view balance");
|
|
145
|
-
* }
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
checkPermission(perm: Permission): boolean;
|
|
149
|
-
/**
|
|
150
|
-
* Authenticates a user with email and password.
|
|
151
|
-
*
|
|
152
|
-
* On successful authentication:
|
|
153
|
-
* - Clears any existing auth data
|
|
154
|
-
* - Stores the new user and token atomically
|
|
155
|
-
* - Initializes related services (wallet manager)
|
|
156
|
-
*
|
|
157
|
-
* @param email - The user's email address
|
|
158
|
-
* @param password - The user's password
|
|
159
|
-
* @returns Promise resolving to the authenticated user
|
|
160
|
-
* @throws {Error} If authentication fails
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* ```typescript
|
|
164
|
-
* try {
|
|
165
|
-
* const user = await auth.logIn("user@example.com", "password123");
|
|
166
|
-
* console.log("Login successful!");
|
|
167
|
-
* router.push("/dashboard");
|
|
168
|
-
* } catch (error) {
|
|
169
|
-
* console.error("Login failed:", error.message);
|
|
170
|
-
* setError("Invalid credentials");
|
|
171
|
-
* }
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
logIn(email: string, password: string): Promise<User>;
|
|
175
|
-
/**
|
|
176
|
-
* Updates the current user's password.
|
|
177
|
-
*
|
|
178
|
-
* @param currentPassword - The user's current password
|
|
179
|
-
* @param newPassword - The new password to set
|
|
180
|
-
* @returns Promise resolving to true if successful
|
|
181
|
-
* @throws {Error} If the password update fails or user is not authenticated
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* try {
|
|
186
|
-
* await auth.resetPassword("oldPassword", "newPassword123");
|
|
187
|
-
* console.log("Password updated successfully");
|
|
188
|
-
* showSuccessMessage("Password updated!");
|
|
189
|
-
* } catch (error) {
|
|
190
|
-
* console.error("Password update failed:", error.message);
|
|
191
|
-
* showErrorMessage("Failed to update password");
|
|
192
|
-
* }
|
|
193
|
-
* ```
|
|
194
|
-
*/
|
|
195
|
-
resetPassword(currentPassword: string, newPassword: string): Promise<boolean>;
|
|
196
|
-
/**
|
|
197
|
-
* Logs out the current user and clears all authentication data.
|
|
198
|
-
*
|
|
199
|
-
* This method:
|
|
200
|
-
* - Clears user state from memory and storage
|
|
201
|
-
* - Removes authentication tokens
|
|
202
|
-
* - Resets related services
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```typescript
|
|
206
|
-
* auth.logOut();
|
|
207
|
-
* router.push("/login");
|
|
208
|
-
* console.log("User logged out successfully");
|
|
209
|
-
* ```
|
|
210
|
-
*/
|
|
211
|
-
logOut(): void;
|
|
212
|
-
/**
|
|
213
|
-
* Refreshes the current authentication state.
|
|
214
|
-
* Useful for clearing potentially stale data.
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* ```typescript
|
|
218
|
-
* // Clear current state and force fresh authentication
|
|
219
|
-
* auth.refresh();
|
|
220
|
-
* ```
|
|
221
|
-
*/
|
|
222
|
-
refresh(): void;
|
|
223
|
-
/**
|
|
224
|
-
* Gets debug information about the current authentication state.
|
|
225
|
-
* Useful for troubleshooting authentication issues.
|
|
226
|
-
*
|
|
227
|
-
* @returns Object containing authentication state information
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```typescript
|
|
231
|
-
* const debugInfo = auth.getDebugInfo();
|
|
232
|
-
* console.log("Auth Debug Info:", debugInfo);
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
getDebugInfo(): {
|
|
236
|
-
hasUser: boolean;
|
|
237
|
-
hasToken: boolean;
|
|
238
|
-
isAuthenticated: boolean;
|
|
239
|
-
userName: string;
|
|
240
|
-
tokenLength: number;
|
|
241
|
-
managerInstance: string;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Clears all stored authentication data from the unified store.
|
|
245
|
-
*
|
|
246
|
-
* @private
|
|
247
|
-
*/
|
|
248
|
-
private clearSavedData;
|
|
249
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { type StoreApi, type UseBoundStore } from "zustand";
|
|
2
|
-
import { User } from "@/modules/auth/user.model.js";
|
|
3
|
-
/** Type definition for the store's internal state */
|
|
4
|
-
type AuthState = {
|
|
5
|
-
user: string | undefined;
|
|
6
|
-
token: string | undefined;
|
|
7
|
-
};
|
|
8
|
-
/** Type definition for the store's actions */
|
|
9
|
-
interface AuthActions {
|
|
10
|
-
setUser: (user: User) => void;
|
|
11
|
-
getUser: () => User | undefined;
|
|
12
|
-
setToken: (token: string) => void;
|
|
13
|
-
getToken: () => string | undefined;
|
|
14
|
-
setUserAndToken: (user: User, token: string) => void;
|
|
15
|
-
clearAuth: () => void;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Unified Zustand store for managing both user and token state with persistence.
|
|
19
|
-
*
|
|
20
|
-
* Features:
|
|
21
|
-
* - Persists both user data and token to sessionStorage
|
|
22
|
-
* - Serializes/deserializes User objects to/from JSON
|
|
23
|
-
* - Provides reactive state updates for React components
|
|
24
|
-
* - Automatically syncs user and token state
|
|
25
|
-
* - Server-side rendering safe
|
|
26
|
-
*/
|
|
27
|
-
export declare const authStore: UseBoundStore<StoreApi<AuthState & AuthActions>>;
|
|
28
|
-
/**
|
|
29
|
-
* Gets the current authenticated user from the auth store.
|
|
30
|
-
* This function can be called from anywhere in the application.
|
|
31
|
-
*
|
|
32
|
-
* @returns The current user or undefined if not authenticated
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* // In BaseRepository or any other file
|
|
37
|
-
* const user = getCurrentUser();
|
|
38
|
-
* if (user) {
|
|
39
|
-
* console.log(`Current user: ${user.name}`);
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare const getCurrentUser: () => User | undefined;
|
|
44
|
-
/**
|
|
45
|
-
* Gets the current authentication token from the auth store.
|
|
46
|
-
* This function can be called from anywhere in the application,
|
|
47
|
-
* including BaseRepository for automatic token injection.
|
|
48
|
-
*
|
|
49
|
-
* @returns The current token or undefined if not authenticated
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* // In BaseRepository
|
|
54
|
-
* const token = getCurrentToken();
|
|
55
|
-
* if (token) {
|
|
56
|
-
* // Use token for API calls
|
|
57
|
-
* return initClient(contract, { baseHeaders: { token } });
|
|
58
|
-
* }
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export declare const getCurrentToken: () => string | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* React hook to access the current user with reactive updates.
|
|
64
|
-
*
|
|
65
|
-
* @returns The current user or undefined if not authenticated
|
|
66
|
-
* @throws {Error} If called in a server environment
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```typescript
|
|
70
|
-
* function UserProfile() {
|
|
71
|
-
* const user = useCurrentUser();
|
|
72
|
-
*
|
|
73
|
-
* if (!user) {
|
|
74
|
-
* return <div>Please log in</div>;
|
|
75
|
-
* }
|
|
76
|
-
*
|
|
77
|
-
* return <div>Welcome, {user.name}!</div>;
|
|
78
|
-
* }
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
export declare const useCurrentUser: () => User | undefined;
|
|
82
|
-
/**
|
|
83
|
-
* React hook to access the current token with reactive updates.
|
|
84
|
-
*
|
|
85
|
-
* @returns The current token or undefined if not authenticated
|
|
86
|
-
* @throws {Error} If called in a server environment
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* function SomeComponent() {
|
|
91
|
-
* const token = useCurrentToken();
|
|
92
|
-
*
|
|
93
|
-
* if (!token) {
|
|
94
|
-
* return <div>Please log in</div>;
|
|
95
|
-
* }
|
|
96
|
-
*
|
|
97
|
-
* // Use token...
|
|
98
|
-
* }
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
export declare const useCurrentToken: () => string | undefined;
|
|
102
|
-
/**
|
|
103
|
-
* Checks if a user is currently authenticated.
|
|
104
|
-
*
|
|
105
|
-
* @returns True if user is authenticated, false otherwise
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* ```typescript
|
|
109
|
-
* if (isAuthenticated()) {
|
|
110
|
-
* // User is logged in
|
|
111
|
-
* showDashboard();
|
|
112
|
-
* } else {
|
|
113
|
-
* // User needs to log in
|
|
114
|
-
* showLoginForm();
|
|
115
|
-
* }
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
export declare const isAuthenticated: () => boolean;
|
|
119
|
-
/**
|
|
120
|
-
* Gets debug information about the current authentication state.
|
|
121
|
-
* Useful for troubleshooting authentication issues.
|
|
122
|
-
*
|
|
123
|
-
* @returns Object containing authentication state information
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* const debugInfo = getAuthDebugInfo();
|
|
128
|
-
* console.log("Auth Debug Info:", debugInfo);
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
export declare const getAuthDebugInfo: () => {
|
|
132
|
-
hasUser: boolean;
|
|
133
|
-
hasToken: boolean;
|
|
134
|
-
isAuthenticated: boolean;
|
|
135
|
-
userName: string;
|
|
136
|
-
tokenLength: number;
|
|
137
|
-
storeState: string | (AuthState & AuthActions);
|
|
138
|
-
};
|
|
139
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type StoreApi, type UseBoundStore } from "zustand";
|
|
2
|
-
import type { AuthStore } from "./types.js";
|
|
3
|
-
import { User } from "@/modules/auth/user.model.js";
|
|
4
|
-
/** Type definition for the store's state */
|
|
5
|
-
type State = {
|
|
6
|
-
user: string | undefined;
|
|
7
|
-
};
|
|
8
|
-
/** Type definition for the store's actions */
|
|
9
|
-
interface Actions {
|
|
10
|
-
setUser: (user: User) => void;
|
|
11
|
-
getUser: () => User | undefined;
|
|
12
|
-
refresh: () => void;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Creates and exports the Zustand store directly for reactive hooks
|
|
16
|
-
* @internal This should only be used by AfloatAuth
|
|
17
|
-
*/
|
|
18
|
-
export declare const clientStore: UseBoundStore<StoreApi<State & Actions>>;
|
|
19
|
-
/**
|
|
20
|
-
* Creates a client-side authentication store using Zustand.
|
|
21
|
-
* @returns {AuthStore} An implementation of AuthStore for client-side use
|
|
22
|
-
*/
|
|
23
|
-
export declare const createClientStore: () => AuthStore;
|
|
24
|
-
/**
|
|
25
|
-
* React hook to access the current user with reactive updates.
|
|
26
|
-
* @returns {User | undefined} The current user or undefined if not authenticated
|
|
27
|
-
*/
|
|
28
|
-
export declare const useClientUser: () => User | undefined;
|
|
29
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { TokenHandler } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Client-side implementation of TokenHandler.
|
|
4
|
-
* Manages tokens using sessionStorage.
|
|
5
|
-
* @implements {TokenHandler}
|
|
6
|
-
*/
|
|
7
|
-
export declare class ClientTokenHandler implements TokenHandler {
|
|
8
|
-
/** Singleton instance */
|
|
9
|
-
private static _instance;
|
|
10
|
-
/** Private constructor to enforce singleton pattern */
|
|
11
|
-
private constructor();
|
|
12
|
-
/**
|
|
13
|
-
* Gets the singleton instance of ClientTokenHandler.
|
|
14
|
-
* @returns {ClientTokenHandler} The singleton instance
|
|
15
|
-
*/
|
|
16
|
-
static get instance(): ClientTokenHandler;
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves the token from sessionStorage.
|
|
19
|
-
* @returns {string | undefined} The stored token or undefined if not present
|
|
20
|
-
*/
|
|
21
|
-
getUserToken(): string | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Stores the token in sessionStorage.
|
|
24
|
-
* @param {string} token - The token to store
|
|
25
|
-
*/
|
|
26
|
-
setUserToken(token: string): void;
|
|
27
|
-
/**
|
|
28
|
-
* Removes the token from sessionStorage.
|
|
29
|
-
*/
|
|
30
|
-
clearToken(): void;
|
|
31
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { User } from "../user.model.js";
|
|
2
|
-
/**
|
|
3
|
-
* Interface defining the contract for auth storage implementations.
|
|
4
|
-
* This allows for different storage strategies in different environments.
|
|
5
|
-
*/
|
|
6
|
-
export interface AuthStore {
|
|
7
|
-
/**
|
|
8
|
-
* Retrieves the currently authenticated user.
|
|
9
|
-
* @returns {User | undefined} The current user or undefined if not authenticated
|
|
10
|
-
*/
|
|
11
|
-
getUser(): User | undefined;
|
|
12
|
-
/**
|
|
13
|
-
* Sets the current authenticated user.
|
|
14
|
-
* @param {User} user - The user to set as currently authenticated
|
|
15
|
-
*/
|
|
16
|
-
setUser(user: User): void;
|
|
17
|
-
/**
|
|
18
|
-
* Clears the current authentication state.
|
|
19
|
-
*/
|
|
20
|
-
refresh(): void;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Interface defining the contract for token handling implementations.
|
|
24
|
-
* This allows for different token storage strategies in different environments.
|
|
25
|
-
*/
|
|
26
|
-
export interface TokenHandler {
|
|
27
|
-
/**
|
|
28
|
-
* Retrieves the current authentication token.
|
|
29
|
-
* @returns {string | undefined} The current token or undefined if not present
|
|
30
|
-
*/
|
|
31
|
-
getUserToken(): string | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Sets the authentication token.
|
|
34
|
-
* @param {string} token - The token to store
|
|
35
|
-
*/
|
|
36
|
-
setUserToken(token: string): void;
|
|
37
|
-
/**
|
|
38
|
-
* Clears the stored authentication token.
|
|
39
|
-
*/
|
|
40
|
-
clearToken(): void;
|
|
41
|
-
}
|