@pubflow/react 0.4.6 → 0.4.8

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.
@@ -107,4 +107,4 @@ export interface BridgeTableProps<T extends EntityData> extends UseBridgeCrudOpt
107
107
  /**
108
108
  * Component for displaying data in a table with sorting, filtering, and pagination
109
109
  */
110
- export declare function BridgeTable<T extends EntityData>({ columns, showPagination, showSearch, showFilters, rowKey, onRowClick, className, loadingComponent, emptyComponent, errorComponent, paginationComponent, searchComponent, filterComponent, searchPlaceholder, actions, ...crudOptions }: BridgeTableProps<T>): string | number | true | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element;
110
+ export declare function BridgeTable<T extends EntityData>({ columns, showPagination, showSearch, showFilters, rowKey, onRowClick, className, loadingComponent, emptyComponent, errorComponent, paginationComponent, searchComponent, filterComponent, searchPlaceholder, actions, ...crudOptions }: BridgeTableProps<T>): string | number | bigint | true | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element;
@@ -2,15 +2,17 @@
2
2
  * Pubflow Provider for React
3
3
  *
4
4
  * Provides a context provider for Pubflow in React applications
5
+ * Following the same pattern as Next.js and React Native packages
5
6
  */
6
7
  import React from 'react';
7
- import { PubflowInstanceConfig, ApiClient, AuthService, User } from '@pubflow/core';
8
+ import { PubflowInstanceConfig, ApiClient, AuthService, TwoFactorService, User, type TwoFactorMethod, type TwoFactorVerifyResult, type TwoFactorStartResult } from '@pubflow/core';
8
9
  /**
9
10
  * Pubflow context value
10
11
  */
11
12
  export interface PubflowContextValue {
12
13
  instances: Record<string, PubflowInstance>;
13
14
  defaultInstance: string;
15
+ isReady: boolean;
14
16
  }
15
17
  /**
16
18
  * Pubflow instance
@@ -19,9 +21,12 @@ export interface PubflowInstance {
19
21
  config: PubflowInstanceConfig;
20
22
  apiClient: ApiClient;
21
23
  authService: AuthService;
24
+ twoFactorService: TwoFactorService;
22
25
  user: User | null | undefined;
23
26
  isAuthenticated: boolean;
24
27
  isLoading: boolean;
28
+ twoFactorPending: boolean;
29
+ twoFactorMethods: TwoFactorMethod[];
25
30
  login: (credentials: {
26
31
  email?: string;
27
32
  userName?: string;
@@ -33,28 +38,13 @@ export interface PubflowInstance {
33
38
  expiresAt?: string;
34
39
  user?: User;
35
40
  }>;
41
+ verifyTwoFactor: (methodId: string, code: string) => Promise<TwoFactorVerifyResult>;
42
+ startTwoFactor: (methodId: string, method: string) => Promise<TwoFactorStartResult>;
36
43
  }
37
44
  /**
38
45
  * Create Pubflow context
39
46
  */
40
47
  export declare const PubflowContext: React.Context<PubflowContextValue>;
41
- /**
42
- * Persistent cache configuration
43
- */
44
- export interface PersistentCacheConfig {
45
- /**
46
- * Whether to enable persistent cache
47
- */
48
- enabled: boolean;
49
- /**
50
- * Cache provider function
51
- */
52
- provider?: () => Map<any, any>;
53
- /**
54
- * Cache options
55
- */
56
- options?: any;
57
- }
58
48
  /**
59
49
  * Pubflow provider props
60
50
  */
