@gofreego/tsutils 0.1.15 → 0.1.17

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.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import React, { ReactNode, CSSProperties } from 'react';
2
+ import * as React from 'react';
3
+ import React__default, { ReactElement, ReactNode, CSSProperties } from 'react';
3
4
  import { AlertColor, IconButtonProps } from '@mui/material';
4
5
  import { Highlighter } from 'shiki';
5
6
 
@@ -231,6 +232,13 @@ interface LoginCallbackPageProps {
231
232
  }
232
233
  declare function LoginCallbackPage({ authService, navigateTo, onLoginFailed }: LoginCallbackPageProps): react_jsx_runtime.JSX.Element;
233
234
 
235
+ interface ProtectedRouteProps {
236
+ children: ReactElement;
237
+ sessionManager: ISessionManager;
238
+ loginUrl: string;
239
+ }
240
+ declare function ProtectedRoute({ children, sessionManager, loginUrl }: ProtectedRouteProps): ReactElement<unknown, string | React.JSXElementConstructor<any>> | null;
241
+
234
242
  /**
235
243
  * Menu item configuration
236
244
  */
@@ -342,7 +350,7 @@ interface SidebarLayoutProps {
342
350
  * defaultSelected="dashboard"
343
351
  * />
344
352
  */
345
- declare const SidebarLayout: React.FC<SidebarLayoutProps>;
353
+ declare const SidebarLayout: React__default.FC<SidebarLayoutProps>;
346
354
 
347
355
  interface ReadmeViewerProps {
348
356
  content: string;
@@ -350,7 +358,7 @@ interface ReadmeViewerProps {
350
358
  isDark?: boolean;
351
359
  muiTheme?: any;
352
360
  }
353
- declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
361
+ declare const ReadmeViewer: React__default.FC<ReadmeViewerProps>;
354
362
 
355
363
  /**
356
364
  * Notification type representing a toast message
@@ -402,7 +410,7 @@ interface NotificationProviderProps {
402
410
  * error('Something went wrong')
403
411
  * ```
404
412
  */
405
- declare const NotificationProvider: React.FC<NotificationProviderProps>;
413
+ declare const NotificationProvider: React__default.FC<NotificationProviderProps>;
406
414
  /**
407
415
  * Hook to access notification context
408
416
  * Must be used within a NotificationProvider
@@ -575,7 +583,7 @@ interface ThemeProviderProps {
575
583
  /** Enable CSS variables injection */
576
584
  enableCssVariables?: boolean;
577
585
  }
578
- declare const ThemeProvider: React.FC<ThemeProviderProps>;
586
+ declare const ThemeProvider: React__default.FC<ThemeProviderProps>;
579
587
 
580
588
  declare const useTheme: () => ThemeContextValue;
581
589
 
@@ -604,7 +612,7 @@ interface ThemeToggleProps extends Omit<IconButtonProps, 'onClick'> {
604
612
  /**
605
613
  * A round button component for toggling between light, dark, and system themes
606
614
  */
607
- declare const ThemeToggle: React.FC<ThemeToggleProps>;
615
+ declare const ThemeToggle: React__default.FC<ThemeToggleProps>;
608
616
 
609
617
  /**
610
618
  * Light theme configuration
@@ -788,4 +796,4 @@ declare class LocalStorage {
788
796
 
789
797
  declare const getHighlighter: () => Promise<Highlighter>;
790
798
 
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 };
799
+ 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, ProtectedRoute, type ProtectedRouteProps, 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 };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import React, { ReactNode, CSSProperties } from 'react';
2
+ import * as React from 'react';
3
+ import React__default, { ReactElement, ReactNode, CSSProperties } from 'react';
3
4
  import { AlertColor, IconButtonProps } from '@mui/material';
4
5
  import { Highlighter } from 'shiki';
5
6
 
@@ -231,6 +232,13 @@ interface LoginCallbackPageProps {
231
232
  }
232
233
  declare function LoginCallbackPage({ authService, navigateTo, onLoginFailed }: LoginCallbackPageProps): react_jsx_runtime.JSX.Element;
233
234
 
235
+ interface ProtectedRouteProps {
236
+ children: ReactElement;
237
+ sessionManager: ISessionManager;
238
+ loginUrl: string;
239
+ }
240
+ declare function ProtectedRoute({ children, sessionManager, loginUrl }: ProtectedRouteProps): ReactElement<unknown, string | React.JSXElementConstructor<any>> | null;
241
+
234
242
  /**
235
243
  * Menu item configuration
236
244
  */
@@ -342,7 +350,7 @@ interface SidebarLayoutProps {
342
350
  * defaultSelected="dashboard"
343
351
  * />
344
352
  */
345
- declare const SidebarLayout: React.FC<SidebarLayoutProps>;
353
+ declare const SidebarLayout: React__default.FC<SidebarLayoutProps>;
346
354
 
347
355
  interface ReadmeViewerProps {
348
356
  content: string;
@@ -350,7 +358,7 @@ interface ReadmeViewerProps {
350
358
  isDark?: boolean;
351
359
  muiTheme?: any;
352
360
  }
353
- declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
361
+ declare const ReadmeViewer: React__default.FC<ReadmeViewerProps>;
354
362
 
355
363
  /**
356
364
  * Notification type representing a toast message
@@ -402,7 +410,7 @@ interface NotificationProviderProps {
402
410
  * error('Something went wrong')
403
411
  * ```
404
412
  */
405
- declare const NotificationProvider: React.FC<NotificationProviderProps>;
413
+ declare const NotificationProvider: React__default.FC<NotificationProviderProps>;
406
414
  /**
407
415
  * Hook to access notification context
408
416
  * Must be used within a NotificationProvider
@@ -575,7 +583,7 @@ interface ThemeProviderProps {
575
583
  /** Enable CSS variables injection */
576
584
  enableCssVariables?: boolean;
577
585
  }
578
- declare const ThemeProvider: React.FC<ThemeProviderProps>;
586
+ declare const ThemeProvider: React__default.FC<ThemeProviderProps>;
579
587
 
580
588
  declare const useTheme: () => ThemeContextValue;
581
589
 
@@ -604,7 +612,7 @@ interface ThemeToggleProps extends Omit<IconButtonProps, 'onClick'> {
604
612
  /**
605
613
  * A round button component for toggling between light, dark, and system themes
606
614
  */
607
- declare const ThemeToggle: React.FC<ThemeToggleProps>;
615
+ declare const ThemeToggle: React__default.FC<ThemeToggleProps>;
608
616
 
609
617
  /**
610
618
  * Light theme configuration
@@ -788,4 +796,4 @@ declare class LocalStorage {
788
796
 
789
797
  declare const getHighlighter: () => Promise<Highlighter>;
790
798
 
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 };
799
+ 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, ProtectedRoute, type ProtectedRouteProps, 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 };
package/dist/index.js CHANGED
@@ -725,6 +725,18 @@ function LoginCallbackPage({ authService, navigateTo = "/", onLoginFailed }) {
725
725
  }
726
726
  );
727
727
  }
728
+
729
+ // src/components/ProtectedRoute.tsx
730
+ function ProtectedRoute({ children, sessionManager, loginUrl }) {
731
+ if (!sessionManager.isAuthenticated()) {
732
+ const callbackUrl = `${window.location.origin}/login-callback`;
733
+ const url = new URL(loginUrl);
734
+ url.searchParams.set("redirect", callbackUrl);
735
+ window.location.href = url.toString();
736
+ return null;
737
+ }
738
+ return children;
739
+ }
728
740
  var RouterMenuItem = ({ item, depth = 0, expanded, onToggle }) => {
729
741
  const hasChildren = item.children && item.children.length > 0;
730
742
  const isExpanded = expanded.has(item.id);
@@ -1423,7 +1435,7 @@ var SessionManager = class _SessionManager {
1423
1435
  }
1424
1436
  };
1425
1437
 
1426
- // src/auth/AuthService.ts
1438
+ // src/auth/authService.ts
1427
1439
  var BASE_URL = "/openauth/v1";
1428
1440
  var AuthService = class _AuthService {
1429
1441
  constructor(client) {
@@ -1516,6 +1528,7 @@ exports.LocalStorage = LocalStorage;
1516
1528
  exports.LoginCallbackPage = LoginCallbackPage;
1517
1529
  exports.NotFoundPage = NotFoundPage;
1518
1530
  exports.NotificationProvider = NotificationProvider;
1531
+ exports.ProtectedRoute = ProtectedRoute;
1519
1532
  exports.ReadmeViewer = ReadmeViewer_default;
1520
1533
  exports.SessionManager = SessionManager;
1521
1534
  exports.SidebarLayout = SidebarLayout;