@famgia/omnify-react-sso 2.2.0 → 2.2.2

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.
Files changed (33) hide show
  1. package/README.md +404 -113
  2. package/dist/@omnify-base/package.json +16 -0
  3. package/dist/@omnify-base/schemas/Branch.ts +131 -0
  4. package/dist/@omnify-base/schemas/BranchCache.ts +131 -0
  5. package/dist/@omnify-base/schemas/OrganizationCache.ts +117 -0
  6. package/dist/@omnify-base/schemas/Permission.ts +114 -0
  7. package/dist/@omnify-base/schemas/Role.ts +121 -0
  8. package/dist/@omnify-base/schemas/RolePermission.ts +97 -0
  9. package/dist/@omnify-base/schemas/Team.ts +110 -0
  10. package/dist/@omnify-base/schemas/TeamCache.ts +110 -0
  11. package/dist/@omnify-base/schemas/TeamPermission.ts +109 -0
  12. package/dist/@omnify-base/schemas/User.ts +135 -0
  13. package/dist/@omnify-base/schemas/UserCache.ts +135 -0
  14. package/dist/@omnify-base/schemas/common.ts +47 -0
  15. package/dist/@omnify-base/schemas/i18n.ts +118 -0
  16. package/dist/index.cjs +1200 -381
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +245 -7
  19. package/dist/index.d.ts +245 -7
  20. package/dist/index.js +1158 -355
  21. package/dist/index.js.map +1 -1
  22. package/dist/schemas/index.cjs +201 -133
  23. package/dist/schemas/index.cjs.map +1 -1
  24. package/dist/schemas/index.d.cts +61 -28
  25. package/dist/schemas/index.d.ts +61 -28
  26. package/dist/schemas/index.js +173 -112
  27. package/dist/schemas/index.js.map +1 -1
  28. package/dist/testing/index.d.cts +1 -1
  29. package/dist/testing/index.d.ts +1 -1
  30. package/dist/{types-BCBSfJJr.d.cts → types-CJmA2a9r.d.cts} +102 -1
  31. package/dist/{types-BCBSfJJr.d.ts → types-CJmA2a9r.d.ts} +102 -1
  32. package/package.json +10 -3
  33. package/scripts/postinstall.cjs +43 -0
package/dist/index.d.cts CHANGED
@@ -1,17 +1,18 @@
1
1
  export { DateString, DateTimeString, Locale, LocaleMap, ValidationRule } from '@omnify-base/schemas/common';
2
2
  export { defaultLocale, fallbackLocale, getMessage, getMessages, supportedLocales, validationMessages } from '@omnify-base/schemas/i18n';
3
- export { BranchCreate, BranchUpdate, PermissionCreate, PermissionUpdate, RoleCreate, RolePermission, RolePermissionCreate, RolePermissionUpdate, RoleUpdate, Team, TeamCreate, TeamPermission, TeamPermissionCreate, TeamPermissionUpdate, TeamUpdate, User, UserCreate, UserUpdate, branchCreateSchema, branchSchemas, branchUpdateSchema, permissionCreateSchema, permissionSchemas, permissionUpdateSchema, roleCreateSchema, rolePermissionCreateSchema, rolePermissionSchemas, rolePermissionUpdateSchema, roleSchemas, roleUpdateSchema, teamCreateSchema, teamPermissionCreateSchema, teamPermissionSchemas, teamPermissionUpdateSchema, teamSchemas, teamUpdateSchema, userCreateSchema, userSchemas, userUpdateSchema } from './schemas/index.cjs';
3
+ export { BranchCache, BranchCacheCreate, BranchCacheUpdate, OrganizationCache, OrganizationCacheCreate, OrganizationCacheUpdate, PermissionCreate, PermissionUpdate, RoleCreate, RolePermission, RolePermissionCreate, RolePermissionUpdate, RoleUpdate, TeamCache, TeamCacheCreate, TeamCacheUpdate, TeamPermission, TeamPermissionCreate, TeamPermissionUpdate, UserCache, UserCacheCreate, UserCacheUpdate, branchCacheCreateSchema, branchCacheSchemas, branchCacheUpdateSchema, organizationCacheCreateSchema, organizationCacheSchemas, organizationCacheUpdateSchema, permissionCreateSchema, permissionSchemas, permissionUpdateSchema, roleCreateSchema, rolePermissionCreateSchema, rolePermissionSchemas, rolePermissionUpdateSchema, roleSchemas, roleUpdateSchema, teamCacheCreateSchema, teamCacheSchemas, teamCacheUpdateSchema, teamPermissionCreateSchema, teamPermissionSchemas, teamPermissionUpdateSchema, userCacheCreateSchema, userCacheSchemas, userCacheUpdateSchema } from './schemas/index.cjs';
4
4
  import * as react from 'react';
