@gofreego/tsutils 0.1.13 → 0.1.15

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.d.ts CHANGED
@@ -1,8 +1,236 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
1
2
  import React, { ReactNode, CSSProperties } from 'react';
2
3
  import { AlertColor, IconButtonProps } from '@mui/material';
3
- import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { Highlighter } from 'shiki';
5
5
 
6
+ declare function NotFoundPage(): react_jsx_runtime.JSX.Element;
7
+
8
+ interface HttpClientConfig {
9
+ baseURL?: string;
10
+ timeout?: number;
11
+ headers?: Record<string, string>;
12
+ }
13
+ interface RequestConfig extends Omit<RequestInit, 'body'> {
14
+ params?: Record<string, string | number | boolean>;
15
+ data?: any;
16
+ timeout?: number;
17
+ }
18
+ interface HttpResponse<T = any> {
19
+ data: T;
20
+ status: number;
21
+ statusText: string;
22
+ headers: Headers;
23
+ }
24
+ interface ErrorData {
25
+ code: number;
26
+ message: string;
27
+ }
28
+ interface HttpError extends Error {
29
+ status?: number;
30
+ statusText?: string;
31
+ data?: ErrorData;
32
+ }
33
+
34
+ declare class HttpClient {
35
+ private baseURL;
36
+ private timeout;
37
+ private defaultHeaders;
38
+ constructor(config?: HttpClientConfig);
39
+ private buildURL;
40
+ private request;
41
+ setDefaultHeader(key: string, value: string): void;
42
+ removeDefaultHeader(key: string): void;
43
+ getDefaultHeaders(): Record<string, string>;
44
+ get<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
45
+ post<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
46
+ put<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
47
+ patch<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
48
+ delete<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
49
+ }
50
+ declare function extractErrorMessage(error: any): string;
51
+
52
+ interface User {
53
+ id: string;
54
+ uuid: string;
55
+ username: string;
56
+ email?: string | undefined;
57
+ phone?: string | undefined;
58
+ /** Display name for the user */
59
+ name?: string | undefined;
60
+ /** URL to user's avatar image */
61
+ avatarUrl?: string | undefined;
62
+ emailVerified: boolean;
63
+ phoneVerified: boolean;
64
+ deactivated: boolean;
65
+ isActive: boolean;
66
+ isLocked: boolean;
67
+ failedLoginAttempts: number;
68
+ lastLoginAt?: string | undefined;
69
+ passwordChangedAt: string;
70
+ createdAt: string;
71
+ updatedAt: string;
72
+ }
73
+ interface SignInMetadata {
74
+ /** Unique device identifier */
75
+ deviceId?: string | undefined;
76
+ /** Human-readable device name */
77
+ deviceName?: string | undefined;
78
+ /** web, mobile, desktop, tablet */
79
+ deviceType?: string | undefined;
80
+ lat?: number | undefined;
81
+ long?: number | undefined;
82
+ }
83
+ /** SignInRequest for user authentication */
84
+ interface SignInRequest {
85
+ username: string;
86
+ password?: string | undefined;
87
+ otp?: string | undefined;
88
+ rememberMe?: boolean | undefined;
89
+ metadata?: SignInMetadata | undefined;
90
+ profiles?: boolean | undefined;
91
+ includePermissions?: boolean | undefined;
92
+ verificationId?: string | undefined;
93
+ }
94
+ /** SignInResponse with authentication tokens and user data */
95
+ interface SignInResponse {
96
+ accessToken: string;
97
+ refreshToken: string;
98
+ /** Access token expiration (Unix timestamp) */
99
+ expiresAt: string;
100
+ /** Refresh token expiration (Unix timestamp) */
101
+ refreshExpiresAt: string;
102
+ user: User | undefined;
103
+ /** Session UUID for tracking */
104
+ sessionId: string;
105
+ message: string;
106
+ }
107
+ /** RefreshTokenRequest to refresh access token */
108
+ interface RefreshTokenRequest {
109
+ refreshToken: string;
110
+ deviceId?: string | undefined;
111
+ profiles?: boolean | undefined;
112
+ includePermissions?: boolean | undefined;
113
+ }
114
+ /** RefreshTokenResponse with new tokens */
115
+ interface RefreshTokenResponse {
116
+ accessToken: string;
117
+ /** New refresh token (rotation) */
118
+ refreshToken: string;
119
+ expiresAt: string;
120
+ refreshExpiresAt: string;
121
+ message: string;
122
+ }
123
+ /** LogoutRequest to end user session */
124
+ interface LogoutRequest {
125
+ /** Specific session to logout */
126
+ sessionId?: string | undefined;
127
+ /** Logout from all devices */
128
+ allSessions?: boolean | undefined;
129
+ }
130
+ /** LogoutResponse */
131
+ interface LogoutResponse {
132
+ success: boolean;
133
+ message: string;
134
+ /** Number of sessions ended */
135
+ sessionsTerminated: number;
136
+ }
137
+ /** GenerateLoginTokenRequest - user is identified from Authorization header */
138
+ interface GenerateLoginTokenRequest {
139
+ /** Token TTL in seconds (default: 60, max: 300) */
140
+ ttlSeconds?: number | undefined;
141
+ }
142
+ /** SignInWithLoginTokenRequest - sign in using a single-use login token */
143
+ interface SignInWithLoginTokenRequest {
144
+ loginToken: string;
145
+ metadata?: SignInMetadata | undefined;
146
+ profiles?: boolean | undefined;
147
+ includePermissions?: boolean | undefined;
148
+ }
149
+ /** GenerateLoginTokenResponse - short-lived single-use token */
150
+ interface GenerateLoginTokenResponse {
151
+ /** Opaque single-use token (prefix: ltk_) */
152
+ loginToken: string;
153
+ /** Unix timestamp (seconds), TTL ~1 min */
154
+ expiresAt: string;
155
+ }
156
+
157
+ interface ISessionManager {
158
+ /** Persist session to localStorage and set the auth header. */
159
+ save(session: SignInResponse): void;
160
+ /** Partially update stored session fields (e.g. after token refresh). */
161
+ patch(updates: Partial<SignInResponse>): void;
162
+ /** Clear session from localStorage and remove the auth header. */
163
+ clear(): void;
164
+ /** Return the full stored session, or null if absent / unparseable. */
165
+ get(): SignInResponse | null;
166
+ /** Return the stored access token, or undefined. */
167
+ getAccessToken(): string | undefined;
168
+ /** Return the stored refresh token, or undefined. */
169
+ getRefreshToken(): string | undefined;
170
+ /** Return the session UUID, or undefined. */
171
+ getSessionId(): string | undefined;
172
+ /** True when a non-expired access token is stored. */
173
+ isAuthenticated(): boolean;
174
+ /** Called on app startup: restore the auth header or wipe an expired session. */
175
+ initialize(): void;
176
+ }
177
+ declare class SessionManager implements ISessionManager {
178
+ private static instance;
179
+ private readonly key;
180
+ private readonly client;
181
+ private cache;
182
+ private constructor();
183
+ static getInstance(client: HttpClient): SessionManager;
184
+ save(session: SignInResponse): void;
185
+ patch(updates: Partial<SignInResponse>): void;
186
+ clear(): void;
187
+ get(): SignInResponse | null;
188
+ getAccessToken(): string | undefined;
189
+ getRefreshToken(): string | undefined;
190
+ getSessionId(): string | undefined;
191
+ isAuthenticated(): boolean;
192
+ initialize(): void;
193
+ private setAuthToken;
194
+ private clearAuthToken;
195
+ }
196
+
197
+ interface IAuthService {
198
+ signIn(request: SignInRequest): Promise<SignInResponse>;
199
+ refreshToken(request?: Partial<RefreshTokenRequest>): Promise<RefreshTokenResponse>;
200
+ logout(request: LogoutRequest): Promise<LogoutResponse>;
201
+ generateLoginToken(request?: GenerateLoginTokenRequest): Promise<GenerateLoginTokenResponse>;
202
+ signInWithLoginToken(request: SignInWithLoginTokenRequest): Promise<SignInResponse>;
203
+ isAuthenticated(): boolean;
204
+ getAccessToken(): string | undefined;
205
+ getSessionDetails(): SignInResponse | null;
206
+ getSessionId(): string | undefined;
207
+ initializeAuth(): void;
208
+ }
209
+ declare class AuthService implements IAuthService {
210
+ private static instance;
211
+ private readonly client;
212
+ private readonly sessionManager;
213
+ private constructor();
214
+ static getInstance(client: HttpClient): AuthService;
215
+ signIn(request: SignInRequest): Promise<SignInResponse>;
216
+ refreshToken(request?: Partial<RefreshTokenRequest>): Promise<RefreshTokenResponse>;
217
+ logout(request: LogoutRequest): Promise<LogoutResponse>;
218
+ generateLoginToken(request?: GenerateLoginTokenRequest): Promise<GenerateLoginTokenResponse>;
219
+ signInWithLoginToken(request: SignInWithLoginTokenRequest): Promise<SignInResponse>;
220
+ isAuthenticated(): boolean;
221
+ getAccessToken(): string | undefined;
222
+ getSessionDetails(): SignInResponse | null;
223
+ getSessionId(): string | undefined;
224
+ initializeAuth(): void;
225
+ }
226
+
227
+ interface LoginCallbackPageProps {
228
+ authService: IAuthService;
229
+ navigateTo?: string;
230
+ onLoginFailed?: () => void;
231
+ }
232
+ declare function LoginCallbackPage({ authService, navigateTo, onLoginFailed }: LoginCallbackPageProps): react_jsx_runtime.JSX.Element;
233
+
6
234
  /**
7
235
  * Menu item configuration
8
236
  */