@@ -63,38 +53,22 @@ export interface PubflowProviderProps {
63
53
  config?: PubflowInstanceConfig;
64
54
  instances?: PubflowInstanceConfig[];
65
55
  defaultInstance?: string;
66
- onSessionExpired?: () => void;
67
- onSessionRefreshed?: () => void;
68
- showSessionAlerts?: boolean;
69
- /**
70
- * Persistent cache configuration
71
- */
72
- persistentCache?: PersistentCacheConfig;
73
- /**
74
- * Login redirect path (for automatic redirects)
75
- */
76
- loginRedirectPath?: string;
77
- /**
78
- * Public paths that don't require authentication
79
- */
80
- publicPaths?: string[];
81
- /**
82
- * Enable debug tools
83
- * When enabled, debug utilities will be available
84
- * Default: false
85
- */
86
56
  enableDebugTools?: boolean;
87
- /**
88
- * Theme configuration
89
- */
57
+ showSessionAlerts?: boolean;
58
+ persistentCache?: {
59
+ enabled: boolean;
60
+ maxAge?: number;
61
+ };
90
62
  theme?: {
91
63
  primaryColor?: string;
92
64
  secondaryColor?: string;
93
65
  appName?: string;
94
- logo?: string | React.ReactNode;
66
+ logo?: string;
95
67
  };
68
+ loginRedirectPath?: string;
69
+ publicPaths?: string[];
96
70
  }
97
71
  /**
98
- * Pubflow provider for React
72
+ * Pubflow Provider Component
99
73
  */