5
- import { b as SsoContextValue, c as SsoProviderProps, S as SsoUser$2, a as SsoOrganization, d as SsoConfig, e as SsoCallbackProps, O as OrganizationSwitcherProps, P as ProtectedRouteProps } from './types-BCBSfJJr.cjs';
6
- export { f as SsoCallbackResponse } from './types-BCBSfJJr.cjs';
5
+ import { b as SsoContextValue, c as SsoProviderProps, B as BranchContextValue, d as BranchProviderProps, S as SsoUser$2, a as SsoOrganization, e as SsoConfig, f as SsoCallbackProps, O as OrganizationSwitcherProps, P as ProtectedRouteProps, g as OrgBranchSelectorModalProps, h as BranchGateProps, i as BranchGateSelection } from './types-CJmA2a9r.cjs';
6
+ export { l as OrgBranchSelection, k as SsoBranch, j as SsoCallbackResponse } from './types-CJmA2a9r.cjs';
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
- export { branchI18n, getBranchFieldLabel, getBranchFieldPlaceholder, getBranchLabel } from '@omnify-base/schemas/Branch';
8
+ export { branchCacheI18n, getBranchCacheFieldLabel, getBranchCacheFieldPlaceholder, getBranchCacheLabel } from '@omnify-base/schemas/BranchCache';
9
+ export { getOrganizationCacheFieldLabel, getOrganizationCacheFieldPlaceholder, getOrganizationCacheLabel, organizationCacheI18n } from '@omnify-base/schemas/OrganizationCache';
9
10
  export { getPermissionFieldLabel, getPermissionFieldPlaceholder, getPermissionLabel, permissionI18n } from '@omnify-base/schemas/Permission';
10
11
  export { getRoleFieldLabel, getRoleFieldPlaceholder, getRoleLabel, roleI18n } from '@omnify-base/schemas/Role';
11
12
  export { getRolePermissionFieldLabel, getRolePermissionFieldPlaceholder, getRolePermissionLabel, rolePermissionI18n } from '@omnify-base/schemas/RolePermission';
12
- export { getTeamFieldLabel, getTeamFieldPlaceholder, getTeamLabel, teamI18n } from '@omnify-base/schemas/Team';
13
+ export { getTeamCacheFieldLabel, getTeamCacheFieldPlaceholder, getTeamCacheLabel, teamCacheI18n } from '@omnify-base/schemas/TeamCache';
13
14
  export { getTeamPermissionFieldLabel, getTeamPermissionFieldPlaceholder, getTeamPermissionLabel, teamPermissionI18n } from '@omnify-base/schemas/TeamPermission';
14
- export { getUserFieldLabel, getUserFieldPlaceholder, getUserLabel, userI18n } from '@omnify-base/schemas/User';
15
+ export { getUserCacheFieldLabel, getUserCacheFieldPlaceholder, getUserCacheLabel, userCacheI18n } from '@omnify-base/schemas/UserCache';
15
16
  import 'zod';
16
17
 
17
18
  /**
@@ -24,6 +25,38 @@ declare const SsoContext: react.Context<SsoContextValue | null>;
24
25
  */
25
26
  declare function SsoProvider({ children, config, onAuthChange }: SsoProviderProps): react_jsx_runtime.JSX.Element;
26
27
 
28
+ /**
29
+ * Branch Context
30
+ *
31
+ * Provides branch state management across the application.
32
+ * Must be used within a BranchProvider.
33
+ */
34
+ declare const BranchContext: react.Context<BranchContextValue | null>;
35
+
36
+ /**
37
+ * BranchProvider component
38
+ *
39
+ * Provides branch state management for the application.
40
+ * Automatically fetches branches when organization changes.
41
+ *
42
+ * @example
43
+ * ```tsx
44
+ * // In your app
45
+ * <SsoProvider config={ssoConfig}>
46
+ * <BranchProvider>
47
+ * <App />
48
+ * </BranchProvider>
49
+ * </SsoProvider>
50
+ *
51
+ * // In a component
52
+ * function MyComponent() {
53
+ * const { branches, currentBranch, switchBranch } = useBranch();
54
+ * // ...
55
+ * }
56
+ * ```
57
+ */
58
+ declare function BranchProvider({ children, storage, storageKey, onBranchChange, }: BranchProviderProps): react_jsx_runtime.JSX.Element;
59
+
27
60
  /**
28
61
  * Hook for authentication actions and state
29
62
  */
