@gofreego/tsutils 0.1.16 → 0.1.18

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
  */
@@ -269,6 +277,8 @@ interface SidebarLayoutProps {
269
277
  defaultExpanded?: string[];
270
278
  /** If true, wraps SidebarLayout in BrowserRouter and enables router-based navigation */
271
279
  isRouter?: boolean;
280
+ /** If true (default), wraps the router layout in BrowserRouter. Set to false when a BrowserRouter already exists higher in the tree. */
281
+ isBrowserRouter?: boolean;
272
282
  }
273
283
  /**
274
284
  * SidebarLayout Component
@@ -342,7 +352,7 @@ interface SidebarLayoutProps {
342
352
  * defaultSelected="dashboard"
343
353
  * />
344
354
  */
345
- declare const SidebarLayout: React.FC<SidebarLayoutProps>;
355
+ declare const SidebarLayout: React__default.FC<SidebarLayoutProps>;
346
356
 
347
357
  interface ReadmeViewerProps {
348
358
  content: string;
@@ -350,7 +360,7 @@ interface ReadmeViewerProps {
350
360
  isDark?: boolean;
351
361
  muiTheme?: any;
352
362
  }
353
- declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
363
+ declare const ReadmeViewer: React__default.FC<ReadmeViewerProps>;
354
364
 
355
365
  /**
356
366
  * Notification type representing a toast message
@@ -402,7 +412,7 @@ interface NotificationProviderProps {
402
412
  * error('Something went wrong')
403
413
  * ```
404
414
  */
405
- declare const NotificationProvider: React.FC<NotificationProviderProps>;
415
+ declare const NotificationProvider: React__default.FC<NotificationProviderProps>;
406
416
  /**
407
417
  * Hook to access notification context
408
418
  * Must be used within a NotificationProvider
@@ -575,7 +585,7 @@ interface ThemeProviderProps {
575
585
  /** Enable CSS variables injection */
576
586
  enableCssVariables?: boolean;
577
587
  }
578
- declare const ThemeProvider: React.FC<ThemeProviderProps>;
588
+ declare const ThemeProvider: React__default.FC<ThemeProviderProps>;
579
589
 
580
590
  declare const useTheme: () => ThemeContextValue;
581
591
 
@@ -604,7 +614,7 @@ interface ThemeToggleProps extends Omit<IconButtonProps, 'onClick'> {
604
614
  /**
605
615
  * A round button component for toggling between light, dark, and system themes
606
616
  */
607
- declare const ThemeToggle: React.FC<ThemeToggleProps>;
617
+ declare const ThemeToggle: React__default.FC<ThemeToggleProps>;
608
618
 
609
619
  /**
610
620
  * Light theme configuration
@@ -788,4 +798,4 @@ declare class LocalStorage {
788
798
 
789
799
  declare const getHighlighter: () => Promise<Highlighter>;
790
800
 
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 };
801
+ 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
  */
@@ -269,6 +277,8 @@ interface SidebarLayoutProps {
269
277
  defaultExpanded?: string[];
270
278
  /** If true, wraps SidebarLayout in BrowserRouter and enables router-based navigation */
271
279
  isRouter?: boolean;
280
+ /** If true (default), wraps the router layout in BrowserRouter. Set to false when a BrowserRouter already exists higher in the tree. */
281
+ isBrowserRouter?: boolean;
272
282
  }
273
283
  /**
274
284
  * SidebarLayout Component
@@ -342,7 +352,7 @@ interface SidebarLayoutProps {
342
352
  * defaultSelected="dashboard"
343
353
  * />
344
354
  */
345
- declare const SidebarLayout: React.FC<SidebarLayoutProps>;
355
+ declare const SidebarLayout: React__default.FC<SidebarLayoutProps>;
346
356
 
347
357
  interface ReadmeViewerProps {
348
358
  content: string;
@@ -350,7 +360,7 @@ interface ReadmeViewerProps {
350
360
  isDark?: boolean;
351
361
  muiTheme?: any;
352
362
  }
353
- declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
363
+ declare const ReadmeViewer: React__default.FC<ReadmeViewerProps>;
354
364
 
355
365
  /**
356
366
  * Notification type representing a toast message
@@ -402,7 +412,7 @@ interface NotificationProviderProps {
402
412
  * error('Something went wrong')
403
413
  * ```
404
414
  */
405
- declare const NotificationProvider: React.FC<NotificationProviderProps>;
415
+ declare const NotificationProvider: React__default.FC<NotificationProviderProps>;
406
416
  /**
407
417
  * Hook to access notification context
408
418
  * Must be used within a NotificationProvider
@@ -575,7 +585,7 @@ interface ThemeProviderProps {
575
585
  /** Enable CSS variables injection */
576
586
  enableCssVariables?: boolean;
577
587
  }
578
- declare const ThemeProvider: React.FC<ThemeProviderProps>;
588
+ declare const ThemeProvider: React__default.FC<ThemeProviderProps>;
579
589
 
580
590
  declare const useTheme: () => ThemeContextValue;
581
591
 
@@ -604,7 +614,7 @@ interface ThemeToggleProps extends Omit<IconButtonProps, 'onClick'> {
604
614
  /**
605
615
  * A round button component for toggling between light, dark, and system themes
606
616
  */
607
- declare const ThemeToggle: React.FC<ThemeToggleProps>;
617
+ declare const ThemeToggle: React__default.FC<ThemeToggleProps>;
608
618
 
609
619
  /**
610
620
  * Light theme configuration
@@ -788,4 +798,4 @@ declare class LocalStorage {
788
798
 
789
799
  declare const getHighlighter: () => Promise<Highlighter>;
790
800
 
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 };
801
+ 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);
@@ -904,6 +916,9 @@ var SidebarLayoutRouterInner = ({
904
916
  );
905
917
  };
906
918
  var SidebarLayoutWithRouter = (props) => {
919
+ if (props.isBrowserRouter === false) {
920
+ return /* @__PURE__ */ jsxRuntime.jsx(SidebarLayoutRouterInner, { ...props });
921
+ }
907
922
  return (
908
923
  // @ts-expect-error - future prop exists in v6 for v7 migration, but is removed from v7 types
909
924
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.BrowserRouter, { future: { v7_startTransition: true, v7_relativeSplatPath: true }, children: /* @__PURE__ */ jsxRuntime.jsx(SidebarLayoutRouterInner, { ...props }) })
@@ -1516,6 +1531,7 @@ exports.LocalStorage = LocalStorage;
1516
1531
  exports.LoginCallbackPage = LoginCallbackPage;
1517
1532
  exports.NotFoundPage = NotFoundPage;
1518
1533
  exports.NotificationProvider = NotificationProvider;
1534
+ exports.ProtectedRoute = ProtectedRoute;
1519
1535
  exports.ReadmeViewer = ReadmeViewer_default;
1520
1536
  exports.SessionManager = SessionManager;
1521
1537
  exports.SidebarLayout = SidebarLayout;