100
- export declare function PubflowProvider({ children, config, instances, defaultInstance, onSessionExpired, onSessionRefreshed, showSessionAlerts, persistentCache, loginRedirectPath, publicPaths, enableDebugTools, theme }: PubflowProviderProps): import("react/jsx-runtime").JSX.Element | null;
74
+ export declare function PubflowProvider({ children, config, instances, defaultInstance, enableDebugTools, showSessionAlerts, persistentCache, theme, loginRedirectPath, publicPaths }: PubflowProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Provides a hook for accessing authentication functionality
5
5
  */
6
- import { User } from '@pubflow/core';
6
+ import { User, type TwoFactorMethod, type TwoFactorVerifyResult, type TwoFactorStartResult } from '@pubflow/core';
7
7
  /**
8
8
  * Authentication hook result
9
9
  */
@@ -11,6 +11,10 @@ export interface UseAuthResult {
11
11
  user: User | null;
12
12
  isAuthenticated: boolean;
13
13
  isLoading: boolean;
14
+ /** Whether the user is in the 2FA pending step (session is partial) */
15
+ twoFactorPending: boolean;
16
+ /** Available 2FA methods for the pending step */
17
+ twoFactorMethods: TwoFactorMethod[];
14
18
  login: (credentials: {
15
19
  email?: string;
16
20
  userName?: string;
@@ -21,7 +25,10 @@ export interface UseAuthResult {
21
25
  isValid: boolean;
22
26
  expiresAt?: string;
23
27
  }>;
24
- refreshUser: () => Promise<User | null>;
28
+ /** Submit a 2FA verification code to complete a pending login */
29
+ verifyTwoFactor: (methodId: string, code: string) => Promise<TwoFactorVerifyResult>;
30
+ /** (Re-)send a 2FA code for the given method */
31
+ startTwoFactor: (methodId: string, method: string) => Promise<TwoFactorStartResult>;
25
32
  }
26
33
  /**
27
34
  * Hook for accessing authentication functionality
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Authentication Guard Hook for React
3
+ *
4
+ * Framework-agnostic hook for handling authentication validation and redirects
5
+ */
6
+ /**
7
+ * Authentication guard options
8
+ */
9
+ export interface UseAuthGuardOptions {
10
+ /**
11
+ * Whether to validate the session on mount
12
+ */
13
+ validateOnMount?: boolean;
14
+ /**
15
+ * User types allowed to access the page
16
+ */
17
+ allowedTypes?: string[];
18
+ /**
19
+ * Pubflow instance ID
20
+ */
21
+ instanceId?: string;
22
+ /**
23
+ * Custom redirect function (framework-specific)
24
+ */
25
+ onRedirect?: (path: string, reason: 'unauthenticated' | 'unauthorized' | 'session-expired') => void;
26
+ /**
27
+ * Custom session expired handler
28
+ */
29
+ onSessionExpired?: () => void;
30
+ /**
31
+ * Login redirect path
32
+ */
33
+ loginRedirectPath?: string;
34
+ /**
35
+ * Access denied redirect path
36
+ */
37
+ accessDeniedPath?: string;
38
+ /**
39
+ * Whether to show console warnings
40
+ */
41
+ enableLogging?: boolean;
42
+ }
43
+ /**
44
+ * Authentication guard result
45
+ */
46
+ export interface UseAuthGuardResult {
47
+ user: any;
48
+ isAuthenticated: boolean;
49
+ isLoading: boolean;
50
+ isAuthorized: boolean;
51
+ validateSession: () => Promise<{
52
+ isValid: boolean;
53
+ expiresAt?: string;
54
+ user?: any;
55
+ }>;
56
+ redirectReason: 'unauthenticated' | 'unauthorized' | 'session-expired' | null;
57
+ }
58
+ /**
59
+ * Hook for handling authentication validation and redirects
60
+ *
61
+ * This hook is framework-agnostic and requires the user to provide
62
+ * their own redirect function (e.g., Next.js router, React Router, etc.)
63
+ *
64
+ * @param options Hook options
65
+ * @returns Authentication guard result
66
+ */
67
+ export declare function useAuthGuard({ validateOnMount, allowedTypes, instanceId, onRedirect, onSessionExpired, loginRedirectPath, accessDeniedPath, enableLogging }?: UseAuthGuardOptions): UseAuthGuardResult;
68
+ /**
69
+ * Simple authentication guard hook with automatic redirects
70
+ *
71
+ * This is a simplified version that uses window.location for redirects
72
+ * Suitable for simple React apps without complex routing
73
+ *
74
+ * @param options Hook options
75
+ * @returns Authentication guard result
76
+ */
77
+ export declare function useSimpleAuthGuard(options?: Omit<UseAuthGuardOptions, 'onRedirect'>): UseAuthGuardResult;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * useTwoFactor Hook for React
3
+ *
4
+ * Convenience hook for managing 2FA settings (setup, toggle, remove).
5
+ * For the LOGIN-TIME 2FA flow use useAuth() which surfaces
6
+ * twoFactorPending / verifyTwoFactor / startTwoFactor.
7
+ */
8
+ import type { TwoFactorMethod, TwoFactorSetupResult, TwoFactorToggleResult, TwoFactorVerifyResult } from '@pubflow/core';
9
+ export interface UseTwoFactorResult {
10
+ /** Whether the 2FA system is globally enabled on this server */
11
+ systemEnabled: boolean;
12
+ /** Available methods on the server (e.g. ['email']) */
13
+ availableMethods: string[];
14
+ /** User's configured 2FA methods (status = active only) */
15
+ methods: TwoFactorMethod[];
16
+ isLoading: boolean;
17
+ error: string | null;
18
+ /** Load system info and user methods */
19
+ refresh: () => Promise<void>;
20
+ /**
21
+ * Step 1 of setup: register method + send verification code.
22
+ * Returns { success, method_id, status: 'pending_setup', ... }
23
+ */
24
+ setup: (method: string, identifier: string) => Promise<TwoFactorSetupResult>;
25
+ /**
26
+ * Step 2 of setup: confirm the code received → activates the method.
27
+ */
28
+ confirmSetup: (methodId: string, method: string, code: string) => Promise<TwoFactorVerifyResult>;
29
+ /**
30
+ * Enable or disable 2FA for the user.
31
+ * When disabling with existing methods a verification code is required.
32
+ */
33
+ toggle: (enabled: boolean, verificationCode?: string, verificationMethodId?: string) => Promise<TwoFactorToggleResult>;
34
+ /**
35
+ * Remove a 2FA method. Requires a verification code from another active method.
36
+ */
37
+ removeMethod: (methodId: string, verificationCode: string, verificationMethodId: string) => Promise<{
38
+ success: boolean;
39
+ message?: string;
40
+ error?: string;
41
+ }>;
42
+ }
43
+ /**
44
+ * Hook for managing 2FA settings.
45
+ *
46
+ * Must be used inside a PubflowProvider.
47
+ *
48
+ * @param instanceId Optional Pubflow instance ID
49
+ */
50
+ export declare function useTwoFactor(instanceId?: string): UseTwoFactorResult;
@@ -14,13 +14,16 @@ export * from './components/auth';
14
14
  export * from './components/theme';
15
15
  export * from './context/PubflowProvider';
16
16
  export * from './hooks/useAuth';
17
+ export * from './hooks/useAuthGuard';
17
18
  export * from './hooks/useBridgeApi';
18
19
  export * from './hooks/useBridgeApiRaw';
19
20
  export * from './hooks/useBridgeQuery';
20
21
  export * from './hooks/useBridgeMutation';
21
- export * from './hooks/useServerAuth';
22
+ export * from './hooks/useTwoFactor';
22
23
  export * from './hooks/useSearchQueryBuilder';
23
24
  import { useBridgeCrud } from './hooks/useBridgeCrud';
24
25
  export { useBridgeCrud };
25
26
  export * from './storage/BrowserStorageAdapter';
26
27
  export * from './utils/auth-utils';
28
+ export { BridgePaymentClient } from '@pubflow/core';
29
+ export type { BridgePaymentConfig, PaymentRequestOptions, CreatePaymentIntentRequest, PaymentIntent, Payment, PaymentMethodType, PaymentMethod, UpdatePaymentMethodRequest, AddressType, Address, CreateAddressRequest, UpdateAddressRequest, Customer, CreateCustomerRequest, UpdateCustomerRequest, SubscriptionStatus, Subscription, CreateSubscriptionRequest, CancelSubscriptionRequest, OrganizationRole, Organization, CreateOrganizationRequest, UpdateOrganizationRequest, OrganizationMember, AddOrganizationMemberRequest, UpdateOrganizationMemberRoleRequest, ConvertGuestToUserRequest, ConvertGuestToUserResponse, PaginationParams, ListResponse } from '@pubflow/core';
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Simple Pubflow Provider for React
3
+ *
4
+ * Framework-agnostic authentication provider that works with any React setup
5
+ */
6
+ import { ReactNode } from 'react';
7
+ export interface User {
8
+ id: string;
9
+ email: string;
10
+ name?: string;
11
+ [key: string]: any;
12
+ }
13
+ export interface PubflowConfig {
14
+ baseUrl: string;
15
+ authPath?: string;
16
+ }
17
+ export interface AuthContextValue {
18
+ user: User | null;
19
+ isAuthenticated: boolean;
20
+ isLoading: boolean;
21
+ login: (credentials: {
22
+ email: string;
23
+ password: string;
24
+ }) => Promise<{
25
+ success: boolean;
26
+ user?: User;
27
+ error?: string;
28
+ }>;
29
+ logout: () => Promise<void>;
30
+ validateSession: () => Promise<{
31
+ isValid: boolean;
32
+ user?: User;
33
+ }>;
34
+ }
35
+ export interface PubflowProviderProps {
36
+ children: ReactNode;
37
+ config: PubflowConfig;
38
+ }
39
+ export declare function PubflowProvider({ children, config }: PubflowProviderProps): import("react/jsx-runtime").JSX.Element;
40
+ export declare function useAuth(): AuthContextValue;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Asset Utilities for Pubflow React
3
+ *
4
+ * Utilities for handling assets like logos, images, and other media files
5
+ * Supports both external URLs and internal assets with proper Vite/bundler integration
6
+ */
7
+ import React from 'react';
8
+ /**
9
+ * Process asset URL - supports both external URLs and internal assets
10
+ *
11
+ * @param assetUrl - The asset URL to process
12
+ * @returns Processed URL ready for use in src attributes
13
+ */
14
+ export declare function processAssetUrl(assetUrl: string | React.ReactNode): string | React.ReactNode;
15
+ /**
16
+ * Process logo URL specifically - alias for processAssetUrl with better naming
17
+ *
18
+ * @param logoUrl - The logo URL to process
19
+ * @returns Processed URL ready for use in img src
20
+ */
21
+ export declare function processLogoUrl(logoUrl: string | React.ReactNode): string | React.ReactNode;
22
+ /**
23
+ * Check if an asset URL is external (hosted on a different domain)
24
+ *
25
+ * @param assetUrl - The asset URL to check
26
+ * @returns True if the URL is external
27
+ */
28
+ export declare function isExternalAsset(assetUrl: string): boolean;
29
+ /**
30
+ * Check if an asset URL is a data URL (base64 encoded)
31
+ *
32
+ * @param assetUrl - The asset URL to check
33
+ * @returns True if the URL is a data URL
34
+ */
35
+ export declare function isDataUrl(assetUrl: string): boolean;
36
+ /**
37
+ * Get asset file extension from URL
38
+ *
39
+ * @param assetUrl - The asset URL
40
+ * @returns File extension (e.g., 'svg', 'png', 'jpg') or null if not found
41
+ */
42
+ export declare function getAssetExtension(assetUrl: string): string | null;
43
+ /**
44
+ * Check if an asset is an image based on its extension
45
+ *
46
+ * @param assetUrl - The asset URL
47
+ * @returns True if the asset appears to be an image
48
+ */
49
+ export declare function isImageAsset(assetUrl: string): boolean;
50
+ /**
51
+ * Create a fallback image URL for broken images
52
+ *
53
+ * @param width - Image width
54
+ * @param height - Image height
55
+ * @param text - Text to display in fallback
56
+ * @param backgroundColor - Background color
57
+ * @param textColor - Text color
58
+ * @returns Data URL for fallback image
59
+ */
60
+ export declare function createFallbackImageUrl(width?: number, height?: number, text?: string, backgroundColor?: string, textColor?: string): string;
61
+ /**
62
+ * Asset loading utility with error handling
63
+ *
64
+ * @param assetUrl - The asset URL to load
65
+ * @returns Promise that resolves when asset is loaded
66
+ */
67
+ export declare function loadAsset(assetUrl: string): Promise<void>;
68
+ /**
69
+ * Batch load multiple assets
70
+ *
71
+ * @param assetUrls - Array of asset URLs to load
72
+ * @returns Promise that resolves when all assets are loaded
73
+ */
74
+ export declare function loadAssets(assetUrls: string[]): Promise<void[]>;
75
+ /**
76
+ * Asset configuration type for components
77
+ */
78
+ export interface AssetConfig {
79
+ /**
80
+ * Asset URL (logo, image, etc.)
81
+ */
82
+ url?: string | React.ReactNode;
83
+ /**
84
+ * Alt text for accessibility
85
+ */
86
+ alt?: string;
87
+ /**
88
+ * Fallback URL if main asset fails to load
89
+ */
90
+ fallback?: string;
91
+ /**
92
+ * Whether to show a fallback placeholder if asset fails
93
+ */
94
+ showFallback?: boolean;
95
+ /**
96
+ * Custom styles for the asset
97
+ */
98
+ style?: React.CSSProperties;
99
+ /**
100
+ * CSS class name
101
+ */
102
+ className?: string;
103
+ }
104
+ /**
105
+ * Smart asset component that handles loading, errors, and fallbacks
106
+ */
107
+ export interface SmartAssetProps extends AssetConfig {
108
+ /**
109
+ * Asset URL
110
+ */
111
+ src: string | React.ReactNode;
112
+ /**
113
+ * Component type to render
114
+ */
115
+ as?: 'img' | 'div';
116
+ /**
117
+ * Callback when asset loads successfully
118
+ */
119
+ onLoad?: () => void;
120
+ /**
121
+ * Callback when asset fails to load
122
+ */
123
+ onError?: (error: Error) => void;
124
+ }
125
+ /**
126
+ * Smart Asset Component with automatic fallback handling
127
+ */
128
+ export declare function SmartAsset({ src, alt, fallback, showFallback, style, className, as, onLoad, onError }: SmartAssetProps): React.ReactElement | null;
@@ -3,3 +3,4 @@
3
3
  */
4
4
  export * from './auth-utils';
5
5
  export * from './persistent-cache';
6
+ export * from './asset-utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubflow/react",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "React adapter for Pubflow framework with support for TanStack Router and SWR - Now with snake_case support",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.esm.js",