@@ -163,6 +196,49 @@ interface UseSsoReturn {
163
196
  */
164
197
  declare function useSso(): UseSsoReturn;
165
198
 
199
+ /**
200
+ * Hook return type for branch management
201
+ */
202
+ type UseBranchReturn = BranchContextValue;
203
+ /**
204
+ * Hook for branch management
205
+ *
206
+ * Provides access to branch state and operations.
207
+ * Must be used within a BranchProvider.
208
+ *
209
+ * @example
210
+ * ```tsx
211
+ * function BranchInfo() {
212
+ * const {
213
+ * branches,
214
+ * currentBranch,
215
+ * hasMultipleBranches,
216
+ * switchBranch
217
+ * } = useBranch();
218
+ *
219
+ * // Auto-selection logic is handled by the provider
220
+ * // - If only 1 branch: auto-selected
221
+ * // - If multiple: use saved preference or primary branch
222
+ *
223
+ * return (
224
+ * <div>
225
+ * <p>Current: {currentBranch?.name}</p>
226
+ * {hasMultipleBranches && (
227
+ * <select onChange={(e) => switchBranch(Number(e.target.value))}>
228
+ * {branches.map((branch) => (
229
+ * <option key={branch.id} value={branch.id}>
230
+ * {branch.name}
231
+ * </option>
232
+ * ))}
233
+ * </select>
234
+ * )}
235
+ * </div>
236
+ * );
237
+ * }
238
+ * ```
239
+ */
240
+ declare function useBranch(): UseBranchReturn;
241
+
166
242
  /**
167
243
  * SSO Callback component
168
244
  *
@@ -241,6 +317,168 @@ declare function OrganizationSwitcher({ className, renderTrigger, renderOption,
241
317
  */
242
318
  declare function ProtectedRoute({ children, fallback, loginFallback, requiredRole, requiredPermission, onAccessDenied, }: ProtectedRouteProps): react_jsx_runtime.JSX.Element;
243
319
 
320
+ /**
321
+ * Organization and Branch Selector Modal
322
+ *
323
+ * A modal component for selecting organization and branch.
324
+ * - If user has only one organization, it's auto-selected
325
+ * - If user has only one branch, it's auto-selected
326
+ * - Shows selection UI only when there are multiple options
327
+ *
328
+ * @example
329
+ * ```tsx
330
+ * function CreateProjectButton() {
331
+ * const [modalOpen, setModalOpen] = useState(false);
332
+ *
333
+ * const handleConfirm = (orgId: number, branchId: number) => {
334
+ * // Create project with selected org and branch
335
+ * createProject({ organization_id: orgId, branch_id: branchId });
336
+ * setModalOpen(false);
337
+ * };
338
+ *
339
+ * return (
340
+ * <>
341
+ * <Button onClick={() => setModalOpen(true)}>
342
+ * Create Project
343
+ * </Button>
344
+ * <OrgBranchSelectorModal
345
+ * open={modalOpen}
346
+ * onClose={() => setModalOpen(false)}
347
+ * onConfirm={handleConfirm}
348
+ * />
349
+ * </>
350
+ * );
351
+ * }
352
+ * ```
353
+ */
354
+ declare function OrgBranchSelectorModal({ open, onClose, onConfirm, title, requireBranch, loadingComponent, }: OrgBranchSelectorModalProps): react_jsx_runtime.JSX.Element;
355
+
356
+ type StoredSelection = {
357
+ orgId: string;
358
+ orgSlug: string;
359
+ orgName: string;
360
+ branchId: string;
361
+ branchName: string;
362
+ branchCode: string;
363
+ };
364
+ /**
365
+ * BranchGate - Ensures user has selected an org/branch before accessing the app.
366
+ *
367
+ * Different from OrgBranchSelectorModal:
368
+ * - OrgBranchSelectorModal: Modal for one-time selection (e.g., creating a project)
369
+ * - BranchGate: Gate that blocks app access until selection is made, persists globally
370
+ *
371
+ * Auto-selection behavior:
372
+ * - If user has only 1 org and 1 branch: auto-selects and allows access
373
+ * - If user has multiple options: shows selection modal first
374
+ * - Stores selection in localStorage for persistence
375
+ *
376
+ * @example
377
+ * ```tsx
378
+ * // In your app layout
379
+ * function DashboardLayout({ children }) {
380
+ * return (
381
+ * <BranchGate
382
+ * onSelectionChange={(selection) => {
383
+ * // Set API headers globally
384
+ * api.defaults.headers['X-Branch-Id'] = selection.branchId;
385
+ * api.defaults.headers['X-Org-Id'] = selection.orgId;
386
+ * }}
387
+ * >
388
+ * {children}
389
+ * </BranchGate>
390
+ * );
391
+ * }
392
+ * ```
393
+ */
394
+ declare function BranchGate({ children, onSelectionChange, storageKey, loadingComponent, title, description, }: BranchGateProps): react_jsx_runtime.JSX.Element;
395
+ declare function useBranchGate(storageKey?: string): {
396
+ selection: StoredSelection | null;
397
+ selectedOrg: {
398
+ id: string;
399
+ slug: string;
400
+ name: string;
401
+ } | null;
402
+ selectedBranch: {
403
+ id: string;
404
+ name: string;
405
+ code: string;
406
+ } | null;
407
+ clearSelection: () => void;
408
+ };
409
+
410
+ /**
411
+ * Branch header utilities for API clients
412
+ *
413
+ * These utilities help set branch context headers on axios instances.
414
+ * Works with BranchGate's onSelectionChange callback.
415
+ *
416
+ * @example
417
+ * ```typescript
418
+ * import { createBranchHeaderSetter } from '@famgia/omnify-react-sso';
419
+ * import api from './api'; // your axios instance
420
+ *
421
+ * // Create setter for your axios instance
422
+ * const setBranchHeaders = createBranchHeaderSetter(api);
423
+ *
424
+ * // Use in BranchGate
425
+ * <BranchGate onSelectionChange={setBranchHeaders}>
426
+ * <App />
427
+ * </BranchGate>
428
+ * ```
429
+ */
430
+
431
+ /**
432
+ * Headers set by branch selection
433
+ */
434
+ declare const BRANCH_HEADERS: {
435
+ readonly BRANCH_ID: "X-Branch-Id";
436
+ readonly ORG_ID: "X-Org-Id";
437
+ readonly BRANCH_NAME: "X-Branch-Name";
438
+ readonly BRANCH_CODE: "X-Branch-Code";
439
+ };
440
+ /**
441
+ * Minimal axios-like interface for header management
442
+ */
443
+ interface AxiosLike {
444
+ defaults: {
445
+ headers: {
446
+ common: Record<string, string | undefined>;
447
+ };
448
+ };
449
+ }
450
+ /**
451
+ * Create a branch header setter function for an axios instance
452
+ *
453
+ * @param axiosInstance - Your axios instance
454
+ * @returns A function to pass to BranchGate's onSelectionChange
455
+ *
456
+ * @example
457
+ * ```typescript
458
+ * const setBranchHeaders = createBranchHeaderSetter(api);
459
+ *
460
+ * <BranchGate onSelectionChange={setBranchHeaders}>
461
+ * <App />
462
+ * </BranchGate>
463
+ * ```
464
+ */
465
+ declare function createBranchHeaderSetter(axiosInstance: AxiosLike): (selection: BranchGateSelection | null) => void;
466
+ /**
467
+ * Set branch headers directly on an axios instance
468
+ *
469
+ * @example
470
+ * ```typescript
471
+ * import api from './api';
472
+ * import { setBranchHeaders } from '@famgia/omnify-react-sso';
473
+ *
474
+ * // In BranchGate onSelectionChange
475
+ * <BranchGate onSelectionChange={(s) => setBranchHeaders(api, s)}>
476
+ * <App />
477
+ * </BranchGate>
478
+ * ```
479
+ */
480
+ declare function setBranchHeaders(axiosInstance: AxiosLike, selection: BranchGateSelection | null): void;
481
+
244
482
  /**
245
483
  * Base service configuration
246
484
  */
@@ -1211,4 +1449,4 @@ declare const ssoQueryKeys: {
1211
1449
  };
1212
1450
  };