@@ -495,50 +723,6 @@ declare namespace tokens {
495
723
  export { tokens_borderRadius as borderRadius, tokens_elevation as elevation, tokens_fontSize as fontSize, tokens_fontWeight as fontWeight, tokens_lineHeight as lineHeight, tokens_spacing as spacing, tokens_transition as transition, tokens_zIndex as zIndex };
496
724
  }
497
725
 
498
- interface HttpClientConfig {
499
- baseURL?: string;
500
- timeout?: number;
501
- headers?: Record<string, string>;
502
- }
503
- interface RequestConfig extends Omit<RequestInit, 'body'> {
504
- params?: Record<string, string | number | boolean>;
505
- data?: any;
506
- timeout?: number;
507
- }
508
- interface HttpResponse<T = any> {
509
- data: T;
510
- status: number;
511
- statusText: string;
512
- headers: Headers;
513
- }
514
- interface ErrorData {
515
- code: number;
516
- message: string;
517
- }
518
- interface HttpError extends Error {
519
- status?: number;
520
- statusText?: string;
521
- data?: ErrorData;
522
- }
523
-
524
- declare class HttpClient {
525
- private baseURL;
526
- private timeout;
527
- private defaultHeaders;
528
- constructor(config?: HttpClientConfig);
529
- private buildURL;
530
- private request;
531
- setDefaultHeader(key: string, value: string): void;
532
- removeDefaultHeader(key: string): void;
533
- getDefaultHeaders(): Record<string, string>;
534
- get<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
535
- post<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
536
- put<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
537
- patch<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
538
- delete<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
539
- }
540
- declare function extractErrorMessage(error: any): string;
541
-
542
726
  /**
543
727
  * Merges class names together
544
728
  * Useful for conditional className composition
@@ -604,64 +788,4 @@ declare class LocalStorage {
604
788
 
605
789
  declare const getHighlighter: () => Promise<Highlighter>;
606
790
 
607
- /**
608
- * Context State Interface
609
- */
610
- interface AuthContextType {
611
- isAuthenticated: boolean;
612
- isLoading: boolean;
613
- }
614
- interface AuthProviderProps {
615
- /** Name of the cookie containing the JWT token. Defaults to "authorization" */
616
- cookieName?: string;
617
- /** URL to redirect the user to if authentication fails */
618
- redirectUrl: string;
619
- /** Components to render if deeply authenticated */
620
- children: ReactNode;
621
- /** Custom fallback logic to fire upon failed auth (overrides redirectUrl behavior) */
622
- onAuthFail?: () => void;
623
- /** Custom callback fired strictly on successful auth */
624
- onAuthSuccess?: () => void;
625
- /** Optional loading element while checking cookies asynchronously */
626
- loadingElement?: ReactNode;
627
- }
628
- /**
629
- * AuthProvider verifies a JWT embedded in document.cookie.
630
- * Checks for existence, decodes the signature, and evaluates the `exp` claim.
631
- * Redirects heavily dependent or kicks custom callbacks if failed.
632
- */
633
- declare const AuthProvider: React.FC<AuthProviderProps>;
634
- /**
635
- * React Hook for easily accessing the authenticated JWT context
636
- */
637
- declare const useAuth: () => AuthContextType;
638
-
639
- /**
640
- * A utility class to manage user permissions using the browser's localStorage.
641
- * Employs an internal memory cache to prevent repeated synchronous parsing.
642
- */
643
- declare class PermissionManager {
644
- private static cachedPermissions;
645
- /**
646
- * Saves an array of permission strings to local storage.
647
- * @param permissions Array of permission strings.
648
- */
649
- static setPermissions(permissions: string[]): void;
650
- /**
651
- * Retrieves the currently stored permissions from local storage or memory cache.
652
- * @returns Array of permission strings, or an empty array if none exist.
653
- */
654
- static getPermissions(): string[];
655
- /**
656
- * Clears all stored permissions from memory and local storage.
657
- */
658
- static clearPermissions(): void;
659
- /**
660
- * Checks whether the given permission string exists in the currently stored permissions.
661
- * @param permission The permission string to check for.
662
- * @returns True if the permission exists, false otherwise.
663
- */
664
- static hasPermission(permission: string): boolean;
665
- }
666
-
667
- export { type AuthContextType, AuthProvider, type AuthProviderProps, ConfirmDialog, type ConfirmDialogProps, type ErrorData, HttpClient, type HttpClientConfig, type HttpError, type HttpResponse, LocalStorage, type MenuItem, type Notification, type NotificationContextType, NotificationProvider, type NotificationProviderProps, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, extractErrorMessage, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useNotification, useTheme, zIndex };
791
+ export { AuthService, ConfirmDialog, type ConfirmDialogProps, type ErrorData, type GenerateLoginTokenRequest, type GenerateLoginTokenResponse, HttpClient, type HttpClientConfig, type HttpError, type HttpResponse, type IAuthService, type ISessionManager, LocalStorage, LoginCallbackPage, type LoginCallbackPageProps, type LogoutRequest, type LogoutResponse, type MenuItem, NotFoundPage, type Notification, type NotificationContextType, NotificationProvider, type NotificationProviderProps, ReadmeViewer, type RefreshTokenRequest, type RefreshTokenResponse, type RequestConfig, type ResolvedThemeMode, SessionManager, SidebarLayout, type SidebarLayoutProps, type SignInMetadata, type SignInRequest, type SignInResponse, type SignInWithLoginTokenRequest, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, type User, borderRadius, cn, darkTheme, debounce, elevation, extractErrorMessage, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useNotification, useTheme, zIndex };