@pubflow/react 0.4.6 → 0.4.7
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 +140 -79
- package/dist/types/components/BridgeTable.d.ts +1 -1
- package/dist/types/context/PubflowProvider.d.ts +18 -44
- package/dist/types/hooks/useAuth.d.ts +9 -2
- package/dist/types/hooks/useAuthGuard.d.ts +77 -0
- package/dist/types/hooks/useTwoFactor.d.ts +47 -0
- package/dist/types/index.d.ts +4 -1
- package/dist/types/simple/PubflowProvider.d.ts +40 -0
- package/dist/types/utils/asset-utils.d.ts +128 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as _pubflow_core from '@pubflow/core';
|
|
2
|
-
import { EntityData, BridgeApiService, EntityConfig, FilterOperator, FilterDefinition, PubflowInstanceConfig, ApiClient, AuthService, User, QueryParams, SearchParams, StorageAdapter } from '@pubflow/core';
|
|
2
|
+
import { EntityData, BridgeApiService, EntityConfig, FilterOperator, FilterDefinition, PubflowInstanceConfig, ApiClient, AuthService, TwoFactorService, User, TwoFactorMethod, TwoFactorVerifyResult, TwoFactorStartResult, QueryParams, SearchParams, TwoFactorSetupResult, TwoFactorToggleResult, StorageAdapter } from '@pubflow/core';
|
|
3
3
|
export * from '@pubflow/core';
|
|
4
|
+
export { AddOrganizationMemberRequest, Address, AddressType, BridgePaymentClient, BridgePaymentConfig, CancelSubscriptionRequest, ConvertGuestToUserRequest, ConvertGuestToUserResponse, CreateAddressRequest, CreateCustomerRequest, CreateOrganizationRequest, CreatePaymentIntentRequest, CreateSubscriptionRequest, Customer, ListResponse, Organization, OrganizationMember, OrganizationRole, PaginationParams, Payment, PaymentIntent, PaymentMethod, PaymentMethodType, PaymentRequestOptions, Subscription, SubscriptionStatus, UpdateAddressRequest, UpdateCustomerRequest, UpdateOrganizationMemberRoleRequest, UpdateOrganizationRequest, UpdatePaymentMethodRequest } from '@pubflow/core';
|
|
4
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
6
|
import React, { CSSProperties, ReactNode } from 'react';
|
|
6
7
|
import { z } from 'zod';
|
|
@@ -403,7 +404,7 @@ interface BridgeTableProps<T extends EntityData> extends UseBridgeCrudOptions<T>
|
|
|
403
404
|
/**
|
|
404
405
|
* Component for displaying data in a table with sorting, filtering, and pagination
|
|
405
406
|
*/
|
|
406
|
-
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> | react_jsx_runtime.JSX.Element;
|
|
407
|
+
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> | react_jsx_runtime.JSX.Element;
|
|
407
408
|
|
|
408
409
|
/**
|
|
409
410
|
* Types for BridgeForm component
|
|
@@ -1284,6 +1285,7 @@ declare function createStyles(theme: ThemeConfig): {
|
|
|
1284
1285
|
interface PubflowContextValue {
|
|
1285
1286
|
instances: Record<string, PubflowInstance>;
|
|
1286
1287
|
defaultInstance: string;
|
|
1288
|
+
isReady: boolean;
|
|
1287
1289
|
}
|
|
1288
1290
|
/**
|
|
1289
1291
|
* Pubflow instance
|
|
@@ -1292,9 +1294,12 @@ interface PubflowInstance {
|
|
|
1292
1294
|
config: PubflowInstanceConfig;
|
|
1293
1295
|
apiClient: ApiClient;
|
|
1294
1296
|
authService: AuthService;
|
|
1297
|
+
twoFactorService: TwoFactorService;
|
|
1295
1298
|
user: User | null | undefined;
|
|
1296
1299
|
isAuthenticated: boolean;
|
|
1297
1300
|
isLoading: boolean;
|
|
1301
|
+
twoFactorPending: boolean;
|
|
1302
|
+
twoFactorMethods: TwoFactorMethod[];
|
|
1298
1303
|
login: (credentials: {
|
|
1299
1304
|
email?: string;
|
|
1300
1305
|
userName?: string;
|
|
@@ -1306,28 +1311,13 @@ interface PubflowInstance {
|
|
|
1306
1311
|
expiresAt?: string;
|
|
1307
1312
|
user?: User;
|
|
1308
1313
|
}>;
|
|
1314
|
+
verifyTwoFactor: (methodId: string, code: string) => Promise<TwoFactorVerifyResult>;
|
|
1315
|
+
startTwoFactor: (methodId: string, method: string) => Promise<TwoFactorStartResult>;
|
|
1309
1316
|
}
|
|
1310
1317
|
/**
|
|
1311
1318
|
* Create Pubflow context
|
|
1312
1319
|
*/
|
|
1313
1320
|
declare const PubflowContext: React.Context<PubflowContextValue>;
|
|
1314
|
-
/**
|
|
1315
|
-
* Persistent cache configuration
|
|
1316
|
-
*/
|
|
1317
|
-
interface PersistentCacheConfig {
|
|
1318
|
-
/**
|
|
1319
|
-
* Whether to enable persistent cache
|
|
1320
|
-
*/
|
|
1321
|
-
enabled: boolean;
|
|
1322
|
-
/**
|
|
1323
|
-
* Cache provider function
|
|
1324
|
-
*/
|
|
1325
|
-
provider?: () => Map<any, any>;
|
|
1326
|
-
/**
|
|
1327
|
-
* Cache options
|
|
1328
|
-
*/
|
|
1329
|
-
options?: any;
|
|
1330
|
-
}
|
|
1331
1321
|
/**
|
|
1332
1322
|
* Pubflow provider props
|
|
1333
1323
|
*/
|
|
@@ -1336,41 +1326,25 @@ interface PubflowProviderProps {
|
|
|
1336
1326
|
config?: PubflowInstanceConfig;
|
|
1337
1327
|
instances?: PubflowInstanceConfig[];
|
|
1338
1328
|
defaultInstance?: string;
|
|
1339
|
-
onSessionExpired?: () => void;
|
|
1340
|
-
onSessionRefreshed?: () => void;
|
|
1341
|
-
showSessionAlerts?: boolean;
|
|
1342
|
-
/**
|
|
1343
|
-
* Persistent cache configuration
|
|
1344
|
-
*/
|
|
1345
|
-
persistentCache?: PersistentCacheConfig;
|
|
1346
|
-
/**
|
|
1347
|
-
* Login redirect path (for automatic redirects)
|
|
1348
|
-
*/
|
|
1349
|
-
loginRedirectPath?: string;
|
|
1350
|
-
/**
|
|
1351
|
-
* Public paths that don't require authentication
|
|
1352
|
-
*/
|
|
1353
|
-
publicPaths?: string[];
|
|
1354
|
-
/**
|
|
1355
|
-
* Enable debug tools
|
|
1356
|
-
* When enabled, debug utilities will be available
|
|
1357
|
-
* Default: false
|
|
1358
|
-
*/
|
|
1359
1329
|
enableDebugTools?: boolean;
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1330
|
+
showSessionAlerts?: boolean;
|
|
1331
|
+
persistentCache?: {
|
|
1332
|
+
enabled: boolean;
|
|
1333
|
+
maxAge?: number;
|
|
1334
|
+
};
|
|
1363
1335
|
theme?: {
|
|
1364
1336
|
primaryColor?: string;
|
|
1365
1337
|
secondaryColor?: string;
|
|
1366
1338
|
appName?: string;
|
|
1367
|
-
logo?: string
|
|
1339
|
+
logo?: string;
|
|
1368
1340
|
};
|
|
1341
|
+
loginRedirectPath?: string;
|
|
1342
|
+
publicPaths?: string[];
|
|
1369
1343
|
}
|
|
1370
1344
|
/**
|
|
1371
|
-
* Pubflow
|
|
1345
|
+
* Pubflow Provider Component
|
|
1372
1346
|
*/
|
|
1373
|
-
declare function PubflowProvider({ children, config, instances, defaultInstance,
|
|
1347
|
+
declare function PubflowProvider({ children, config, instances, defaultInstance, enableDebugTools, showSessionAlerts, persistentCache, theme, loginRedirectPath, publicPaths }: PubflowProviderProps): react_jsx_runtime.JSX.Element;
|
|
1374
1348
|
|
|
1375
1349
|
/**
|
|
1376
1350
|
* Authentication Hook for React
|
|
@@ -1385,6 +1359,10 @@ interface UseAuthResult {
|
|
|
1385
1359
|
user: User | null;
|
|
1386
1360
|
isAuthenticated: boolean;
|
|
1387
1361
|
isLoading: boolean;
|
|
1362
|
+
/** Whether the user is in the 2FA pending step (session is partial) */
|
|
1363
|
+
twoFactorPending: boolean;
|
|
1364
|
+
/** Available 2FA methods for the pending step */
|
|
1365
|
+
twoFactorMethods: TwoFactorMethod[];
|
|
1388
1366
|
login: (credentials: {
|
|
1389
1367
|
email?: string;
|
|
1390
1368
|
userName?: string;
|
|
@@ -1395,7 +1373,10 @@ interface UseAuthResult {
|
|
|
1395
1373
|
isValid: boolean;
|
|
1396
1374
|
expiresAt?: string;
|
|
1397
1375
|
}>;
|
|
1398
|
-
|
|
1376
|
+
/** Submit a 2FA verification code to complete a pending login */
|
|
1377
|
+
verifyTwoFactor: (methodId: string, code: string) => Promise<TwoFactorVerifyResult>;
|
|
1378
|
+
/** (Re-)send a 2FA code for the given method */
|
|
1379
|
+
startTwoFactor: (methodId: string, method: string) => Promise<TwoFactorStartResult>;
|
|
1399
1380
|
}
|
|
1400
1381
|
/**
|
|
1401
1382
|
* Hook for accessing authentication functionality
|
|
@@ -1405,6 +1386,84 @@ interface UseAuthResult {
|
|
|
1405
1386
|
*/
|
|
1406
1387
|
declare function useAuth(instanceId?: string): UseAuthResult;
|
|
1407
1388
|
|
|
1389
|
+
/**
|
|
1390
|
+
* Authentication Guard Hook for React
|
|
1391
|
+
*
|
|
1392
|
+
* Framework-agnostic hook for handling authentication validation and redirects
|
|
1393
|
+
*/
|
|
1394
|
+
/**
|
|
1395
|
+
* Authentication guard options
|
|
1396
|
+
*/
|
|
1397
|
+
interface UseAuthGuardOptions {
|
|
1398
|
+
/**
|
|
1399
|
+
* Whether to validate the session on mount
|
|
1400
|
+
*/
|
|
1401
|
+
validateOnMount?: boolean;
|
|
1402
|
+
/**
|
|
1403
|
+
* User types allowed to access the page
|
|
1404
|
+
*/
|
|
1405
|
+
allowedTypes?: string[];
|
|
1406
|
+
/**
|
|
1407
|
+
* Pubflow instance ID
|
|
1408
|
+
*/
|
|
1409
|
+
instanceId?: string;
|
|
1410
|
+
/**
|
|
1411
|
+
* Custom redirect function (framework-specific)
|
|
1412
|
+
*/
|
|
1413
|
+
onRedirect?: (path: string, reason: 'unauthenticated' | 'unauthorized' | 'session-expired') => void;
|
|
1414
|
+
/**
|
|
1415
|
+
* Custom session expired handler
|
|
1416
|
+
*/
|
|
1417
|
+
onSessionExpired?: () => void;
|
|
1418
|
+
/**
|
|
1419
|
+
* Login redirect path
|
|
1420
|
+
*/
|
|
1421
|
+
loginRedirectPath?: string;
|
|
1422
|
+
/**
|
|
1423
|
+
* Access denied redirect path
|
|
1424
|
+
*/
|
|
1425
|
+
accessDeniedPath?: string;
|
|
1426
|
+
/**
|
|
1427
|
+
* Whether to show console warnings
|
|
1428
|
+
*/
|
|
1429
|
+
enableLogging?: boolean;
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Authentication guard result
|
|
1433
|
+
*/
|
|
1434
|
+
interface UseAuthGuardResult {
|
|
1435
|
+
user: any;
|
|
1436
|
+
isAuthenticated: boolean;
|
|
1437
|
+
isLoading: boolean;
|
|
1438
|
+
isAuthorized: boolean;
|
|
1439
|
+
validateSession: () => Promise<{
|
|
1440
|
+
isValid: boolean;
|
|
1441
|
+
expiresAt?: string;
|
|
1442
|
+
user?: any;
|
|
1443
|
+
}>;
|
|
1444
|
+
redirectReason: 'unauthenticated' | 'unauthorized' | 'session-expired' | null;
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Hook for handling authentication validation and redirects
|
|
1448
|
+
*
|
|
1449
|
+
* This hook is framework-agnostic and requires the user to provide
|
|
1450
|
+
* their own redirect function (e.g., Next.js router, React Router, etc.)
|
|
1451
|
+
*
|
|
1452
|
+
* @param options Hook options
|
|
1453
|
+
* @returns Authentication guard result
|
|
1454
|
+
*/
|
|
1455
|
+
declare function useAuthGuard({ validateOnMount, allowedTypes, instanceId, onRedirect, onSessionExpired, loginRedirectPath, accessDeniedPath, enableLogging }?: UseAuthGuardOptions): UseAuthGuardResult;
|
|
1456
|
+
/**
|
|
1457
|
+
* Simple authentication guard hook with automatic redirects
|
|
1458
|
+
*
|
|
1459
|
+
* This is a simplified version that uses window.location for redirects
|
|
1460
|
+
* Suitable for simple React apps without complex routing
|
|
1461
|
+
*
|
|
1462
|
+
* @param options Hook options
|
|
1463
|
+
* @returns Authentication guard result
|
|
1464
|
+
*/
|
|
1465
|
+
declare function useSimpleAuthGuard(options?: Omit<UseAuthGuardOptions, 'onRedirect'>): UseAuthGuardResult;
|
|
1466
|
+
|
|
1408
1467
|
/**
|
|
1409
1468
|
* Bridge API Hook for React
|
|
1410
1469
|
*
|
|
@@ -1556,50 +1615,52 @@ interface UseBridgeQueryResult<T extends EntityData, Q extends QueryType> {
|
|
|
1556
1615
|
declare function useBridgeQuery<T extends EntityData, Q extends QueryType>(service: BridgeApiService<T>, type: Q, params: BridgeQueryParams<Q>, config?: SWRConfiguration): UseBridgeQueryResult<T, Q>;
|
|
1557
1616
|
|
|
1558
1617
|
/**
|
|
1559
|
-
*
|
|
1618
|
+
* useTwoFactor Hook for React
|
|
1560
1619
|
*
|
|
1561
|
-
*
|
|
1620
|
+
* Convenience hook for managing 2FA settings (setup, toggle, remove).
|
|
1621
|
+
* For the LOGIN-TIME 2FA flow use useAuth() which surfaces
|
|
1622
|
+
* twoFactorPending / verifyTwoFactor / startTwoFactor.
|
|
1562
1623
|
*/
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
*/
|
|
1566
|
-
|
|
1567
|
-
/**
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1624
|
+
|
|
1625
|
+
interface UseTwoFactorResult {
|
|
1626
|
+
/** Whether the 2FA system is globally enabled on this server */
|
|
1627
|
+
systemEnabled: boolean;
|
|
1628
|
+
/** Available methods on the server (e.g. ['email']) */
|
|
1629
|
+
availableMethods: string[];
|
|
1630
|
+
/** User's configured 2FA methods */
|
|
1631
|
+
methods: TwoFactorMethod[];
|
|
1632
|
+
isLoading: boolean;
|
|
1633
|
+
error: string | null;
|
|
1634
|
+
/** Load system info and user methods */
|
|
1635
|
+
refresh: () => Promise<void>;
|
|
1575
1636
|
/**
|
|
1576
|
-
*
|
|
1637
|
+
* Set up a new 2FA method.
|
|
1638
|
+
* @param method e.g. 'email'
|
|
1639
|
+
* @param identifier email address or phone number
|
|
1577
1640
|
*/
|
|
1578
|
-
|
|
1641
|
+
setup: (method: string, identifier: string) => Promise<TwoFactorSetupResult>;
|
|
1579
1642
|
/**
|
|
1580
|
-
*
|
|
1643
|
+
* Enable or disable 2FA for the user.
|
|
1644
|
+
* When disabling with existing methods a verification code is required.
|
|
1581
1645
|
*/
|
|
1582
|
-
|
|
1646
|
+
toggle: (enabled: boolean, verificationCode?: string, verificationMethodId?: string) => Promise<TwoFactorToggleResult>;
|
|
1583
1647
|
/**
|
|
1584
|
-
*
|
|
1648
|
+
* Remove a 2FA method. Requires a verification code from another active method.
|
|
1585
1649
|
*/
|
|
1586
|
-
|
|
1650
|
+
removeMethod: (methodId: string, verificationCode: string, verificationMethodId: string) => Promise<{
|
|
1651
|
+
success: boolean;
|
|
1652
|
+
message?: string;
|
|
1653
|
+
error?: string;
|
|
1654
|
+
}>;
|
|
1587
1655
|
}
|
|
1588
1656
|
/**
|
|
1589
|
-
* Hook for
|
|
1657
|
+
* Hook for managing 2FA settings.
|
|
1590
1658
|
*
|
|
1591
|
-
*
|
|
1592
|
-
*
|
|
1659
|
+
* Must be used inside a PubflowProvider.
|
|
1660
|
+
*
|
|
1661
|
+
* @param instanceId Optional Pubflow instance ID
|
|
1593
1662
|
*/
|
|
1594
|
-
declare function
|
|
1595
|
-
user: _pubflow_core.User | null;
|
|
1596
|
-
isAuthenticated: boolean;
|
|
1597
|
-
isLoading: boolean;
|
|
1598
|
-
validateSession: () => Promise<{
|
|
1599
|
-
isValid: boolean;
|
|
1600
|
-
expiresAt?: string;
|
|
1601
|
-
}>;
|
|
1602
|
-
};
|
|
1663
|
+
declare function useTwoFactor(instanceId?: string): UseTwoFactorResult;
|
|
1603
1664
|
|
|
1604
1665
|
/**
|
|
1605
1666
|
* Search Query Builder Hook for React
|
|
@@ -1905,4 +1966,4 @@ declare function useRequireAuth(options?: UseRequireAuthOptions): {
|
|
|
1905
1966
|
isLoading: boolean;
|
|
1906
1967
|
};
|
|
1907
1968
|
|
|
1908
|
-
export { AccountCreationForm, AccountCreationFormConfig, AccountCreationFormProps, AdvancedFilter, AdvancedFilterColors, AdvancedFilterProps, AdvancedFilterTexts, BridgeForm, BridgeFormProps, BridgeList, BridgeListColors, BridgeListLayout, BridgeListProps, BridgeListRenderItemProps, BridgeListTexts, BridgeTable, BridgeTableProps, BridgeView, BridgeViewProps, BrowserStorageAdapter, BrowserStorageOptions, ColumnDef, FieldConfig, FieldRenderProps, FilterField, LoginForm, LoginFormConfig, LoginFormProps, MutationOptions, OfflineIndicator, OfflineIndicatorProps, PasswordResetForm, PasswordResetFormConfig, PasswordResetFormProps,
|
|
1969
|
+
export { AccountCreationForm, AccountCreationFormConfig, AccountCreationFormProps, AdvancedFilter, AdvancedFilterColors, AdvancedFilterProps, AdvancedFilterTexts, BridgeForm, BridgeFormProps, BridgeList, BridgeListColors, BridgeListLayout, BridgeListProps, BridgeListRenderItemProps, BridgeListTexts, BridgeTable, BridgeTableProps, BridgeView, BridgeViewProps, BrowserStorageAdapter, BrowserStorageOptions, ColumnDef, FieldConfig, FieldRenderProps, FilterField, LoginForm, LoginFormConfig, LoginFormProps, MutationOptions, OfflineIndicator, OfflineIndicatorProps, PasswordResetForm, PasswordResetFormConfig, PasswordResetFormProps, PubflowContext, PubflowContextValue, PubflowInstance, PubflowProvider, PubflowProviderProps, RawApiRequestOptions, RawApiResponse, SearchField, SearchQueryState, ThemeConfig, ThemeProvider, ThemeProviderProps, UseAuthGuardOptions, UseAuthGuardResult, UseAuthResult, UseBridgeApiRawResult, UseBridgeMutationResult, UseBridgeQueryResult, UseRequireAuthOptions, UseSearchQueryBuilderResult, UseTwoFactorResult, createStyles, generateCSSVariables, useAuth, useAuthGuard, useBridgeApi, useBridgeApiRaw, useBridgeCrud, useBridgeMutation, useBridgeQuery, useNetworkStatus, useRequireAuth, useSearchQueryBuilder, useSimpleAuthGuard, useTheme, useTwoFactor };
|
|
@@ -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
|
-
|
|
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
|
|
66
|
+
logo?: string;
|
|
95
67
|
};
|
|
68
|
+
loginRedirectPath?: string;
|
|
69
|
+
publicPaths?: string[];
|
|
96
70
|
}
|
|
97
71
|
/**
|
|
98
|
-
* Pubflow
|
|
72
|
+
* Pubflow Provider Component
|
|
99
73
|
*/
|
|
100
|
-
export declare function PubflowProvider({ children, config, instances, defaultInstance,
|
|
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
|
-
|
|
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,47 @@
|
|
|
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 } 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 */
|
|
15
|
+
methods: TwoFactorMethod[];
|
|
16
|
+
isLoading: boolean;
|
|
17
|
+
error: string | null;
|
|
18
|
+
/** Load system info and user methods */
|
|
19
|
+
refresh: () => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Set up a new 2FA method.
|
|
22
|
+
* @param method e.g. 'email'
|
|
23
|
+
* @param identifier email address or phone number
|
|
24
|
+
*/
|
|
25
|
+
setup: (method: string, identifier: string) => Promise<TwoFactorSetupResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Enable or disable 2FA for the user.
|
|
28
|
+
* When disabling with existing methods a verification code is required.
|
|
29
|
+
*/
|
|
30
|
+
toggle: (enabled: boolean, verificationCode?: string, verificationMethodId?: string) => Promise<TwoFactorToggleResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Remove a 2FA method. Requires a verification code from another active method.
|
|
33
|
+
*/
|
|
34
|
+
removeMethod: (methodId: string, verificationCode: string, verificationMethodId: string) => Promise<{
|
|
35
|
+
success: boolean;
|
|
36
|
+
message?: string;
|
|
37
|
+
error?: string;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Hook for managing 2FA settings.
|
|
42
|
+
*
|
|
43
|
+
* Must be used inside a PubflowProvider.
|
|
44
|
+
*
|
|
45
|
+
* @param instanceId Optional Pubflow instance ID
|
|
46
|
+
*/
|
|
47
|
+
export declare function useTwoFactor(instanceId?: string): UseTwoFactorResult;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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/
|
|
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;
|
package/package.json
CHANGED