1213
1451
 
1214
- export { type ApiToken$1 as ApiToken, type AssignRoleInput, type AssignRoleResponse, type AuthCallbackInput, type AuthCallbackResponse, type AuthService, type SsoUser$1 as AuthUser, type AuthUserResponse, type Branch, type BranchService, type BranchesResponse, type CleanupOrphanedInput$1 as CleanupOrphanedInput, type CreatePermissionInput$1 as CreatePermissionInput, type CreateRoleInput$1 as CreateRoleInput, type Organization$1 as Organization, OrganizationSwitcher, OrganizationSwitcherProps, type OrphanedTeam$1 as OrphanedTeam, type Permission$1 as Permission, type PermissionListParams, type PermissionMatrix$1 as PermissionMatrix, type PermissionService, ProtectedRoute, ProtectedRouteProps, type RemoveRoleResponse, type Role$1 as Role, type RoleAssignment, type RoleScope, type RoleService, type RoleWithPermissions$1 as RoleWithPermissions, type ServiceConfig, type Permission$1 as ServicePermission, type Role$1 as ServiceRole, SsoCallback, SsoCallbackProps, SsoConfig, SsoContext, SsoContextValue, SsoOrganization, SsoProvider, SsoProviderProps, type SsoService, type SsoServiceConfig, type SsoUser$1 as SsoServiceUser, SsoUser$2 as SsoUser, type SyncPermissionsInput$1 as SyncPermissionsInput, type SyncPermissionsResponse, type SyncRolesInput, type SyncRolesResponse, type SyncTeamPermissionsInput, type TeamPermissionDetail$1 as TeamPermissionDetail, type TeamService, type TeamWithPermissions$1 as TeamWithPermissions, type TokenService, type UpdatePermissionInput$1 as UpdatePermissionInput, type UpdateRoleInput$1 as UpdateRoleInput, type UseAuthReturn, type UseOrganizationReturn, type UseSsoReturn, type UserRoleService, createAuthService, createBranchService, createPermissionService, createRoleService, createSsoService, createTeamService, createTokenService, createUserRoleService, getEffectivePermissions, getScopeLabel, ssoQueryKeys, useAuth, useOrganization, useSso };
1452
+ export { type ApiToken$1 as ApiToken, type AssignRoleInput, type AssignRoleResponse, type AuthCallbackInput, type AuthCallbackResponse, type AuthService, type SsoUser$1 as AuthUser, type AuthUserResponse, BRANCH_HEADERS, type Branch, BranchContext, BranchContextValue, BranchGate, BranchGateProps, BranchGateSelection, BranchProvider, BranchProviderProps, type BranchService, type BranchesResponse, type CleanupOrphanedInput$1 as CleanupOrphanedInput, type CreatePermissionInput$1 as CreatePermissionInput, type CreateRoleInput$1 as CreateRoleInput, OrgBranchSelectorModal, OrgBranchSelectorModalProps, type Organization$1 as Organization, OrganizationSwitcher, OrganizationSwitcherProps, type OrphanedTeam$1 as OrphanedTeam, type Permission$1 as Permission, type PermissionListParams, type PermissionMatrix$1 as PermissionMatrix, type PermissionService, ProtectedRoute, ProtectedRouteProps, type RemoveRoleResponse, type Role$1 as Role, type RoleAssignment, type RoleScope, type RoleService, type RoleWithPermissions$1 as RoleWithPermissions, type ServiceConfig, type Permission$1 as ServicePermission, type Role$1 as ServiceRole, SsoCallback, SsoCallbackProps, SsoConfig, SsoContext, SsoContextValue, SsoOrganization, SsoProvider, SsoProviderProps, type SsoService, type SsoServiceConfig, type SsoUser$1 as SsoServiceUser, SsoUser$2 as SsoUser, type SyncPermissionsInput$1 as SyncPermissionsInput, type SyncPermissionsResponse, type SyncRolesInput, type SyncRolesResponse, type SyncTeamPermissionsInput, type TeamPermissionDetail$1 as TeamPermissionDetail, type TeamService, type TeamWithPermissions$1 as TeamWithPermissions, type TokenService, type UpdatePermissionInput$1 as UpdatePermissionInput, type UpdateRoleInput$1 as UpdateRoleInput, type UseAuthReturn, type UseBranchReturn, type UseOrganizationReturn, type UseSsoReturn, type UserRoleService, createAuthService, createBranchHeaderSetter, createBranchService, createPermissionService, createRoleService, createSsoService, createTeamService, createTokenService, createUserRoleService, getEffectivePermissions, getScopeLabel, setBranchHeaders, ssoQueryKeys, useAuth, useBranch, useBranchGate, useOrganization, useSso };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,18 @@
1
1
  export { DateString, DateTimeString, Locale, LocaleMap, ValidationRule } from '@omnify-base/schemas/common';
2
2
  export { defaultLocale, fallbackLocale, getMessage, getMessages, supportedLocales, validationMessages } from '@omnify-base/schemas/i18n';
3
- export { BranchCreate, BranchUpdate, PermissionCreate, PermissionUpdate, RoleCreate, RolePermission, RolePermissionCreate, RolePermissionUpdate, RoleUpdate, Team, TeamCreate, TeamPermission, TeamPermissionCreate, TeamPermissionUpdate, TeamUpdate, User, UserCreate, UserUpdate, branchCreateSchema, branchSchemas, branchUpdateSchema, permissionCreateSchema, permissionSchemas, permissionUpdateSchema, roleCreateSchema, rolePermissionCreateSchema, rolePermissionSchemas, rolePermissionUpdateSchema, roleSchemas, roleUpdateSchema, teamCreateSchema, teamPermissionCreateSchema, teamPermissionSchemas, teamPermissionUpdateSchema, teamSchemas, teamUpdateSchema, userCreateSchema, userSchemas, userUpdateSchema } from './schemas/index.js';
3
+ export { BranchCache, BranchCacheCreate, BranchCacheUpdate, OrganizationCache, OrganizationCacheCreate, OrganizationCacheUpdate, PermissionCreate, PermissionUpdate, RoleCreate, RolePermission, RolePermissionCreate, RolePermissionUpdate, RoleUpdate, TeamCache, TeamCacheCreate, TeamCacheUpdate, TeamPermission, TeamPermissionCreate, TeamPermissionUpdate, UserCache, UserCacheCreate, UserCacheUpdate, branchCacheCreateSchema, branchCacheSchemas, branchCacheUpdateSchema, organizationCacheCreateSchema, organizationCacheSchemas, organizationCacheUpdateSchema, permissionCreateSchema, permissionSchemas, permissionUpdateSchema, roleCreateSchema, rolePermissionCreateSchema, rolePermissionSchemas, rolePermissionUpdateSchema, roleSchemas, roleUpdateSchema, teamCacheCreateSchema, teamCacheSchemas, teamCacheUpdateSchema, teamPermissionCreateSchema, teamPermissionSchemas, teamPermissionUpdateSchema, userCacheCreateSchema, userCacheSchemas, userCacheUpdateSchema } from './schemas/index.js';
4
4
  import * as react from 'react';
5
- import { b as SsoContextValue, c as SsoProviderProps, S as SsoUser$2, a as SsoOrganization, d as SsoConfig, e as SsoCallbackProps, O as OrganizationSwitcherProps, P as ProtectedRouteProps } from './types-BCBSfJJr.js';
6
- export { f as SsoCallbackResponse } from './types-BCBSfJJr.js';
5
+ import { b as SsoContextValue, c as SsoProviderProps, B as BranchContextValue, d as BranchProviderProps, S as SsoUser$2, a as SsoOrganization, e as SsoConfig, f as SsoCallbackProps, O as OrganizationSwitcherProps, P as ProtectedRouteProps, g as OrgBranchSelectorModalProps, h as BranchGateProps, i as BranchGateSelection } from './types-CJmA2a9r.js';
6
+ export { l as OrgBranchSelection, k as SsoBranch, j as SsoCallbackResponse } from './types-CJmA2a9r.js';
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
- export { branchI18n, getBranchFieldLabel, getBranchFieldPlaceholder, getBranchLabel } from '@omnify-base/schemas/Branch';
8
+ export { branchCacheI18n, getBranchCacheFieldLabel, getBranchCacheFieldPlaceholder, getBranchCacheLabel } from '@omnify-base/schemas/BranchCache';
9
+ export { getOrganizationCacheFieldLabel, getOrganizationCacheFieldPlaceholder, getOrganizationCacheLabel, organizationCacheI18n } from '@omnify-base/schemas/OrganizationCache';
9
10
  export { getPermissionFieldLabel, getPermissionFieldPlaceholder, getPermissionLabel, permissionI18n } from '@omnify-base/schemas/Permission';
10
11
  export { getRoleFieldLabel, getRoleFieldPlaceholder, getRoleLabel, roleI18n } from '@omnify-base/schemas/Role';
11
12
  export { getRolePermissionFieldLabel, getRolePermissionFieldPlaceholder, getRolePermissionLabel, rolePermissionI18n } from '@omnify-base/schemas/RolePermission';
12
- export { getTeamFieldLabel, getTeamFieldPlaceholder, getTeamLabel, teamI18n } from '@omnify-base/schemas/Team';
13
+ export { getTeamCacheFieldLabel, getTeamCacheFieldPlaceholder, getTeamCacheLabel, teamCacheI18n } from '@omnify-base/schemas/TeamCache';
13
14
  export { getTeamPermissionFieldLabel, getTeamPermissionFieldPlaceholder, getTeamPermissionLabel, teamPermissionI18n } from '@omnify-base/schemas/TeamPermission';
14
- export { getUserFieldLabel, getUserFieldPlaceholder, getUserLabel, userI18n } from '@omnify-base/schemas/User';
15
+ export { getUserCacheFieldLabel, getUserCacheFieldPlaceholder, getUserCacheLabel, userCacheI18n } from '@omnify-base/schemas/UserCache';
15
16
  import 'zod';
16
17
 
17
18
  /**
@@ -24,6 +25,38 @@ declare const SsoContext: react.Context<SsoContextValue | null>;
24
25
  */
25
26
  declare function SsoProvider({ children, config, onAuthChange }: SsoProviderProps): react_jsx_runtime.JSX.Element;
26
27
 
28
+ /**
29
+ * Branch Context
30
+ *
31
+ * Provides branch state management across the application.
32
+ * Must be used within a BranchProvider.
33
+ */
34
+ declare const BranchContext: react.Context<BranchContextValue | null>;
35
+
36
+ /**
37
+ * BranchProvider component
38
+ *
39
+ * Provides branch state management for the application.
40
+ * Automatically fetches branches when organization changes.
41
+ *
42
+ * @example
43
+ * ```tsx
44
+ * // In your app
45
+ * <SsoProvider config={ssoConfig}>
46
+ * <BranchProvider>
47
+ * <App />
48
+ * </BranchProvider>
49
+ * </SsoProvider>
50
+ *
51
+ * // In a component
52
+ * function MyComponent() {
53
+ * const { branches, currentBranch, switchBranch } = useBranch();
54
+ * // ...
55
+ * }
56
+ * ```
57
+ */
58
+ declare function BranchProvider({ children, storage, storageKey, onBranchChange, }: BranchProviderProps): react_jsx_runtime.JSX.Element;
59
+
27
60
  /**
28
61
  * Hook for authentication actions and state
29
62
  */
@@ -163,6 +196,49 @@ interface UseSsoReturn {
163
196
  */
164
197
  declare function useSso(): UseSsoReturn;
165
198
 
199
+ /**
200
+ * Hook return type for branch management
201
+ */
202
+ type UseBranchReturn = BranchContextValue;
203
+ /**
204
+ * Hook for branch management
205
+ *
206
+ * Provides access to branch state and operations.
207
+ * Must be used within a BranchProvider.
208
+ *
209
+ * @example
210
+ * ```tsx
211
+ * function BranchInfo() {
212
+ * const {
213
+ * branches,
214
+ * currentBranch,
215
+ * hasMultipleBranches,
216
+ * switchBranch
217
+ * } = useBranch();
218
+ *
219
+ * // Auto-selection logic is handled by the provider
220
+ * // - If only 1 branch: auto-selected
221
+ * // - If multiple: use saved preference or primary branch
222
+ *
223
+ * return (
224
+ * <div>
225
+ * <p>Current: {currentBranch?.name}</p>
226
+ * {hasMultipleBranches && (
227
+ * <select onChange={(e) => switchBranch(Number(e.target.value))}>
228
+ * {branches.map((branch) => (
229
+ * <option key={branch.id} value={branch.id}>
230
+ * {branch.name}
231
+ * </option>
232
+ * ))}
233
+ * </select>
234
+ * )}
235
+ * </div>
236
+ * );
237
+ * }
238
+ * ```
239
+ */
240
+ declare function useBranch(): UseBranchReturn;
241
+
166
242
  /**
167
243
  * SSO Callback component
168
244
  *
@@ -241,6 +317,168 @@ declare function OrganizationSwitcher({ className, renderTrigger, renderOption,
241
317
  */
242
318
  declare function ProtectedRoute({ children, fallback, loginFallback, requiredRole, requiredPermission, onAccessDenied, }: ProtectedRouteProps): react_jsx_runtime.JSX.Element;
243
319
 
320
+ /**
321
+ * Organization and Branch Selector Modal
322
+ *
323
+ * A modal component for selecting organization and branch.
324
+ * - If user has only one organization, it's auto-selected
325
+ * - If user has only one branch, it's auto-selected
326
+ * - Shows selection UI only when there are multiple options
327
+ *
328
+ * @example
329
+ * ```tsx
330
+ * function CreateProjectButton() {
331
+ * const [modalOpen, setModalOpen] = useState(false);
332
+ *
333
+ * const handleConfirm = (orgId: number, branchId: number) => {
334
+ * // Create project with selected org and branch
335
+ * createProject({ organization_id: orgId, branch_id: branchId });
336
+ * setModalOpen(false);
337
+ * };
338
+ *
339
+ * return (
340
+ * <>
341
+ * <Button onClick={() => setModalOpen(true)}>
342
+ * Create Project
343
+ * </Button>
344
+ * <OrgBranchSelectorModal
345
+ * open={modalOpen}
346
+ * onClose={() => setModalOpen(false)}
347
+ * onConfirm={handleConfirm}
348
+ * />
349
+ * </>
350
+ * );
351
+ * }
352
+ * ```
353
+ */
354
+ declare function OrgBranchSelectorModal({ open, onClose, onConfirm, title, requireBranch, loadingComponent, }: OrgBranchSelectorModalProps): react_jsx_runtime.JSX.Element;
355
+
356
+ type StoredSelection = {
357
+ orgId: string;
358
+ orgSlug: string;
359
+ orgName: string;
360
+ branchId: string;
361
+ branchName: string;
362
+ branchCode: string;
363
+ };
364
+ /**
365
+ * BranchGate - Ensures user has selected an org/branch before accessing the app.
366
+ *
367
+ * Different from OrgBranchSelectorModal:
368
+ * - OrgBranchSelectorModal: Modal for one-time selection (e.g., creating a project)
369
+ * - BranchGate: Gate that blocks app access until selection is made, persists globally
370
+ *
371
+ * Auto-selection behavior:
372
+ * - If user has only 1 org and 1 branch: auto-selects and allows access
373
+ * - If user has multiple options: shows selection modal first
374
+ * - Stores selection in localStorage for persistence
375
+ *
376
+ * @example
377
+ * ```tsx
378
+ * // In your app layout
379
+ * function DashboardLayout({ children }) {
380
+ * return (
381
+ * <BranchGate
382
+ * onSelectionChange={(selection) => {
383
+ * // Set API headers globally
384
+ * api.defaults.headers['X-Branch-Id'] = selection.branchId;
385
+ * api.defaults.headers['X-Org-Id'] = selection.orgId;
386
+ * }}
387
+ * >
388
+ * {children}
389
+ * </BranchGate>
390
+ * );
391
+ * }
392
+ * ```
393
+ */
394
+ declare function BranchGate({ children, onSelectionChange, storageKey, loadingComponent, title, description, }: BranchGateProps): react_jsx_runtime.JSX.Element;
395
+ declare function useBranchGate(storageKey?: string): {
396
+ selection: StoredSelection | null;
397
+ selectedOrg: {
398
+ id: string;
399
+ slug: string;
400
+ name: string;
401
+ } | null;
402
+ selectedBranch: {
403
+ id: string;
404
+ name: string;
405
+ code: string;
406
+ } | null;
407
+ clearSelection: () => void;
408
+ };
409
+
410
+ /**
411
+ * Branch header utilities for API clients
412
+ *
413
+ * These utilities help set branch context headers on axios instances.
414
+ * Works with BranchGate's onSelectionChange callback.
415
+ *
416
+ * @example
417
+ * ```typescript
418
+ * import { createBranchHeaderSetter } from '@famgia/omnify-react-sso';
419
+ * import api from './api'; // your axios instance
420
+ *
421
+ * // Create setter for your axios instance
422
+ * const setBranchHeaders = createBranchHeaderSetter(api);
423
+ *
424
+ * // Use in BranchGate
425
+ * <BranchGate onSelectionChange={setBranchHeaders}>
426
+ * <App />
427
+ * </BranchGate>
428
+ * ```
429
+ */
430
+
431
+ /**
432
+ * Headers set by branch selection
433
+ */
434
+ declare const BRANCH_HEADERS: {
435
+ readonly BRANCH_ID: "X-Branch-Id";
436
+ readonly ORG_ID: "X-Org-Id";
437
+ readonly BRANCH_NAME: "X-Branch-Name";
438
+ readonly BRANCH_CODE: "X-Branch-Code";
439
+ };
440
+ /**
441
+ * Minimal axios-like interface for header management
442
+ */
443
+ interface AxiosLike {
444
+ defaults: {
445
+ headers: {
446
+ common: Record<string, string | undefined>;
447
+ };
448
+ };
449
+ }
450
+ /**
451
+ * Create a branch header setter function for an axios instance
452
+ *
453
+ * @param axiosInstance - Your axios instance
454
+ * @returns A function to pass to BranchGate's onSelectionChange
455
+ *
456
+ * @example
457
+ * ```typescript
458
+ * const setBranchHeaders = createBranchHeaderSetter(api);
459
+ *
460
+ * <BranchGate onSelectionChange={setBranchHeaders}>
461
+ * <App />
462
+ * </BranchGate>
463
+ * ```
464
+ */
465
+ declare function createBranchHeaderSetter(axiosInstance: AxiosLike): (selection: BranchGateSelection | null) => void;
466
+ /**
467
+ * Set branch headers directly on an axios instance
468
+ *
469
+ * @example
470
+ * ```typescript
471
+ * import api from './api';
472
+ * import { setBranchHeaders } from '@famgia/omnify-react-sso';
473
+ *
474
+ * // In BranchGate onSelectionChange
475
+ * <BranchGate onSelectionChange={(s) => setBranchHeaders(api, s)}>
476
+ * <App />
477
+ * </BranchGate>
478
+ * ```
479
+ */
480
+ declare function setBranchHeaders(axiosInstance: AxiosLike, selection: BranchGateSelection | null): void;
481
+
244
482
  /**
245
483
  * Base service configuration
246
484
  */
@@ -1211,4 +1449,4 @@ declare const ssoQueryKeys: {
1211
1449
  };
1212
1450
  };
1213
1451
 
1214
- export { type ApiToken$1 as ApiToken, type AssignRoleInput, type AssignRoleResponse, type AuthCallbackInput, type AuthCallbackResponse, type AuthService, type SsoUser$1 as AuthUser, type AuthUserResponse, type Branch, type BranchService, type BranchesResponse, type CleanupOrphanedInput$1 as CleanupOrphanedInput, type CreatePermissionInput$1 as CreatePermissionInput, type CreateRoleInput$1 as CreateRoleInput, type Organization$1 as Organization, OrganizationSwitcher, OrganizationSwitcherProps, type OrphanedTeam$1 as OrphanedTeam, type Permission$1 as Permission, type PermissionListParams, type PermissionMatrix$1 as PermissionMatrix, type PermissionService, ProtectedRoute, ProtectedRouteProps, type RemoveRoleResponse, type Role$1 as Role, type RoleAssignment, type RoleScope, type RoleService, type RoleWithPermissions$1 as RoleWithPermissions, type ServiceConfig, type Permission$1 as ServicePermission, type Role$1 as ServiceRole, SsoCallback, SsoCallbackProps, SsoConfig, SsoContext, SsoContextValue, SsoOrganization, SsoProvider, SsoProviderProps, type SsoService, type SsoServiceConfig, type SsoUser$1 as SsoServiceUser, SsoUser$2 as SsoUser, type SyncPermissionsInput$1 as SyncPermissionsInput, type SyncPermissionsResponse, type SyncRolesInput, type SyncRolesResponse, type SyncTeamPermissionsInput, type TeamPermissionDetail$1 as TeamPermissionDetail, type TeamService, type TeamWithPermissions$1 as TeamWithPermissions, type TokenService, type UpdatePermissionInput$1 as UpdatePermissionInput, type UpdateRoleInput$1 as UpdateRoleInput, type UseAuthReturn, type UseOrganizationReturn, type UseSsoReturn, type UserRoleService, createAuthService, createBranchService, createPermissionService, createRoleService, createSsoService, createTeamService, createTokenService, createUserRoleService, getEffectivePermissions, getScopeLabel, ssoQueryKeys, useAuth, useOrganization, useSso };
1452
+ export { type ApiToken$1 as ApiToken, type AssignRoleInput, type AssignRoleResponse, type AuthCallbackInput, type AuthCallbackResponse, type AuthService, type SsoUser$1 as AuthUser, type AuthUserResponse, BRANCH_HEADERS, type Branch, BranchContext, BranchContextValue, BranchGate, BranchGateProps, BranchGateSelection, BranchProvider, BranchProviderProps, type BranchService, type BranchesResponse, type CleanupOrphanedInput$1 as CleanupOrphanedInput, type CreatePermissionInput$1 as CreatePermissionInput, type CreateRoleInput$1 as CreateRoleInput, OrgBranchSelectorModal, OrgBranchSelectorModalProps, type Organization$1 as Organization, OrganizationSwitcher, OrganizationSwitcherProps, type OrphanedTeam$1 as OrphanedTeam, type Permission$1 as Permission, type PermissionListParams, type PermissionMatrix$1 as PermissionMatrix, type PermissionService, ProtectedRoute, ProtectedRouteProps, type RemoveRoleResponse, type Role$1 as Role, type RoleAssignment, type RoleScope, type RoleService, type RoleWithPermissions$1 as RoleWithPermissions, type ServiceConfig, type Permission$1 as ServicePermission, type Role$1 as ServiceRole, SsoCallback, SsoCallbackProps, SsoConfig, SsoContext, SsoContextValue, SsoOrganization, SsoProvider, SsoProviderProps, type SsoService, type SsoServiceConfig, type SsoUser$1 as SsoServiceUser, SsoUser$2 as SsoUser, type SyncPermissionsInput$1 as SyncPermissionsInput, type SyncPermissionsResponse, type SyncRolesInput, type SyncRolesResponse, type SyncTeamPermissionsInput, type TeamPermissionDetail$1 as TeamPermissionDetail, type TeamService, type TeamWithPermissions$1 as TeamWithPermissions, type TokenService, type UpdatePermissionInput$1 as UpdatePermissionInput, type UpdateRoleInput$1 as UpdateRoleInput, type UseAuthReturn, type UseBranchReturn, type UseOrganizationReturn, type UseSsoReturn, type UserRoleService, createAuthService, createBranchHeaderSetter, createBranchService, createPermissionService, createRoleService, createSsoService, createTeamService, createTokenService, createUserRoleService, getEffectivePermissions, getScopeLabel, setBranchHeaders, ssoQueryKeys, useAuth, useBranch, useBranchGate, useOrganization, useSso };