@jmruthers/pace-core 0.5.1 → 0.5.3

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 (206) hide show
  1. package/dist/{DataTable-GX3XERFJ.js → DataTable-ZQDRE46Q.js} +7 -6
  2. package/dist/{PublicLoadingSpinner-DztrzuJr.d.ts → PublicLoadingSpinner-Bq_-BeK-.d.ts} +1 -1
  3. package/dist/RBACProvider-BO4ilsQB.d.ts +63 -0
  4. package/dist/{UnifiedAuthProvider-w66zSCUf.d.ts → UnifiedAuthProvider-DGQsy-vY.d.ts} +2 -59
  5. package/dist/{api-ETQ6YJ3C.js → api-H5A3H4IR.js} +2 -2
  6. package/dist/{chunk-T3XIA4AJ.js → chunk-5H3C2SWM.js} +14 -16
  7. package/dist/chunk-5H3C2SWM.js.map +1 -0
  8. package/dist/chunk-5SIXIV7R.js +1925 -0
  9. package/dist/chunk-5SIXIV7R.js.map +1 -0
  10. package/dist/chunk-GNTALZV3.js +17 -0
  11. package/dist/chunk-GNTALZV3.js.map +1 -0
  12. package/dist/{chunk-C5G2A4PO.js → chunk-GWSBHC4J.js} +6 -6
  13. package/dist/{chunk-XJK2J4N6.js → chunk-HD7PYDUV.js} +4 -6
  14. package/dist/{chunk-XJK2J4N6.js.map → chunk-HD7PYDUV.js.map} +1 -1
  15. package/dist/{chunk-TGDCLPP2.js → chunk-HXX35Q2M.js} +6 -21
  16. package/dist/chunk-HXX35Q2M.js.map +1 -0
  17. package/dist/{chunk-5EL3KHOQ.js → chunk-K6B7BLSE.js} +2 -2
  18. package/dist/{chunk-GSNM5D6H.js → chunk-M4RW7PIP.js} +4 -4
  19. package/dist/{chunk-U6JDHVC2.js → chunk-PVMYVQSM.js} +6 -8
  20. package/dist/{chunk-U6JDHVC2.js.map → chunk-PVMYVQSM.js.map} +1 -1
  21. package/dist/{chunk-6CR3MRZN.js → chunk-QKHFMQ5R.js} +372 -11
  22. package/dist/{chunk-6CR3MRZN.js.map → chunk-QKHFMQ5R.js.map} +1 -1
  23. package/dist/chunk-QVYBYGT2.js +428 -0
  24. package/dist/chunk-QVYBYGT2.js.map +1 -0
  25. package/dist/{chunk-OEGRKULD.js → chunk-WJARTBCT.js} +56 -1
  26. package/dist/chunk-WJARTBCT.js.map +1 -0
  27. package/dist/components.d.ts +4 -3
  28. package/dist/components.js +16 -162
  29. package/dist/components.js.map +1 -1
  30. package/dist/hooks.d.ts +2 -2
  31. package/dist/hooks.js +7 -9
  32. package/dist/hooks.js.map +1 -1
  33. package/dist/index.d.ts +8 -6
  34. package/dist/index.js +152 -17
  35. package/dist/index.js.map +1 -1
  36. package/dist/providers.d.ts +3 -2
  37. package/dist/providers.js +6 -12
  38. package/dist/rbac/index.d.ts +167 -98
  39. package/dist/rbac/index.js +48 -1881
  40. package/dist/rbac/index.js.map +1 -1
  41. package/dist/styles/core.css +0 -58
  42. package/dist/types.d.ts +2 -2
  43. package/dist/{unified-CM7T0aTK.d.ts → unified-CMPjE_fv.d.ts} +1 -1
  44. package/dist/{usePublicRouteParams-B6i0KtXW.d.ts → usePublicRouteParams-B2OcAsur.d.ts} +1 -1
  45. package/dist/utils.js +12 -14
  46. package/dist/utils.js.map +1 -1
  47. package/docs/api/classes/ErrorBoundary.md +1 -1
  48. package/docs/api/classes/InvalidScopeError.md +73 -0
  49. package/docs/api/classes/MissingUserContextError.md +66 -0
  50. package/docs/api/classes/OrganisationContextRequiredError.md +66 -0
  51. package/docs/api/classes/PermissionDeniedError.md +73 -0
  52. package/docs/api/classes/PublicErrorBoundary.md +1 -1
  53. package/docs/api/classes/RBACAuditManager.md +270 -0
  54. package/docs/api/classes/RBACCache.md +284 -0
  55. package/docs/api/classes/RBACEngine.md +141 -0
  56. package/docs/api/classes/RBACError.md +76 -0
  57. package/docs/api/classes/RBACNotInitializedError.md +66 -0
  58. package/docs/api/classes/SecureSupabaseClient.md +135 -0
  59. package/docs/api/interfaces/AggregateConfig.md +1 -1
  60. package/docs/api/interfaces/ButtonProps.md +1 -1
  61. package/docs/api/interfaces/CardProps.md +1 -1
  62. package/docs/api/interfaces/ColorPalette.md +1 -1
  63. package/docs/api/interfaces/ColorShade.md +1 -1
  64. package/docs/api/interfaces/DataAccessRecord.md +96 -0
  65. package/docs/api/interfaces/DataTableAction.md +1 -1
  66. package/docs/api/interfaces/DataTableColumn.md +1 -1
  67. package/docs/api/interfaces/DataTableProps.md +1 -1
  68. package/docs/api/interfaces/DataTableToolbarButton.md +1 -1
  69. package/docs/api/interfaces/EmptyStateConfig.md +1 -1
  70. package/docs/api/interfaces/EnhancedNavigationMenuProps.md +235 -0
  71. package/docs/api/interfaces/EventContextType.md +1 -1
  72. package/docs/api/interfaces/EventLogoProps.md +1 -1
  73. package/docs/api/interfaces/EventProviderProps.md +1 -1
  74. package/docs/api/interfaces/FileSizeLimits.md +1 -1
  75. package/docs/api/interfaces/FileUploadProps.md +1 -1
  76. package/docs/api/interfaces/FooterProps.md +1 -1
  77. package/docs/api/interfaces/InactivityWarningModalProps.md +1 -1
  78. package/docs/api/interfaces/InputProps.md +1 -1
  79. package/docs/api/interfaces/LabelProps.md +1 -1
  80. package/docs/api/interfaces/LoginFormProps.md +1 -1
  81. package/docs/api/interfaces/NavigationAccessRecord.md +107 -0
  82. package/docs/api/interfaces/NavigationContextType.md +164 -0
  83. package/docs/api/interfaces/NavigationGuardProps.md +139 -0
  84. package/docs/api/interfaces/NavigationItem.md +1 -1
  85. package/docs/api/interfaces/NavigationMenuProps.md +1 -1
  86. package/docs/api/interfaces/NavigationProviderProps.md +117 -0
  87. package/docs/api/interfaces/Organisation.md +1 -1
  88. package/docs/api/interfaces/OrganisationContextType.md +1 -1
  89. package/docs/api/interfaces/OrganisationMembership.md +2 -2
  90. package/docs/api/interfaces/OrganisationProviderProps.md +1 -1
  91. package/docs/api/interfaces/OrganisationSecurityError.md +1 -1
  92. package/docs/api/interfaces/PaceAppLayoutProps.md +1 -1
  93. package/docs/api/interfaces/PaceLoginPageProps.md +1 -1
  94. package/docs/api/interfaces/PageAccessRecord.md +85 -0
  95. package/docs/api/interfaces/PagePermissionContextType.md +140 -0
  96. package/docs/api/interfaces/PagePermissionGuardProps.md +153 -0
  97. package/docs/api/interfaces/PagePermissionProviderProps.md +119 -0
  98. package/docs/api/interfaces/PaletteData.md +1 -1
  99. package/docs/api/interfaces/PermissionEnforcerProps.md +153 -0
  100. package/docs/api/interfaces/PublicErrorBoundaryProps.md +1 -1
  101. package/docs/api/interfaces/PublicErrorBoundaryState.md +1 -1
  102. package/docs/api/interfaces/PublicLoadingSpinnerProps.md +1 -1
  103. package/docs/api/interfaces/PublicPageFooterProps.md +1 -1
  104. package/docs/api/interfaces/PublicPageHeaderProps.md +1 -1
  105. package/docs/api/interfaces/PublicPageLayoutProps.md +1 -1
  106. package/docs/api/interfaces/RBACConfig.md +99 -0
  107. package/docs/api/interfaces/RBACContextType.md +474 -0
  108. package/docs/api/interfaces/RBACLogger.md +112 -0
  109. package/docs/api/interfaces/RBACProviderProps.md +107 -0
  110. package/docs/api/interfaces/RoleBasedRouterContextType.md +151 -0
  111. package/docs/api/interfaces/RoleBasedRouterProps.md +156 -0
  112. package/docs/api/interfaces/RouteAccessRecord.md +107 -0
  113. package/docs/api/interfaces/RouteConfig.md +121 -0
  114. package/docs/api/interfaces/SecureDataContextType.md +168 -0
  115. package/docs/api/interfaces/SecureDataProviderProps.md +132 -0
  116. package/docs/api/interfaces/StorageConfig.md +1 -1
  117. package/docs/api/interfaces/StorageFileInfo.md +1 -1
  118. package/docs/api/interfaces/StorageFileMetadata.md +1 -1
  119. package/docs/api/interfaces/StorageListOptions.md +1 -1
  120. package/docs/api/interfaces/StorageListResult.md +1 -1
  121. package/docs/api/interfaces/StorageUploadOptions.md +1 -1
  122. package/docs/api/interfaces/StorageUploadResult.md +1 -1
  123. package/docs/api/interfaces/StorageUrlOptions.md +1 -1
  124. package/docs/api/interfaces/StyleImport.md +1 -1
  125. package/docs/api/interfaces/ToastActionElement.md +1 -1
  126. package/docs/api/interfaces/ToastProps.md +1 -1
  127. package/docs/api/interfaces/UnifiedAuthContextType.md +85 -85
  128. package/docs/api/interfaces/UnifiedAuthProviderProps.md +1 -1
  129. package/docs/api/interfaces/UseInactivityTrackerOptions.md +1 -1
  130. package/docs/api/interfaces/UseInactivityTrackerReturn.md +1 -1
  131. package/docs/api/interfaces/UsePublicEventLogoOptions.md +1 -1
  132. package/docs/api/interfaces/UsePublicEventLogoReturn.md +1 -1
  133. package/docs/api/interfaces/UsePublicEventOptions.md +1 -1
  134. package/docs/api/interfaces/UsePublicEventReturn.md +1 -1
  135. package/docs/api/interfaces/UsePublicRouteParamsReturn.md +1 -1
  136. package/docs/api/interfaces/UserEventAccess.md +11 -11
  137. package/docs/api/interfaces/UserMenuProps.md +1 -1
  138. package/docs/api/interfaces/UserProfile.md +1 -1
  139. package/docs/api/modules.md +2244 -3
  140. package/docs/migration-guide.md +43 -18
  141. package/docs/styles/README.md +187 -98
  142. package/docs/usage.md +32 -7
  143. package/package.json +2 -2
  144. package/src/components/Footer/Footer.test.tsx +482 -0
  145. package/src/components/Form/Form.test.tsx +1158 -0
  146. package/src/components/Header/Header.test.tsx +582 -0
  147. package/src/components/Header/Header.tsx +1 -1
  148. package/src/components/InactivityWarningModal/InactivityWarningModal.test.tsx +489 -0
  149. package/src/components/Input/Input.test.tsx +466 -0
  150. package/src/components/LoadingSpinner/LoadingSpinner.test.tsx +450 -0
  151. package/src/components/LoginForm/LoginForm.test.tsx +816 -0
  152. package/src/components/NavigationMenu/NavigationMenu.test.tsx +883 -0
  153. package/src/components/OrganisationSelector/OrganisationSelector.test.tsx +748 -0
  154. package/src/components/PaceAppLayout/PaceAppLayout.test.tsx +891 -0
  155. package/src/components/PaceLoginPage/PaceLoginPage.test.tsx +475 -0
  156. package/src/components/PasswordReset/PasswordChangeForm.test.tsx +621 -0
  157. package/src/components/PasswordReset/PasswordResetForm.test.tsx +605 -0
  158. package/src/components/Select/Select.test.tsx +948 -0
  159. package/src/components/SuperAdminGuard.tsx +1 -1
  160. package/src/components/Toast/Toast.test.tsx +586 -0
  161. package/src/components/Tooltip/Tooltip.test.tsx +852 -0
  162. package/src/components/UserMenu/UserMenu.test.tsx +702 -0
  163. package/src/components/UserMenu/UserMenu.tsx +2 -2
  164. package/src/hooks/useDebounce.test.ts +375 -0
  165. package/src/hooks/useOrganisationPermissions.test.ts +528 -0
  166. package/src/hooks/useOrganisationSecurity.test.ts +734 -0
  167. package/src/hooks/usePermissionCache.test.ts +542 -0
  168. package/src/hooks/usePermissionCache.ts +1 -1
  169. package/src/index.ts +2 -3
  170. package/src/providers/UnifiedAuthProvider.tsx +2 -2
  171. package/src/providers/index.ts +3 -1
  172. package/src/rbac/__tests__/integration.test.tsx +218 -0
  173. package/src/rbac/api.test.ts +441 -0
  174. package/src/rbac/hooks/index.ts +21 -0
  175. package/src/rbac/hooks/useCan.test.ts +461 -0
  176. package/src/rbac/hooks/usePermissions.test.ts +359 -0
  177. package/src/rbac/hooks/usePermissions.ts +567 -0
  178. package/src/rbac/hooks/useRBAC.simple.test.ts +90 -0
  179. package/src/rbac/hooks/useRBAC.test.ts +503 -0
  180. package/src/{hooks → rbac/hooks}/useRBAC.ts +7 -7
  181. package/src/rbac/index.ts +5 -10
  182. package/src/{providers → rbac/providers}/RBACProvider.tsx +6 -6
  183. package/src/rbac/providers/__tests__/RBACProvider.test.tsx +687 -0
  184. package/src/rbac/providers/index.ts +11 -0
  185. package/src/styles/core.css +0 -58
  186. package/src/utils/formatDate.test.ts +241 -0
  187. package/dist/chunk-AUE24LVR.js +0 -268
  188. package/dist/chunk-AUE24LVR.js.map +0 -1
  189. package/dist/chunk-COBPIXXQ.js +0 -379
  190. package/dist/chunk-COBPIXXQ.js.map +0 -1
  191. package/dist/chunk-OEGRKULD.js.map +0 -1
  192. package/dist/chunk-OYRY44Q2.js +0 -62
  193. package/dist/chunk-OYRY44Q2.js.map +0 -1
  194. package/dist/chunk-T3XIA4AJ.js.map +0 -1
  195. package/dist/chunk-TGDCLPP2.js.map +0 -1
  196. package/src/components/RBAC/PagePermissionGuard.tsx +0 -287
  197. package/src/components/RBAC/RBACGuard.tsx +0 -143
  198. package/src/components/RBAC/RBACProvider.tsx +0 -186
  199. package/src/components/RBAC/RoleBasedContent.tsx +0 -129
  200. package/src/components/RBAC/index.ts +0 -23
  201. package/src/rbac/hooks.ts +0 -570
  202. /package/dist/{DataTable-GX3XERFJ.js.map → DataTable-ZQDRE46Q.js.map} +0 -0
  203. /package/dist/{api-ETQ6YJ3C.js.map → api-H5A3H4IR.js.map} +0 -0
  204. /package/dist/{chunk-C5G2A4PO.js.map → chunk-GWSBHC4J.js.map} +0 -0
  205. /package/dist/{chunk-5EL3KHOQ.js.map → chunk-K6B7BLSE.js.map} +0 -0
  206. /package/dist/{chunk-GSNM5D6H.js.map → chunk-M4RW7PIP.js.map} +0 -0
@@ -1,3 +1,37 @@
1
+ import {
2
+ ALL_PERMISSIONS,
3
+ AccessLevelGuard,
4
+ EVENT_APP_PERMISSIONS,
5
+ EnhancedNavigationMenu,
6
+ GLOBAL_PERMISSIONS,
7
+ NavigationGuard,
8
+ NavigationProvider,
9
+ ORGANISATION_PERMISSIONS,
10
+ PAGE_PERMISSIONS,
11
+ PERMISSION_GROUPS,
12
+ PagePermissionGuard,
13
+ PagePermissionProvider,
14
+ PermissionEnforcer,
15
+ PermissionGuard,
16
+ RoleBasedRouter,
17
+ SecureDataProvider,
18
+ SecureSupabaseClient,
19
+ createRBACExpressMiddleware,
20
+ createRBACMiddleware,
21
+ createSecureClient,
22
+ fromSupabaseClient,
23
+ getPermissionsForRole,
24
+ hasAnyPermissionCached,
25
+ hasPermissionCached,
26
+ isValidPermission,
27
+ useNavigationPermissions,
28
+ usePagePermissions,
29
+ useRoleBasedRouter,
30
+ useSecureData,
31
+ withAccessLevelGuard,
32
+ withPermissionGuard,
33
+ withRoleGuard
34
+ } from "../chunk-5SIXIV7R.js";
1
35
  import {
2
36
  useAccessLevel,
3
37
  useCachedPermissions,
@@ -5,11 +39,11 @@ import {
5
39
  useHasAllPermissions,
6
40
  useHasAnyPermission,
7
41
  useMultiplePermissions,
8
- usePermissions
9
- } from "../chunk-AUE24LVR.js";
42
+ usePermissions,
43
+ useRBAC as useRBAC2
44
+ } from "../chunk-QVYBYGT2.js";
10
45
  import {
11
46
  CACHE_PATTERNS,
12
- OrganisationContextRequiredError,
13
47
  RBACCache,
14
48
  RBACEngine,
15
49
  createRBACConfig,
@@ -27,7 +61,7 @@ import {
27
61
  isPermittedCached,
28
62
  rbacCache,
29
63
  setupRBAC
30
- } from "../chunk-C5G2A4PO.js";
64
+ } from "../chunk-GWSBHC4J.js";
31
65
  import {
32
66
  RBACAuditManager,
33
67
  createAuditManager,
@@ -35,1886 +69,16 @@ import {
35
69
  getGlobalAuditManager,
36
70
  setGlobalAuditManager
37
71
  } from "../chunk-7BNPOCLL.js";
72
+ import "../chunk-HXX35Q2M.js";
73
+ import "../chunk-HD7PYDUV.js";
38
74
  import {
39
- useSecureDataAccess
40
- } from "../chunk-XJK2J4N6.js";
41
- import "../chunk-COBPIXXQ.js";
42
- import {
43
- init_UnifiedAuthProvider,
44
- useUnifiedAuth
45
- } from "../chunk-6CR3MRZN.js";
75
+ RBACProvider,
76
+ useRBAC
77
+ } from "../chunk-QKHFMQ5R.js";
46
78
  import "../chunk-YDJW5XTN.js";
47
- import {
48
- getCurrentAppName,
49
- init_appNameResolver
50
- } from "../chunk-MZBUOP4P.js";
51
- import "../chunk-OEGRKULD.js";
52
- import "../chunk-OYRY44Q2.js";
79
+ import "../chunk-MZBUOP4P.js";
80
+ import "../chunk-WJARTBCT.js";
53
81
  import "../chunk-PLDDJCW6.js";
54
-
55
- // src/rbac/secureClient.ts
56
- import { createClient } from "@supabase/supabase-js";
57
- var SecureSupabaseClient = class _SecureSupabaseClient {
58
- constructor(supabaseUrl, supabaseKey, organisationId, eventId, appId) {
59
- this.supabaseUrl = supabaseUrl;
60
- this.supabaseKey = supabaseKey;
61
- this.organisationId = organisationId;
62
- this.eventId = eventId;
63
- this.appId = appId;
64
- this.supabase = createClient(supabaseUrl, supabaseKey, {
65
- global: {
66
- headers: {
67
- "x-organisation-id": organisationId,
68
- "x-event-id": eventId || "",
69
- "x-app-id": appId || ""
70
- }
71
- }
72
- });
73
- this.setupContextInjection();
74
- }
75
- /**
76
- * Setup context injection for all database operations
77
- */
78
- setupContextInjection() {
79
- const originalFrom = this.supabase.from.bind(this.supabase);
80
- this.supabase.from = (table) => {
81
- this.validateContext();
82
- const query = originalFrom(table);
83
- return this.injectContext(query);
84
- };
85
- const originalRpc = this.supabase.rpc.bind(this.supabase);
86
- this.supabase.rpc = (fn, args) => {
87
- this.validateContext();
88
- const contextArgs = {
89
- ...args,
90
- p_organisation_id: this.organisationId,
91
- p_event_id: this.eventId,
92
- p_app_id: this.appId
93
- };
94
- return originalRpc(fn, contextArgs);
95
- };
96
- }
97
- /**
98
- * Inject organisation context into a query
99
- */
100
- injectContext(query) {
101
- const originalSelect = query.select.bind(query);
102
- const originalInsert = query.insert.bind(query);
103
- const originalUpdate = query.update.bind(query);
104
- const originalDelete = query.delete.bind(query);
105
- query.select = (columns) => {
106
- const result = originalSelect(columns);
107
- return this.addOrganisationFilter(result);
108
- };
109
- query.insert = (values) => {
110
- const contextValues = Array.isArray(values) ? values.map((v) => ({ ...v, organisation_id: this.organisationId })) : { ...values, organisation_id: this.organisationId };
111
- return originalInsert(contextValues);
112
- };
113
- query.update = (values) => {
114
- const result = originalUpdate(values);
115
- return this.addOrganisationFilter(result);
116
- };
117
- query.delete = () => {
118
- const result = originalDelete();
119
- return this.addOrganisationFilter(result);
120
- };
121
- return query;
122
- }
123
- /**
124
- * Add organisation filter to a query
125
- */
126
- addOrganisationFilter(query) {
127
- return query.eq("organisation_id", this.organisationId);
128
- }
129
- /**
130
- * Validate that required context is present
131
- */
132
- validateContext() {
133
- if (!this.organisationId) {
134
- throw new OrganisationContextRequiredError();
135
- }
136
- }
137
- /**
138
- * Get the current organisation ID
139
- */
140
- getOrganisationId() {
141
- return this.organisationId;
142
- }
143
- /**
144
- * Get the current event ID
145
- */
146
- getEventId() {
147
- return this.eventId;
148
- }
149
- /**
150
- * Get the current app ID
151
- */
152
- getAppId() {
153
- return this.appId;
154
- }
155
- /**
156
- * Create a new client with updated context
157
- */
158
- withContext(updates) {
159
- return new _SecureSupabaseClient(
160
- this.supabaseUrl,
161
- this.supabaseKey,
162
- updates.organisationId || this.organisationId,
163
- updates.eventId !== void 0 ? updates.eventId : this.eventId,
164
- updates.appId !== void 0 ? updates.appId : this.appId
165
- );
166
- }
167
- /**
168
- * Get the underlying Supabase client (for internal use only)
169
- * @internal
170
- */
171
- getClient() {
172
- return this.supabase;
173
- }
174
- };
175
- function createSecureClient(supabaseUrl, supabaseKey, organisationId, eventId, appId) {
176
- return new SecureSupabaseClient(supabaseUrl, supabaseKey, organisationId, eventId, appId);
177
- }
178
- function fromSupabaseClient(client, organisationId, eventId, appId) {
179
- throw new Error("fromSupabaseClient is not supported. Use createSecureClient instead.");
180
- }
181
-
182
- // src/rbac/components/PagePermissionProvider.tsx
183
- init_UnifiedAuthProvider();
184
- import { createContext, useContext, useState, useCallback, useMemo, useEffect } from "react";
185
- import { jsx } from "react/jsx-runtime";
186
- var PagePermissionContext = createContext(null);
187
- function PagePermissionProvider({
188
- children,
189
- strictMode = true,
190
- auditLog = true,
191
- onPageAccess,
192
- onStrictModeViolation,
193
- maxHistorySize = 1e3
194
- }) {
195
- const { user, selectedOrganisationId, selectedEventId } = useUnifiedAuth();
196
- const [pageAccessHistory, setPageAccessHistory] = useState([]);
197
- const [isEnabled, setIsEnabled] = useState(true);
198
- const currentScope = useMemo(() => {
199
- if (!selectedOrganisationId) return null;
200
- return {
201
- organisationId: selectedOrganisationId,
202
- eventId: selectedEventId || void 0,
203
- appId: void 0
204
- };
205
- }, [selectedOrganisationId, selectedEventId]);
206
- const hasPagePermission = useCallback((pageName, operation, pageId, scope) => {
207
- if (!isEnabled) return true;
208
- if (!user?.id) return false;
209
- const effectiveScope = scope || currentScope;
210
- if (!effectiveScope) return false;
211
- const permission = `${operation}:page.${pageName}`;
212
- return false;
213
- }, [isEnabled, user?.id, currentScope]);
214
- const getPagePermissions = useCallback(() => {
215
- if (!isEnabled || !user?.id) return {};
216
- return {};
217
- }, [isEnabled, user?.id]);
218
- const getPageAccessHistory = useCallback(() => {
219
- return [...pageAccessHistory];
220
- }, [pageAccessHistory]);
221
- const clearPageAccessHistory = useCallback(() => {
222
- setPageAccessHistory([]);
223
- }, []);
224
- const recordPageAccess = useCallback((pageName, operation, allowed, pageId, scope) => {
225
- if (!auditLog || !user?.id) return;
226
- const record = {
227
- pageName,
228
- operation,
229
- userId: user.id,
230
- scope: scope || currentScope || { organisationId: "" },
231
- allowed,
232
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
233
- pageId
234
- };
235
- setPageAccessHistory((prev) => {
236
- const newHistory = [record, ...prev];
237
- return newHistory.slice(0, maxHistorySize);
238
- });
239
- if (onPageAccess) {
240
- onPageAccess(pageName, operation, allowed, record);
241
- }
242
- if (strictMode && !allowed && onStrictModeViolation) {
243
- onStrictModeViolation(pageName, operation, record);
244
- }
245
- }, [auditLog, user?.id, currentScope, maxHistorySize, onPageAccess, onStrictModeViolation, strictMode]);
246
- const contextValue = useMemo(() => ({
247
- hasPagePermission,
248
- getPagePermissions,
249
- isEnabled,
250
- isStrictMode: strictMode,
251
- isAuditLogEnabled: auditLog,
252
- getPageAccessHistory,
253
- clearPageAccessHistory
254
- }), [
255
- hasPagePermission,
256
- getPagePermissions,
257
- isEnabled,
258
- strictMode,
259
- auditLog,
260
- getPageAccessHistory,
261
- clearPageAccessHistory
262
- ]);
263
- useEffect(() => {
264
- if (strictMode && auditLog) {
265
- console.log(`[PagePermissionProvider] Strict mode enabled - all page access attempts will be logged and enforced`);
266
- }
267
- }, [strictMode, auditLog]);
268
- return /* @__PURE__ */ jsx(PagePermissionContext.Provider, { value: contextValue, children });
269
- }
270
- function usePagePermissions() {
271
- const context = useContext(PagePermissionContext);
272
- if (!context) {
273
- throw new Error("usePagePermissions must be used within a PagePermissionProvider");
274
- }
275
- return context;
276
- }
277
-
278
- // src/rbac/components/PagePermissionGuard.tsx
279
- import { useMemo as useMemo2, useEffect as useEffect2, useState as useState2 } from "react";
280
- init_UnifiedAuthProvider();
281
-
282
- // src/rbac/utils/eventContext.ts
283
- async function getOrganisationFromEvent(supabase, eventId) {
284
- const { data, error } = await supabase.from("event").select("organisation_id").eq("event_id", eventId).single();
285
- if (error || !data) {
286
- return null;
287
- }
288
- return data.organisation_id;
289
- }
290
- async function createScopeFromEvent(supabase, eventId, appId) {
291
- const organisationId = await getOrganisationFromEvent(supabase, eventId);
292
- if (!organisationId) {
293
- return null;
294
- }
295
- return {
296
- organisationId,
297
- eventId,
298
- appId
299
- };
300
- }
301
-
302
- // src/rbac/components/PagePermissionGuard.tsx
303
- init_appNameResolver();
304
- import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
305
- function PagePermissionGuard({
306
- pageName,
307
- operation,
308
- children,
309
- fallback = /* @__PURE__ */ jsx2(DefaultAccessDenied, {}),
310
- strictMode = true,
311
- auditLog = true,
312
- pageId,
313
- scope,
314
- onDenied,
315
- loading = /* @__PURE__ */ jsx2(DefaultLoading, {})
316
- }) {
317
- const { user, selectedOrganisationId, selectedEventId, supabase } = useUnifiedAuth();
318
- const [hasChecked, setHasChecked] = useState2(false);
319
- const [checkError, setCheckError] = useState2(null);
320
- const [resolvedScope, setResolvedScope] = useState2(null);
321
- useEffect2(() => {
322
- const resolveScope = async () => {
323
- if (scope) {
324
- setResolvedScope(scope);
325
- return;
326
- }
327
- let appId = void 0;
328
- if (supabase) {
329
- const appName = getCurrentAppName();
330
- if (appName) {
331
- try {
332
- console.log("[PagePermissionGuard] Resolving app name to ID:", appName);
333
- const { data: app, error: error2 } = await supabase.from("rbac_apps").select("id, name, is_active").eq("name", appName).eq("is_active", true).single();
334
- if (error2) {
335
- console.error("[PagePermissionGuard] Database error resolving app ID:", error2);
336
- const { data: inactiveApp } = await supabase.from("rbac_apps").select("id, name, is_active").eq("name", appName).single();
337
- if (inactiveApp) {
338
- console.error(`[PagePermissionGuard] App "${appName}" exists but is inactive (is_active: ${inactiveApp.is_active})`);
339
- } else {
340
- console.error(`[PagePermissionGuard] App "${appName}" not found in rbac_apps table`);
341
- }
342
- } else if (app) {
343
- appId = app.id;
344
- console.log("[PagePermissionGuard] Successfully resolved app ID:", app.id);
345
- } else {
346
- console.error("[PagePermissionGuard] No app data returned for:", appName);
347
- }
348
- } catch (error2) {
349
- console.error("[PagePermissionGuard] Unexpected error resolving app ID:", error2);
350
- }
351
- } else {
352
- console.error("[PagePermissionGuard] No app name found. Make sure to call setRBACAppName() in your app setup.");
353
- }
354
- }
355
- if (selectedOrganisationId && selectedEventId) {
356
- if (!appId) {
357
- if (false) {
358
- console.warn("[PagePermissionGuard] App ID not resolved in test environment, proceeding without it");
359
- } else {
360
- console.error("[PagePermissionGuard] CRITICAL: App ID not resolved. Check console for details.");
361
- setCheckError(new Error("App ID not resolved. Check console for database errors."));
362
- setResolvedScope(null);
363
- return;
364
- }
365
- }
366
- if (appId) {
367
- const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
368
- if (!uuidRegex.test(appId)) {
369
- console.error("[PagePermissionGuard] CRITICAL: App ID is not a valid UUID:", appId);
370
- setCheckError(new Error(`Invalid app ID format: ${appId}. Expected UUID.`));
371
- setResolvedScope(null);
372
- return;
373
- }
374
- }
375
- const resolvedScope2 = {
376
- organisationId: selectedOrganisationId,
377
- eventId: selectedEventId,
378
- appId
379
- };
380
- console.log("[PagePermissionGuard] Setting resolved scope:", resolvedScope2);
381
- setResolvedScope(resolvedScope2);
382
- return;
383
- }
384
- if (selectedOrganisationId) {
385
- if (!appId) {
386
- if (false) {
387
- console.warn("[PagePermissionGuard] App ID not resolved in test environment, proceeding without it");
388
- } else {
389
- console.error("[PagePermissionGuard] CRITICAL: App ID not resolved. Check console for details.");
390
- setCheckError(new Error("App ID not resolved. Check console for database errors."));
391
- setResolvedScope(null);
392
- return;
393
- }
394
- }
395
- if (appId) {
396
- const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
397
- if (!uuidRegex.test(appId)) {
398
- console.error("[PagePermissionGuard] CRITICAL: App ID is not a valid UUID:", appId);
399
- setCheckError(new Error(`Invalid app ID format: ${appId}. Expected UUID.`));
400
- setResolvedScope(null);
401
- return;
402
- }
403
- }
404
- const resolvedScope2 = {
405
- organisationId: selectedOrganisationId,
406
- eventId: selectedEventId || void 0,
407
- appId
408
- };
409
- console.log("[PagePermissionGuard] Setting resolved scope (org only):", resolvedScope2);
410
- setResolvedScope(resolvedScope2);
411
- return;
412
- }
413
- if (selectedEventId && supabase) {
414
- try {
415
- const eventScope = await createScopeFromEvent(supabase, selectedEventId);
416
- if (!eventScope) {
417
- setCheckError(new Error("Could not resolve organization from event context"));
418
- setResolvedScope(null);
419
- return;
420
- }
421
- setResolvedScope({
422
- ...eventScope,
423
- appId: appId || eventScope.appId
424
- });
425
- } catch (error2) {
426
- setCheckError(error2);
427
- setResolvedScope(null);
428
- }
429
- return;
430
- }
431
- setCheckError(new Error("Either organisation context or event context is required for page permission checking"));
432
- setResolvedScope(null);
433
- };
434
- resolveScope();
435
- }, [scope, selectedOrganisationId, selectedEventId, supabase]);
436
- const effectivePageId = useMemo2(() => {
437
- return pageId || pageName;
438
- }, [pageId, pageName]);
439
- const permission = useMemo2(() => {
440
- return `${operation}:page.${pageName}`;
441
- }, [operation, pageName]);
442
- console.log("[PagePermissionGuard] Calling useCan with scope:", resolvedScope);
443
- console.log("[PagePermissionGuard] resolvedScope:", resolvedScope);
444
- console.log("[PagePermissionGuard] selectedEventId:", selectedEventId);
445
- console.log("[PagePermissionGuard] About to call useCan with:", {
446
- userId: user?.id || "",
447
- scope: resolvedScope || { organisationId: "", appId: "", eventId: selectedEventId || void 0 },
448
- permission,
449
- pageId: effectivePageId,
450
- useCache: true
451
- });
452
- const { can, isLoading: canIsLoading, error: canError } = useCan(
453
- user?.id || "",
454
- resolvedScope || { organisationId: "", appId: "", eventId: selectedEventId || void 0 },
455
- permission,
456
- effectivePageId,
457
- true
458
- // Use cache
459
- );
460
- console.log("[PagePermissionGuard] useCan returned:", { can, canIsLoading, canError });
461
- const isLoading = !resolvedScope || canIsLoading;
462
- const error = checkError || canError;
463
- console.log("[PagePermissionGuard] Combined state:", {
464
- can,
465
- isLoading,
466
- canIsLoading,
467
- resolvedScopeExists: !!resolvedScope,
468
- error: error?.message
469
- });
470
- useEffect2(() => {
471
- if (!isLoading && !error) {
472
- setHasChecked(true);
473
- setCheckError(null);
474
- if (!can && onDenied) {
475
- onDenied(pageName, operation);
476
- }
477
- } else if (error) {
478
- setCheckError(error);
479
- setHasChecked(true);
480
- }
481
- }, [can, isLoading, error, pageName, operation, onDenied]);
482
- useEffect2(() => {
483
- if (auditLog && hasChecked && !isLoading) {
484
- console.log(`[PagePermissionGuard] Page access attempt:`, {
485
- pageName,
486
- operation,
487
- userId: user?.id,
488
- scope: resolvedScope,
489
- allowed: can,
490
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
491
- });
492
- }
493
- }, [auditLog, hasChecked, isLoading, pageName, operation, user?.id, resolvedScope, can]);
494
- useEffect2(() => {
495
- if (strictMode && hasChecked && !isLoading && !can) {
496
- console.error(`[PagePermissionGuard] STRICT MODE VIOLATION: User attempted to access protected page without permission`, {
497
- pageName,
498
- operation,
499
- userId: user?.id,
500
- scope: resolvedScope,
501
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
502
- });
503
- }
504
- }, [strictMode, hasChecked, isLoading, can, pageName, operation, user?.id, resolvedScope]);
505
- if (isLoading || !resolvedScope || !hasChecked) {
506
- return /* @__PURE__ */ jsx2(Fragment, { children: loading });
507
- }
508
- if (checkError) {
509
- console.error(`[PagePermissionGuard] Permission check failed for page ${pageName}:`, checkError);
510
- return /* @__PURE__ */ jsx2(Fragment, { children: fallback });
511
- }
512
- if (!can) {
513
- return /* @__PURE__ */ jsx2(Fragment, { children: fallback });
514
- }
515
- return /* @__PURE__ */ jsx2(Fragment, { children });
516
- }
517
- function DefaultAccessDenied() {
518
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center min-h-[200px] p-8 text-center", children: [
519
- /* @__PURE__ */ jsx2("div", { className: "mb-4", children: /* @__PURE__ */ jsx2("svg", { className: "w-16 h-16 text-acc-500 mx-auto", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z" }) }) }),
520
- /* @__PURE__ */ jsx2("h2", { className: "text-xl font-semibold text-sec-900 mb-2", children: "Access Denied" }),
521
- /* @__PURE__ */ jsx2("p", { className: "text-sec-600 mb-4", children: "You don't have permission to access this page." }),
522
- /* @__PURE__ */ jsx2(
523
- "button",
524
- {
525
- onClick: () => window.history.back(),
526
- className: "px-4 py-2 bg-main-600 text-main-50 rounded-md hover:bg-main-700 transition-colors",
527
- children: "Go Back"
528
- }
529
- )
530
- ] });
531
- }
532
- function DefaultLoading() {
533
- return /* @__PURE__ */ jsx2("div", { className: "flex items-center justify-center min-h-[200px] p-8", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-2", children: [
534
- /* @__PURE__ */ jsx2("div", { className: "animate-spin rounded-full h-8 w-8 border-b-2 border-main-600" }),
535
- /* @__PURE__ */ jsx2("span", { className: "text-sec-600", children: "Checking permissions..." })
536
- ] }) });
537
- }
538
-
539
- // src/rbac/components/SecureDataProvider.tsx
540
- init_UnifiedAuthProvider();
541
- import { createContext as createContext2, useContext as useContext2, useState as useState3, useCallback as useCallback3, useMemo as useMemo3, useEffect as useEffect3 } from "react";
542
- import { jsx as jsx3 } from "react/jsx-runtime";
543
- var SecureDataContext = createContext2(null);
544
- function SecureDataProvider({
545
- children,
546
- strictMode = true,
547
- auditLog = true,
548
- onDataAccess,
549
- onStrictModeViolation,
550
- maxHistorySize = 1e3,
551
- enforceRLS = true
552
- }) {
553
- const { user, selectedOrganisationId, selectedEventId } = useUnifiedAuth();
554
- const { validateContext } = useSecureDataAccess();
555
- const [dataAccessHistory, setDataAccessHistory] = useState3([]);
556
- const [isEnabled, setIsEnabled] = useState3(true);
557
- const currentScope = useMemo3(() => {
558
- if (!selectedOrganisationId) return null;
559
- return {
560
- organisationId: selectedOrganisationId,
561
- eventId: selectedEventId || void 0,
562
- appId: void 0
563
- };
564
- }, [selectedOrganisationId, selectedEventId]);
565
- const isDataAccessAllowed = useCallback3((table, operation, scope) => {
566
- if (!isEnabled) return true;
567
- if (!user?.id) return false;
568
- const effectiveScope = scope || currentScope;
569
- if (!effectiveScope) return false;
570
- const permission = `${operation}:data.${table}`;
571
- return true;
572
- }, [isEnabled, user?.id, currentScope]);
573
- const getDataAccessPermissions = useCallback3(() => {
574
- if (!isEnabled || !user?.id) return {};
575
- return {};
576
- }, [isEnabled, user?.id]);
577
- const getDataAccessHistory = useCallback3(() => {
578
- return [...dataAccessHistory];
579
- }, [dataAccessHistory]);
580
- const clearDataAccessHistory = useCallback3(() => {
581
- setDataAccessHistory([]);
582
- }, []);
583
- const validateDataAccess = useCallback3((table, operation, scope) => {
584
- if (!isEnabled) return true;
585
- if (!user?.id) return false;
586
- const effectiveScope = scope || currentScope;
587
- if (!effectiveScope) return false;
588
- try {
589
- validateContext();
590
- } catch (error) {
591
- console.error(`[SecureDataProvider] Organisation context validation failed:`, error);
592
- return false;
593
- }
594
- return isDataAccessAllowed(table, operation, effectiveScope);
595
- }, [isEnabled, user?.id, currentScope, validateContext, isDataAccessAllowed]);
596
- const recordDataAccess = useCallback3((table, operation, allowed, query, filters, scope) => {
597
- if (!auditLog || !user?.id) return;
598
- const record = {
599
- table,
600
- operation,
601
- userId: user.id,
602
- scope: scope || currentScope || { organisationId: "" },
603
- allowed,
604
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
605
- query,
606
- filters
607
- };
608
- setDataAccessHistory((prev) => {
609
- const newHistory = [record, ...prev];
610
- return newHistory.slice(0, maxHistorySize);
611
- });
612
- if (onDataAccess) {
613
- onDataAccess(table, operation, allowed, record);
614
- }
615
- if (strictMode && !allowed && onStrictModeViolation) {
616
- onStrictModeViolation(table, operation, record);
617
- }
618
- }, [auditLog, user?.id, currentScope, maxHistorySize, onDataAccess, onStrictModeViolation, strictMode]);
619
- const contextValue = useMemo3(() => ({
620
- isDataAccessAllowed,
621
- getDataAccessPermissions,
622
- isEnabled,
623
- isStrictMode: strictMode,
624
- isAuditLogEnabled: auditLog,
625
- getDataAccessHistory,
626
- clearDataAccessHistory,
627
- validateDataAccess
628
- }), [
629
- isDataAccessAllowed,
630
- getDataAccessPermissions,
631
- isEnabled,
632
- strictMode,
633
- auditLog,
634
- getDataAccessHistory,
635
- clearDataAccessHistory,
636
- validateDataAccess
637
- ]);
638
- useEffect3(() => {
639
- if (strictMode && auditLog) {
640
- console.log(`[SecureDataProvider] Strict mode enabled - all data access attempts will be logged and enforced`);
641
- }
642
- }, [strictMode, auditLog]);
643
- useEffect3(() => {
644
- if (enforceRLS && auditLog) {
645
- console.log(`[SecureDataProvider] RLS enforcement enabled - all queries will include organisation context`);
646
- }
647
- }, [enforceRLS, auditLog]);
648
- return /* @__PURE__ */ jsx3(SecureDataContext.Provider, { value: contextValue, children });
649
- }
650
- function useSecureData() {
651
- const context = useContext2(SecureDataContext);
652
- if (!context) {
653
- throw new Error("useSecureData must be used within a SecureDataProvider");
654
- }
655
- return context;
656
- }
657
-
658
- // src/rbac/components/PermissionEnforcer.tsx
659
- import { useMemo as useMemo4, useEffect as useEffect4, useState as useState4 } from "react";
660
- init_UnifiedAuthProvider();
661
- import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
662
- function PermissionEnforcer({
663
- permissions,
664
- operation,
665
- children,
666
- fallback = /* @__PURE__ */ jsx4(DefaultAccessDenied2, {}),
667
- strictMode = true,
668
- auditLog = true,
669
- scope,
670
- onDenied,
671
- loading = /* @__PURE__ */ jsx4(DefaultLoading2, {}),
672
- requireAll = true
673
- }) {
674
- const { user, selectedOrganisationId, selectedEventId, supabase } = useUnifiedAuth();
675
- const [hasChecked, setHasChecked] = useState4(false);
676
- const [checkError, setCheckError] = useState4(null);
677
- const [permissionResults, setPermissionResults] = useState4({});
678
- const [resolvedScope, setResolvedScope] = useState4(null);
679
- useEffect4(() => {
680
- const resolveScope = async () => {
681
- if (scope) {
682
- setResolvedScope(scope);
683
- return;
684
- }
685
- if (selectedOrganisationId && selectedEventId) {
686
- setResolvedScope({
687
- organisationId: selectedOrganisationId,
688
- eventId: selectedEventId,
689
- appId: void 0
690
- });
691
- return;
692
- }
693
- if (selectedOrganisationId) {
694
- setResolvedScope({
695
- organisationId: selectedOrganisationId,
696
- eventId: selectedEventId || void 0,
697
- appId: void 0
698
- });
699
- return;
700
- }
701
- if (selectedEventId && supabase) {
702
- try {
703
- const eventScope = await createScopeFromEvent(supabase, selectedEventId);
704
- if (!eventScope) {
705
- setCheckError(new Error("Could not resolve organization from event context"));
706
- return;
707
- }
708
- setResolvedScope(eventScope);
709
- } catch (error2) {
710
- setCheckError(error2);
711
- }
712
- return;
713
- }
714
- setCheckError(new Error("Either organisation context or event context is required for permission checking"));
715
- };
716
- resolveScope();
717
- }, [scope, selectedOrganisationId, selectedEventId, supabase]);
718
- const representativePermission = permissions[0];
719
- const { can, isLoading, error } = useCan(
720
- user?.id || "",
721
- resolvedScope || { eventId: selectedEventId || void 0 },
722
- representativePermission,
723
- void 0,
724
- true
725
- // Use cache
726
- );
727
- const hasRequiredPermissions = useMemo4(() => {
728
- if (permissions.length === 0) return true;
729
- return can;
730
- }, [permissions, can]);
731
- useEffect4(() => {
732
- if (!isLoading && !error) {
733
- setHasChecked(true);
734
- setCheckError(null);
735
- if (!hasRequiredPermissions && onDenied) {
736
- onDenied(permissions, operation);
737
- }
738
- } else if (error) {
739
- setCheckError(error);
740
- setHasChecked(true);
741
- }
742
- }, [hasRequiredPermissions, isLoading, error, permissions, operation, onDenied]);
743
- useEffect4(() => {
744
- if (auditLog && hasChecked && !isLoading) {
745
- console.log(`[PermissionEnforcer] Permission check attempt:`, {
746
- permissions,
747
- operation,
748
- userId: user?.id,
749
- scope: resolvedScope,
750
- allowed: hasRequiredPermissions,
751
- requireAll,
752
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
753
- });
754
- }
755
- }, [auditLog, hasChecked, isLoading, permissions, operation, user?.id, resolvedScope, hasRequiredPermissions, requireAll]);
756
- useEffect4(() => {
757
- if (strictMode && hasChecked && !isLoading && !hasRequiredPermissions) {
758
- console.error(`[PermissionEnforcer] STRICT MODE VIOLATION: User attempted to perform operation without permission`, {
759
- permissions,
760
- operation,
761
- userId: user?.id,
762
- scope: resolvedScope,
763
- requireAll,
764
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
765
- });
766
- }
767
- }, [strictMode, hasChecked, isLoading, hasRequiredPermissions, permissions, operation, user?.id, resolvedScope, requireAll]);
768
- if (isLoading || !hasChecked) {
769
- return /* @__PURE__ */ jsx4(Fragment2, { children: loading });
770
- }
771
- if (checkError) {
772
- console.error(`[PermissionEnforcer] Permission check failed for operation ${operation}:`, checkError);
773
- return /* @__PURE__ */ jsx4(Fragment2, { children: fallback });
774
- }
775
- if (!hasRequiredPermissions) {
776
- return /* @__PURE__ */ jsx4(Fragment2, { children: fallback });
777
- }
778
- return /* @__PURE__ */ jsx4(Fragment2, { children });
779
- }
780
- function DefaultAccessDenied2() {
781
- return /* @__PURE__ */ jsxs2("div", { className: "flex flex-col items-center justify-center min-h-[200px] p-8 text-center", children: [
782
- /* @__PURE__ */ jsx4("div", { className: "mb-4", children: /* @__PURE__ */ jsx4("svg", { className: "w-16 h-16 text-acc-500 mx-auto", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx4("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z" }) }) }),
783
- /* @__PURE__ */ jsx4("h2", { className: "text-xl font-semibold text-sec-900 mb-2", children: "Access Denied" }),
784
- /* @__PURE__ */ jsx4("p", { className: "text-sec-600 mb-4", children: "You don't have permission to perform this operation." }),
785
- /* @__PURE__ */ jsx4(
786
- "button",
787
- {
788
- onClick: () => window.history.back(),
789
- className: "px-4 py-2 bg-main-600 text-main-50 rounded-md hover:bg-main-700 transition-colors",
790
- children: "Go Back"
791
- }
792
- )
793
- ] });
794
- }
795
- function DefaultLoading2() {
796
- return /* @__PURE__ */ jsx4("div", { className: "flex items-center justify-center min-h-[200px] p-8", children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center space-x-2", children: [
797
- /* @__PURE__ */ jsx4("div", { className: "animate-spin rounded-full h-8 w-8 border-b-2 border-main-600" }),
798
- /* @__PURE__ */ jsx4("span", { className: "text-sec-600", children: "Checking permissions..." })
799
- ] }) });
800
- }
801
-
802
- // src/rbac/components/RoleBasedRouter.tsx
803
- import { useMemo as useMemo5, useCallback as useCallback5, useEffect as useEffect5, useState as useState5, createContext as createContext3, useContext as useContext3 } from "react";
804
- import { useLocation, useNavigate, Outlet } from "react-router-dom";
805
- init_UnifiedAuthProvider();
806
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
807
- var RoleBasedRouterContext = createContext3(null);
808
- function RoleBasedRouter({
809
- routes,
810
- fallbackRoute = "/unauthorized",
811
- children,
812
- strictMode = true,
813
- auditLog = true,
814
- onRouteAccess,
815
- onStrictModeViolation,
816
- maxHistorySize = 1e3,
817
- unauthorizedComponent: UnauthorizedComponent = DefaultUnauthorizedComponent
818
- }) {
819
- const { user, selectedOrganisationId, selectedEventId } = useUnifiedAuth();
820
- const location = useLocation();
821
- const navigate = useNavigate();
822
- const [routeAccessHistory, setRouteAccessHistory] = useState5([]);
823
- const [currentRoute, setCurrentRoute] = useState5("");
824
- const currentScope = useMemo5(() => {
825
- if (!selectedOrganisationId) return null;
826
- return {
827
- organisationId: selectedOrganisationId,
828
- eventId: selectedEventId || void 0,
829
- appId: void 0
830
- };
831
- }, [selectedOrganisationId, selectedEventId]);
832
- const currentRouteConfig = useMemo5(() => {
833
- const currentPath = location.pathname;
834
- return routes.find((route) => route.path === currentPath) || null;
835
- }, [routes, location.pathname]);
836
- const canAccessRoute = useCallback5((path) => {
837
- if (!user?.id || !currentScope) return false;
838
- const routeConfig = routes.find((route) => route.path === path);
839
- if (!routeConfig) return false;
840
- return true;
841
- }, [user?.id, currentScope, routes]);
842
- const { can: canAccessCurrentRoute, isLoading: permissionLoading } = useCan(
843
- user?.id || "",
844
- currentScope || { organisationId: "", eventId: void 0, appId: void 0 },
845
- currentRouteConfig?.permissions?.[0] || "read:page",
846
- currentRouteConfig?.pageId
847
- );
848
- const hasPermissions = currentRouteConfig?.permissions && currentRouteConfig.permissions.length > 0;
849
- const finalCanAccess = hasPermissions ? canAccessCurrentRoute : false;
850
- const finalLoading = hasPermissions ? permissionLoading : false;
851
- const getAccessibleRoutes = useCallback5(() => {
852
- if (!user?.id || !currentScope) return [];
853
- return routes.filter((route) => canAccessRoute(route.path));
854
- }, [user?.id, currentScope, routes, canAccessRoute]);
855
- const getRouteConfig = useCallback5((path) => {
856
- return routes.find((route) => route.path === path) || null;
857
- }, [routes]);
858
- const getRouteAccessHistory = useCallback5(() => {
859
- return [...routeAccessHistory];
860
- }, [routeAccessHistory]);
861
- const clearRouteAccessHistory = useCallback5(() => {
862
- setRouteAccessHistory([]);
863
- }, []);
864
- const recordRouteAccess = useCallback5((route, allowed, routeConfig) => {
865
- if (!auditLog || !user?.id || !currentScope) return;
866
- const record = {
867
- route,
868
- permissions: routeConfig.permissions,
869
- userId: user.id,
870
- scope: currentScope,
871
- allowed,
872
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
873
- pageId: routeConfig.pageId,
874
- roles: routeConfig.roles,
875
- accessLevel: routeConfig.accessLevel
876
- };
877
- setRouteAccessHistory((prev) => {
878
- const newHistory = [record, ...prev];
879
- return newHistory.slice(0, maxHistorySize);
880
- });
881
- if (onRouteAccess) {
882
- onRouteAccess(route, allowed, record);
883
- }
884
- if (strictMode && !allowed && onStrictModeViolation) {
885
- onStrictModeViolation(route, record);
886
- }
887
- }, [auditLog, user?.id, currentScope, maxHistorySize, onRouteAccess, onStrictModeViolation, strictMode]);
888
- useEffect5(() => {
889
- const currentPath = location.pathname;
890
- setCurrentRoute(currentPath);
891
- if (!currentRouteConfig) {
892
- if (strictMode) {
893
- console.error(`[RoleBasedRouter] STRICT MODE VIOLATION: Route not found in configuration`, {
894
- route: currentPath,
895
- userId: user?.id,
896
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
897
- });
898
- if (onStrictModeViolation) {
899
- onStrictModeViolation(currentPath, {
900
- route: currentPath,
901
- permissions: [],
902
- userId: user?.id || "",
903
- scope: currentScope || { organisationId: "" },
904
- allowed: false,
905
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
906
- });
907
- }
908
- }
909
- return;
910
- }
911
- const allowed = finalCanAccess;
912
- recordRouteAccess(currentPath, allowed, currentRouteConfig);
913
- if (!allowed) {
914
- navigate(fallbackRoute, { replace: true });
915
- }
916
- }, [location.pathname, currentRouteConfig, canAccessCurrentRoute, recordRouteAccess, strictMode, user?.id, currentScope, onStrictModeViolation, navigate, fallbackRoute]);
917
- const contextValue = useMemo5(() => ({
918
- getAccessibleRoutes,
919
- canAccessRoute,
920
- getRouteConfig,
921
- getRouteAccessHistory,
922
- clearRouteAccessHistory,
923
- isStrictMode: strictMode,
924
- isAuditLogEnabled: auditLog
925
- }), [
926
- getAccessibleRoutes,
927
- canAccessRoute,
928
- getRouteConfig,
929
- getRouteAccessHistory,
930
- clearRouteAccessHistory,
931
- strictMode,
932
- auditLog
933
- ]);
934
- if (finalLoading) {
935
- return /* @__PURE__ */ jsx5("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsxs3("div", { className: "text-center", children: [
936
- /* @__PURE__ */ jsx5("div", { className: "animate-spin rounded-full h-8 w-8 border-b-2 border-main-600 mx-auto mb-4" }),
937
- /* @__PURE__ */ jsx5("p", { className: "text-sec-600", children: "Checking permissions..." })
938
- ] }) });
939
- }
940
- if (currentRouteConfig && !finalCanAccess) {
941
- return /* @__PURE__ */ jsx5(
942
- UnauthorizedComponent,
943
- {
944
- route: currentRoute,
945
- reason: "Insufficient permissions"
946
- }
947
- );
948
- }
949
- return /* @__PURE__ */ jsxs3(RoleBasedRouterContext.Provider, { value: contextValue, children: [
950
- children,
951
- /* @__PURE__ */ jsx5(Outlet, {})
952
- ] });
953
- }
954
- function useRoleBasedRouter() {
955
- const context = useContext3(RoleBasedRouterContext);
956
- if (!context) {
957
- throw new Error("useRoleBasedRouter must be used within a RoleBasedRouter");
958
- }
959
- return context;
960
- }
961
- function DefaultUnauthorizedComponent({ route, reason }) {
962
- return /* @__PURE__ */ jsxs3("div", { className: "flex flex-col items-center justify-center min-h-screen p-8 text-center", children: [
963
- /* @__PURE__ */ jsx5("div", { className: "mb-4", children: /* @__PURE__ */ jsx5("svg", { className: "w-16 h-16 text-acc-500 mx-auto", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z" }) }) }),
964
- /* @__PURE__ */ jsx5("h2", { className: "text-xl font-semibold text-sec-900 mb-2", children: "Access Denied" }),
965
- /* @__PURE__ */ jsxs3("p", { className: "text-sec-600 mb-4", children: [
966
- "You don't have permission to access ",
967
- /* @__PURE__ */ jsx5("code", { className: "bg-sec-100 px-2 py-1 rounded", children: route })
968
- ] }),
969
- /* @__PURE__ */ jsxs3("p", { className: "text-sm text-sec-500 mb-4", children: [
970
- "Reason: ",
971
- reason
972
- ] }),
973
- /* @__PURE__ */ jsx5(
974
- "button",
975
- {
976
- onClick: () => window.history.back(),
977
- className: "px-4 py-2 bg-main-600 text-main-50 rounded-md hover:bg-main-700 transition-colors",
978
- children: "Go Back"
979
- }
980
- )
981
- ] });
982
- }
983
-
984
- // src/rbac/components/NavigationProvider.tsx
985
- init_UnifiedAuthProvider();
986
- import { createContext as createContext4, useContext as useContext4, useState as useState6, useCallback as useCallback6, useMemo as useMemo6, useEffect as useEffect6 } from "react";
987
- import { jsx as jsx6 } from "react/jsx-runtime";
988
- var NavigationContext = createContext4(null);
989
- function NavigationProvider({
990
- children,
991
- strictMode = true,
992
- auditLog = true,
993
- onNavigationAccess,
994
- onStrictModeViolation,
995
- maxHistorySize = 1e3
996
- }) {
997
- const { user, selectedOrganisationId, selectedEventId } = useUnifiedAuth();
998
- const [navigationAccessHistory, setNavigationAccessHistory] = useState6([]);
999
- const [isEnabled, setIsEnabled] = useState6(true);
1000
- const currentScope = useMemo6(() => {
1001
- if (!selectedOrganisationId) return null;
1002
- return {
1003
- organisationId: selectedOrganisationId,
1004
- eventId: selectedEventId || void 0,
1005
- appId: void 0
1006
- };
1007
- }, [selectedOrganisationId, selectedEventId]);
1008
- const hasNavigationPermission = useCallback6((item) => {
1009
- if (!isEnabled) return true;
1010
- if (!user?.id) return false;
1011
- if (!currentScope) return false;
1012
- return true;
1013
- }, [isEnabled, user?.id, currentScope]);
1014
- const getNavigationPermissions = useCallback6(() => {
1015
- if (!isEnabled || !user?.id) return {};
1016
- return {};
1017
- }, [isEnabled, user?.id]);
1018
- const getFilteredNavigationItems = useCallback6((items) => {
1019
- if (!isEnabled) return items;
1020
- return items.filter((item) => hasNavigationPermission(item));
1021
- }, [isEnabled, hasNavigationPermission]);
1022
- const getNavigationAccessHistory = useCallback6(() => {
1023
- return [...navigationAccessHistory];
1024
- }, [navigationAccessHistory]);
1025
- const clearNavigationAccessHistory = useCallback6(() => {
1026
- setNavigationAccessHistory([]);
1027
- }, []);
1028
- const recordNavigationAccess = useCallback6((item, allowed) => {
1029
- if (!auditLog || !user?.id || !currentScope) return;
1030
- const record = {
1031
- navigationItem: item.id,
1032
- permissions: item.permissions,
1033
- userId: user.id,
1034
- scope: currentScope,
1035
- allowed,
1036
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1037
- pageId: item.pageId,
1038
- roles: item.roles,
1039
- accessLevel: item.accessLevel
1040
- };
1041
- setNavigationAccessHistory((prev) => {
1042
- const newHistory = [record, ...prev];
1043
- return newHistory.slice(0, maxHistorySize);
1044
- });
1045
- if (onNavigationAccess) {
1046
- onNavigationAccess(item, allowed, record);
1047
- }
1048
- if (strictMode && !allowed && onStrictModeViolation) {
1049
- onStrictModeViolation(item, record);
1050
- }
1051
- }, [auditLog, user?.id, currentScope, maxHistorySize, onNavigationAccess, onStrictModeViolation, strictMode]);
1052
- const contextValue = useMemo6(() => ({
1053
- hasNavigationPermission,
1054
- getNavigationPermissions,
1055
- getFilteredNavigationItems,
1056
- isEnabled,
1057
- isStrictMode: strictMode,
1058
- isAuditLogEnabled: auditLog,
1059
- getNavigationAccessHistory,
1060
- clearNavigationAccessHistory
1061
- }), [
1062
- hasNavigationPermission,
1063
- getNavigationPermissions,
1064
- getFilteredNavigationItems,
1065
- isEnabled,
1066
- strictMode,
1067
- auditLog,
1068
- getNavigationAccessHistory,
1069
- clearNavigationAccessHistory
1070
- ]);
1071
- useEffect6(() => {
1072
- if (strictMode && auditLog) {
1073
- console.log(`[NavigationProvider] Strict mode enabled - all navigation access attempts will be logged and enforced`);
1074
- }
1075
- }, [strictMode, auditLog]);
1076
- return /* @__PURE__ */ jsx6(NavigationContext.Provider, { value: contextValue, children });
1077
- }
1078
- function useNavigationPermissions() {
1079
- const context = useContext4(NavigationContext);
1080
- if (!context) {
1081
- throw new Error("useNavigationPermissions must be used within a NavigationProvider");
1082
- }
1083
- return context;
1084
- }
1085
-
1086
- // src/rbac/components/NavigationGuard.tsx
1087
- import { useMemo as useMemo7, useEffect as useEffect7, useState as useState7 } from "react";
1088
- init_UnifiedAuthProvider();
1089
- import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
1090
- function NavigationGuard({
1091
- navigationItem,
1092
- children,
1093
- fallback = /* @__PURE__ */ jsx7(DefaultAccessDenied3, {}),
1094
- strictMode = true,
1095
- auditLog = true,
1096
- scope,
1097
- onDenied,
1098
- loading = /* @__PURE__ */ jsx7(DefaultLoading3, {}),
1099
- requireAll = true
1100
- }) {
1101
- const { user, selectedOrganisationId, selectedEventId, supabase } = useUnifiedAuth();
1102
- const [hasChecked, setHasChecked] = useState7(false);
1103
- const [checkError, setCheckError] = useState7(null);
1104
- const [resolvedScope, setResolvedScope] = useState7(null);
1105
- useEffect7(() => {
1106
- const resolveScope = async () => {
1107
- if (scope) {
1108
- setResolvedScope(scope);
1109
- return;
1110
- }
1111
- if (selectedOrganisationId && selectedEventId) {
1112
- setResolvedScope({
1113
- organisationId: selectedOrganisationId,
1114
- eventId: selectedEventId,
1115
- appId: void 0
1116
- });
1117
- return;
1118
- }
1119
- if (selectedOrganisationId) {
1120
- setResolvedScope({
1121
- organisationId: selectedOrganisationId,
1122
- eventId: selectedEventId || void 0,
1123
- appId: void 0
1124
- });
1125
- return;
1126
- }
1127
- if (selectedEventId && supabase) {
1128
- try {
1129
- const eventScope = await createScopeFromEvent(supabase, selectedEventId);
1130
- if (!eventScope) {
1131
- setCheckError(new Error("Could not resolve organization from event context"));
1132
- return;
1133
- }
1134
- setResolvedScope(eventScope);
1135
- } catch (error2) {
1136
- setCheckError(error2);
1137
- }
1138
- return;
1139
- }
1140
- setCheckError(new Error("Either organisation context or event context is required for navigation permission checking"));
1141
- };
1142
- resolveScope();
1143
- }, [scope, selectedOrganisationId, selectedEventId, supabase]);
1144
- const representativePermission = navigationItem.permissions[0];
1145
- const { can, isLoading, error } = useCan(
1146
- user?.id || "",
1147
- resolvedScope || { eventId: selectedEventId || void 0 },
1148
- representativePermission,
1149
- navigationItem.pageId,
1150
- true
1151
- // Use cache
1152
- );
1153
- const hasRequiredPermissions = useMemo7(() => {
1154
- if (navigationItem.permissions.length === 0) return true;
1155
- return can;
1156
- }, [navigationItem.permissions, can]);
1157
- useEffect7(() => {
1158
- if (!isLoading && !error) {
1159
- setHasChecked(true);
1160
- setCheckError(null);
1161
- if (!hasRequiredPermissions && onDenied) {
1162
- onDenied(navigationItem);
1163
- }
1164
- } else if (error) {
1165
- setCheckError(error);
1166
- setHasChecked(true);
1167
- }
1168
- }, [hasRequiredPermissions, isLoading, error, navigationItem, onDenied]);
1169
- useEffect7(() => {
1170
- if (auditLog && hasChecked && !isLoading) {
1171
- console.log(`[NavigationGuard] Navigation access attempt:`, {
1172
- navigationItem: navigationItem.id,
1173
- permissions: navigationItem.permissions,
1174
- userId: user?.id,
1175
- scope: resolvedScope,
1176
- allowed: hasRequiredPermissions,
1177
- requireAll,
1178
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1179
- });
1180
- }
1181
- }, [auditLog, hasChecked, isLoading, navigationItem, user?.id, resolvedScope, hasRequiredPermissions, requireAll]);
1182
- useEffect7(() => {
1183
- if (strictMode && hasChecked && !isLoading && !hasRequiredPermissions) {
1184
- console.error(`[NavigationGuard] STRICT MODE VIOLATION: User attempted to access protected navigation item without permission`, {
1185
- navigationItem: navigationItem.id,
1186
- permissions: navigationItem.permissions,
1187
- userId: user?.id,
1188
- scope: resolvedScope,
1189
- requireAll,
1190
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1191
- });
1192
- }
1193
- }, [strictMode, hasChecked, isLoading, hasRequiredPermissions, navigationItem, user?.id, resolvedScope, requireAll]);
1194
- if (isLoading || !resolvedScope || !hasChecked) {
1195
- return /* @__PURE__ */ jsx7(Fragment3, { children: loading });
1196
- }
1197
- if (checkError) {
1198
- console.error(`[NavigationGuard] Permission check failed for navigation item ${navigationItem.id}:`, checkError);
1199
- return /* @__PURE__ */ jsx7(Fragment3, { children: fallback });
1200
- }
1201
- if (!hasRequiredPermissions) {
1202
- return /* @__PURE__ */ jsx7(Fragment3, { children: fallback });
1203
- }
1204
- return /* @__PURE__ */ jsx7(Fragment3, { children });
1205
- }
1206
- function DefaultAccessDenied3() {
1207
- return /* @__PURE__ */ jsx7("div", { className: "flex items-center justify-center p-2 text-center", children: /* @__PURE__ */ jsxs4("div", { className: "flex items-center space-x-2", children: [
1208
- /* @__PURE__ */ jsx7("svg", { className: "w-4 h-4 text-acc-500", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx7("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z" }) }),
1209
- /* @__PURE__ */ jsx7("span", { className: "text-sm text-sec-600", children: "Access Denied" })
1210
- ] }) });
1211
- }
1212
- function DefaultLoading3() {
1213
- return /* @__PURE__ */ jsx7("div", { className: "flex items-center justify-center p-2", children: /* @__PURE__ */ jsxs4("div", { className: "flex items-center space-x-2", children: [
1214
- /* @__PURE__ */ jsx7("div", { className: "animate-spin rounded-full h-4 w-4 border-b-2 border-main-600" }),
1215
- /* @__PURE__ */ jsx7("span", { className: "text-sm text-sec-600", children: "Checking..." })
1216
- ] }) });
1217
- }
1218
- var NavigationGuard_default = NavigationGuard;
1219
-
1220
- // src/rbac/components/EnhancedNavigationMenu.tsx
1221
- import { useMemo as useMemo8, useCallback as useCallback8, useEffect as useEffect8, useState as useState8 } from "react";
1222
- import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
1223
- function EnhancedNavigationMenu({
1224
- items,
1225
- strictMode = true,
1226
- auditLog = true,
1227
- onNavigationAccess,
1228
- onStrictModeViolation,
1229
- className = "flex flex-col space-y-1",
1230
- itemClassName = "px-3 py-2 rounded-md text-sm font-medium transition-colors",
1231
- activeItemClassName = "bg-main-100 text-main-700",
1232
- disabledItemClassName = "text-sec-400 cursor-not-allowed",
1233
- hideUnauthorizedItems = false,
1234
- renderItem,
1235
- activePath,
1236
- onItemClick
1237
- }) {
1238
- const {
1239
- hasNavigationPermission,
1240
- getFilteredNavigationItems,
1241
- isEnabled,
1242
- isStrictMode,
1243
- isAuditLogEnabled
1244
- } = useNavigationPermissions();
1245
- const [navigationHistory, setNavigationHistory] = useState8([]);
1246
- const filteredItems = useMemo8(() => {
1247
- if (!isEnabled) return items;
1248
- return getFilteredNavigationItems(items);
1249
- }, [isEnabled, items, getFilteredNavigationItems]);
1250
- const handleItemClick = useCallback8((item) => {
1251
- if (onItemClick) {
1252
- onItemClick(item);
1253
- }
1254
- if (auditLog) {
1255
- console.log(`[EnhancedNavigationMenu] Navigation item clicked:`, {
1256
- item: item.id,
1257
- path: item.path,
1258
- permissions: item.permissions,
1259
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1260
- });
1261
- }
1262
- setNavigationHistory((prev) => {
1263
- const newHistory = [item, ...prev.filter((i) => i.id !== item.id)];
1264
- return newHistory.slice(0, 10);
1265
- });
1266
- }, [onItemClick, auditLog]);
1267
- const handleNavigationAccess = useCallback8((item, allowed) => {
1268
- if (onNavigationAccess) {
1269
- onNavigationAccess(item, allowed);
1270
- }
1271
- if (auditLog) {
1272
- console.log(`[EnhancedNavigationMenu] Navigation access attempt:`, {
1273
- item: item.id,
1274
- allowed,
1275
- strictMode,
1276
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1277
- });
1278
- }
1279
- }, [onNavigationAccess, auditLog, strictMode]);
1280
- const handleStrictModeViolation = useCallback8((item) => {
1281
- if (onStrictModeViolation) {
1282
- onStrictModeViolation(item);
1283
- }
1284
- if (strictMode) {
1285
- console.error(`[EnhancedNavigationMenu] STRICT MODE VIOLATION: User attempted to access protected navigation item without permission`, {
1286
- item: item.id,
1287
- path: item.path,
1288
- permissions: item.permissions,
1289
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1290
- });
1291
- }
1292
- }, [onStrictModeViolation, strictMode]);
1293
- const defaultRenderItem = useCallback8((item, isAuthorized) => {
1294
- const isActive = activePath === item.path;
1295
- const isDisabled = !isAuthorized;
1296
- return /* @__PURE__ */ jsx8(
1297
- NavigationGuard_default,
1298
- {
1299
- navigationItem: item,
1300
- strictMode,
1301
- auditLog,
1302
- onDenied: handleStrictModeViolation,
1303
- fallback: hideUnauthorizedItems ? null : /* @__PURE__ */ jsx8("div", { className: `${itemClassName} ${disabledItemClassName}`, children: /* @__PURE__ */ jsxs5("div", { className: "flex items-center space-x-2", children: [
1304
- item.meta?.icon && /* @__PURE__ */ jsx8("span", { className: "text-sm", children: item.meta.icon }),
1305
- /* @__PURE__ */ jsx8("span", { children: item.label }),
1306
- /* @__PURE__ */ jsx8("span", { className: "text-xs text-sec-400", children: "(Access Denied)" })
1307
- ] }) }),
1308
- children: /* @__PURE__ */ jsx8(
1309
- "button",
1310
- {
1311
- onClick: () => handleItemClick(item),
1312
- className: `${itemClassName} ${isActive ? activeItemClassName : ""} ${isDisabled ? disabledItemClassName : "hover:bg-sec-100"}`,
1313
- disabled: isDisabled,
1314
- children: /* @__PURE__ */ jsxs5("div", { className: "flex items-center space-x-2", children: [
1315
- item.meta?.icon && /* @__PURE__ */ jsx8("span", { className: "text-sm", children: item.meta.icon }),
1316
- /* @__PURE__ */ jsx8("span", { children: item.label }),
1317
- item.meta?.description && /* @__PURE__ */ jsx8("span", { className: "text-xs text-sec-500 ml-auto", children: item.meta.description })
1318
- ] })
1319
- }
1320
- )
1321
- },
1322
- item.id
1323
- );
1324
- }, [
1325
- activePath,
1326
- itemClassName,
1327
- activeItemClassName,
1328
- disabledItemClassName,
1329
- hideUnauthorizedItems,
1330
- strictMode,
1331
- auditLog,
1332
- handleStrictModeViolation,
1333
- handleItemClick
1334
- ]);
1335
- useEffect8(() => {
1336
- if (strictMode && auditLog) {
1337
- console.log(`[EnhancedNavigationMenu] Strict mode enabled - all navigation access attempts will be logged and enforced`);
1338
- }
1339
- }, [strictMode, auditLog]);
1340
- useEffect8(() => {
1341
- if (auditLog) {
1342
- console.log(`[EnhancedNavigationMenu] Navigation menu initialized:`, {
1343
- totalItems: items.length,
1344
- filteredItems: filteredItems.length,
1345
- strictMode,
1346
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1347
- });
1348
- }
1349
- }, [items.length, filteredItems.length, strictMode, auditLog]);
1350
- return /* @__PURE__ */ jsx8("nav", { className, children: filteredItems.map((item) => {
1351
- const isAuthorized = hasNavigationPermission(item);
1352
- if (renderItem) {
1353
- return renderItem(item, isAuthorized);
1354
- }
1355
- return defaultRenderItem(item, isAuthorized);
1356
- }) });
1357
- }
1358
-
1359
- // src/rbac/adapters.tsx
1360
- import React9, { useContext as useContext5 } from "react";
1361
- import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
1362
- function PermissionGuard({
1363
- userId,
1364
- scope,
1365
- permission,
1366
- pageId,
1367
- children,
1368
- fallback = null,
1369
- onDenied,
1370
- loading = null,
1371
- // NEW: Phase 1 - Enhanced Security Features
1372
- strictMode = true,
1373
- auditLog = true,
1374
- enforceAudit = true
1375
- }) {
1376
- const logger = getRBACLogger();
1377
- const authContext = useContext5(React9.createContext(null));
1378
- let effectiveUserId = userId;
1379
- if (!effectiveUserId) {
1380
- try {
1381
- if (authContext?.user?.id) {
1382
- effectiveUserId = authContext.user.id;
1383
- } else {
1384
- const globalUser = window.__PACE_USER__;
1385
- if (globalUser?.id) {
1386
- effectiveUserId = globalUser.id;
1387
- }
1388
- }
1389
- } catch (error2) {
1390
- logger.debug("Could not infer userId from context:", error2);
1391
- }
1392
- }
1393
- const { can, isLoading, error } = useCan(effectiveUserId || "", scope, permission, pageId);
1394
- if (!effectiveUserId) {
1395
- logger.error("PermissionGuard: No userId provided and could not infer from context");
1396
- return /* @__PURE__ */ jsxs6("div", { className: "rbac-error", role: "alert", children: [
1397
- /* @__PURE__ */ jsx9("p", { children: "Permission check failed: User context not available" }),
1398
- /* @__PURE__ */ jsxs6("details", { children: [
1399
- /* @__PURE__ */ jsx9("summary", { children: "Debug info" }),
1400
- /* @__PURE__ */ jsx9("p", { children: "Make sure to either:" }),
1401
- /* @__PURE__ */ jsxs6("ul", { children: [
1402
- /* @__PURE__ */ jsx9("li", { children: "Pass userId prop explicitly" }),
1403
- /* @__PURE__ */ jsx9("li", { children: "Wrap your app with an auth provider" }),
1404
- /* @__PURE__ */ jsx9("li", { children: "Set window.__PACE_USER__ with user data" })
1405
- ] })
1406
- ] })
1407
- ] });
1408
- }
1409
- if (isLoading) {
1410
- return loading || /* @__PURE__ */ jsx9("div", { className: "rbac-loading", role: "status", "aria-live": "polite", children: /* @__PURE__ */ jsx9("span", { className: "sr-only", children: "Checking permissions..." }) });
1411
- }
1412
- if (error) {
1413
- logger.error("Permission check failed:", error);
1414
- if (auditLog) {
1415
- logger.info(`[PermissionGuard] Permission check failed:`, {
1416
- userId: effectiveUserId,
1417
- scope,
1418
- permission,
1419
- pageId,
1420
- error: error.message,
1421
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1422
- });
1423
- }
1424
- return fallback;
1425
- }
1426
- if (!can) {
1427
- if (auditLog) {
1428
- logger.info(`[PermissionGuard] Permission denied:`, {
1429
- userId: effectiveUserId,
1430
- scope,
1431
- permission,
1432
- pageId,
1433
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1434
- });
1435
- }
1436
- if (strictMode) {
1437
- logger.error(`[PermissionGuard] STRICT MODE VIOLATION: User attempted to access protected resource without permission`, {
1438
- userId: effectiveUserId,
1439
- scope,
1440
- permission,
1441
- pageId,
1442
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1443
- });
1444
- }
1445
- if (onDenied) {
1446
- onDenied();
1447
- }
1448
- return /* @__PURE__ */ jsx9(Fragment4, { children: fallback });
1449
- }
1450
- if (auditLog) {
1451
- logger.info(`[PermissionGuard] Permission granted:`, {
1452
- userId: effectiveUserId,
1453
- scope,
1454
- permission,
1455
- pageId,
1456
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1457
- });
1458
- }
1459
- return /* @__PURE__ */ jsx9(Fragment4, { children });
1460
- }
1461
- function AccessLevelGuard({
1462
- userId,
1463
- scope,
1464
- minLevel,
1465
- children,
1466
- fallback = null,
1467
- loading = null
1468
- }) {
1469
- const logger = getRBACLogger();
1470
- const authContext = useContext5(React9.createContext(null));
1471
- let effectiveUserId = userId;
1472
- if (!effectiveUserId) {
1473
- try {
1474
- if (authContext?.user?.id) {
1475
- effectiveUserId = authContext.user.id;
1476
- } else {
1477
- const globalUser = window.__PACE_USER__;
1478
- if (globalUser?.id) {
1479
- effectiveUserId = globalUser.id;
1480
- }
1481
- }
1482
- } catch (error2) {
1483
- logger.debug("Could not infer userId from context:", error2);
1484
- }
1485
- }
1486
- const { accessLevel, isLoading, error } = useAccessLevel(effectiveUserId || "", scope);
1487
- if (!effectiveUserId) {
1488
- logger.error("AccessLevelGuard: No userId provided and could not infer from context");
1489
- return /* @__PURE__ */ jsxs6("div", { className: "rbac-error", role: "alert", children: [
1490
- /* @__PURE__ */ jsx9("p", { children: "Access level check failed: User context not available" }),
1491
- /* @__PURE__ */ jsxs6("details", { children: [
1492
- /* @__PURE__ */ jsx9("summary", { children: "Debug info" }),
1493
- /* @__PURE__ */ jsx9("p", { children: "Make sure to either:" }),
1494
- /* @__PURE__ */ jsxs6("ul", { children: [
1495
- /* @__PURE__ */ jsx9("li", { children: "Pass userId prop explicitly" }),
1496
- /* @__PURE__ */ jsx9("li", { children: "Wrap your app with an auth provider" }),
1497
- /* @__PURE__ */ jsx9("li", { children: "Set window.__PACE_USER__ with user data" })
1498
- ] })
1499
- ] })
1500
- ] });
1501
- }
1502
- if (isLoading) {
1503
- return loading || /* @__PURE__ */ jsx9("div", { className: "rbac-loading", role: "status", "aria-live": "polite", children: /* @__PURE__ */ jsx9("span", { className: "sr-only", children: "Checking access level..." }) });
1504
- }
1505
- if (error) {
1506
- logger.error("Access level check failed:", error);
1507
- return fallback;
1508
- }
1509
- const levelHierarchy = ["viewer", "participant", "planner", "admin", "super"];
1510
- const userLevelIndex = accessLevel ? levelHierarchy.indexOf(accessLevel) : -1;
1511
- const requiredLevelIndex = levelHierarchy.indexOf(minLevel);
1512
- if (userLevelIndex < requiredLevelIndex) {
1513
- return /* @__PURE__ */ jsx9(Fragment4, { children: fallback });
1514
- }
1515
- return /* @__PURE__ */ jsx9(Fragment4, { children });
1516
- }
1517
- function withPermissionGuard(config, handler) {
1518
- return async (...args) => {
1519
- const [req] = args;
1520
- const userId = req.user?.id;
1521
- const organisationId = req.organisationId;
1522
- const eventId = req.eventId;
1523
- const appId = req.appId;
1524
- if (!userId || !organisationId) {
1525
- throw new Error("User context required for permission check");
1526
- }
1527
- const { isPermitted: isPermitted2 } = await import("../api-ETQ6YJ3C.js");
1528
- const hasPermission2 = await isPermitted2({
1529
- userId,
1530
- scope: { organisationId, eventId, appId },
1531
- permission: config.permission,
1532
- pageId: config.pageId
1533
- });
1534
- if (!hasPermission2) {
1535
- throw new Error(`Permission denied: ${config.permission}`);
1536
- }
1537
- return handler(...args);
1538
- };
1539
- }
1540
- function withAccessLevelGuard(minLevel, handler) {
1541
- return async (...args) => {
1542
- const [req] = args;
1543
- const userId = req.user?.id;
1544
- const organisationId = req.organisationId;
1545
- const eventId = req.eventId;
1546
- const appId = req.appId;
1547
- if (!userId || !organisationId) {
1548
- throw new Error("User context required for access level check");
1549
- }
1550
- const { getAccessLevel: getAccessLevel2 } = await import("../api-ETQ6YJ3C.js");
1551
- const accessLevel = await getAccessLevel2({
1552
- userId,
1553
- scope: { organisationId, eventId, appId }
1554
- });
1555
- const levelHierarchy = ["viewer", "participant", "planner", "admin", "super"];
1556
- const userLevelIndex = levelHierarchy.indexOf(accessLevel);
1557
- const requiredLevelIndex = levelHierarchy.indexOf(minLevel);
1558
- if (userLevelIndex < requiredLevelIndex) {
1559
- throw new Error(`Access level required: ${minLevel}, got: ${accessLevel}`);
1560
- }
1561
- return handler(...args);
1562
- };
1563
- }
1564
- function withRoleGuard(config, handler) {
1565
- return async (...args) => {
1566
- const [req] = args;
1567
- const userId = req.user?.id;
1568
- const organisationId = req.organisationId;
1569
- const eventId = req.eventId;
1570
- const appId = req.appId;
1571
- if (!userId || !organisationId) {
1572
- throw new Error("User context required for role check");
1573
- }
1574
- if (config.globalRoles && config.globalRoles.length > 0) {
1575
- const { isSuperAdmin } = await import("../api-ETQ6YJ3C.js");
1576
- const isSuper = await isSuperAdmin(userId);
1577
- if (isSuper) {
1578
- if (organisationId) {
1579
- const { emitAuditEvent: emitAuditEvent2 } = await import("../audit-BUW3LMJB.js");
1580
- await emitAuditEvent2({
1581
- type: "permission_check",
1582
- userId,
1583
- organisationId,
1584
- eventId,
1585
- appId,
1586
- permission: "bypass:all",
1587
- decision: true,
1588
- source: "api",
1589
- bypass: true,
1590
- duration_ms: 0,
1591
- metadata: {
1592
- operation: "role_guard",
1593
- reason: "super_admin_bypass"
1594
- }
1595
- });
1596
- }
1597
- return handler(...args);
1598
- }
1599
- }
1600
- if (config.organisationRoles && config.organisationRoles.length > 0) {
1601
- const { isOrganisationAdmin } = await import("../api-ETQ6YJ3C.js");
1602
- const isOrgAdmin = await isOrganisationAdmin(userId, organisationId);
1603
- if (!isOrgAdmin && config.requireAll !== false) {
1604
- throw new Error(`Organisation admin role required`);
1605
- }
1606
- }
1607
- if (config.eventAppRoles && config.eventAppRoles.length > 0 && eventId && appId) {
1608
- const { isEventAdmin } = await import("../api-ETQ6YJ3C.js");
1609
- const isEventAdminUser = await isEventAdmin(userId, { organisationId, eventId, appId });
1610
- if (!isEventAdminUser && config.requireAll !== false) {
1611
- throw new Error(`Event admin role required`);
1612
- }
1613
- }
1614
- if (organisationId) {
1615
- const { emitAuditEvent: emitAuditEvent2 } = await import("../audit-BUW3LMJB.js");
1616
- await emitAuditEvent2({
1617
- type: "permission_check",
1618
- userId,
1619
- organisationId,
1620
- eventId,
1621
- appId,
1622
- permission: "role:check",
1623
- decision: true,
1624
- source: "api",
1625
- bypass: false,
1626
- duration_ms: 0,
1627
- metadata: {
1628
- operation: "role_guard"
1629
- }
1630
- });
1631
- }
1632
- return handler(...args);
1633
- };
1634
- }
1635
- function createRBACMiddleware(config) {
1636
- return async (req, res, next) => {
1637
- const { pathname } = req.nextUrl;
1638
- const userId = req.user?.id;
1639
- const organisationId = req.organisationId;
1640
- if (!userId || !organisationId) {
1641
- return res.redirect(config.fallbackUrl || "/login");
1642
- }
1643
- const protectedRoute = config.protectedRoutes.find(
1644
- (route) => pathname.startsWith(route.path)
1645
- );
1646
- if (protectedRoute) {
1647
- try {
1648
- const { isPermitted: isPermitted2 } = await import("../api-ETQ6YJ3C.js");
1649
- const hasPermission2 = await isPermitted2({
1650
- userId,
1651
- scope: { organisationId },
1652
- permission: protectedRoute.permission,
1653
- pageId: protectedRoute.pageId
1654
- });
1655
- if (!hasPermission2) {
1656
- return res.redirect(config.fallbackUrl || "/access-denied");
1657
- }
1658
- } catch (_error) {
1659
- return res.redirect(config.fallbackUrl || "/access-denied");
1660
- }
1661
- }
1662
- next();
1663
- };
1664
- }
1665
- function createRBACExpressMiddleware(config) {
1666
- return async (req, res, next) => {
1667
- const userId = req.user?.id;
1668
- const organisationId = req.organisationId;
1669
- const eventId = req.eventId;
1670
- const appId = req.appId;
1671
- if (!userId || !organisationId) {
1672
- return res.status(401).json({ error: "User context required" });
1673
- }
1674
- try {
1675
- const { isPermitted: isPermitted2 } = await import("../api-ETQ6YJ3C.js");
1676
- const hasPermission2 = await isPermitted2({
1677
- userId,
1678
- scope: { organisationId, eventId, appId },
1679
- permission: config.permission,
1680
- pageId: config.pageId
1681
- });
1682
- if (!hasPermission2) {
1683
- return res.status(403).json({ error: "Permission denied" });
1684
- }
1685
- next();
1686
- } catch (_error) {
1687
- return res.status(500).json({ error: "Permission check failed" });
1688
- }
1689
- };
1690
- }
1691
- function hasPermissionCached(userId, scope, _permission, _pageId) {
1692
- const cacheKey = RBACCache.generatePermissionKey({
1693
- userId,
1694
- organisationId: scope.organisationId,
1695
- eventId: scope.eventId,
1696
- appId: scope.appId
1697
- });
1698
- return rbacCache.get(cacheKey) || false;
1699
- }
1700
- function hasAnyPermissionCached(userId, scope, permissions, pageId) {
1701
- return permissions.some(
1702
- (permission) => hasPermissionCached(userId, scope, permission, pageId)
1703
- );
1704
- }
1705
-
1706
- // src/rbac/permissions.ts
1707
- var GLOBAL_PERMISSIONS = {
1708
- MANAGE_ALL: "manage:*",
1709
- READ_ALL: "read:*",
1710
- CREATE_ALL: "create:*",
1711
- UPDATE_ALL: "update:*",
1712
- DELETE_ALL: "delete:*"
1713
- };
1714
- var ORGANISATION_PERMISSIONS = {
1715
- // Organisation management
1716
- MANAGE_ORGANISATION: "manage:organisation",
1717
- READ_ORGANISATION: "read:organisation",
1718
- UPDATE_ORGANISATION: "update:organisation",
1719
- // User management
1720
- MANAGE_USERS: "manage:users",
1721
- READ_USERS: "read:users",
1722
- CREATE_USERS: "create:users",
1723
- UPDATE_USERS: "update:users",
1724
- DELETE_USERS: "delete:users",
1725
- // Role management
1726
- MANAGE_ROLES: "manage:roles",
1727
- READ_ROLES: "read:roles",
1728
- CREATE_ROLES: "create:roles",
1729
- UPDATE_ROLES: "update:roles",
1730
- DELETE_ROLES: "delete:roles",
1731
- // Event management
1732
- MANAGE_EVENTS: "manage:events",
1733
- READ_EVENTS: "read:events",
1734
- CREATE_EVENTS: "create:events",
1735
- UPDATE_EVENTS: "update:events",
1736
- DELETE_EVENTS: "delete:events",
1737
- // App management
1738
- MANAGE_APPS: "manage:apps",
1739
- READ_APPS: "read:apps",
1740
- CREATE_APPS: "create:apps",
1741
- UPDATE_APPS: "update:apps",
1742
- DELETE_APPS: "delete:apps"
1743
- };
1744
- var EVENT_APP_PERMISSIONS = {
1745
- // Event management
1746
- MANAGE_EVENT: "manage:event",
1747
- READ_EVENT: "read:event",
1748
- UPDATE_EVENT: "update:event",
1749
- // App management
1750
- MANAGE_APP: "manage:app",
1751
- READ_APP: "read:app",
1752
- UPDATE_APP: "update:app",
1753
- // Team management
1754
- MANAGE_TEAM: "manage:team",
1755
- READ_TEAM: "read:team",
1756
- CREATE_TEAM: "create:team",
1757
- UPDATE_TEAM: "update:team",
1758
- DELETE_TEAM: "delete:team",
1759
- // Team members
1760
- MANAGE_TEAM_MEMBERS: "manage:team.members",
1761
- READ_TEAM_MEMBERS: "read:team.members",
1762
- CREATE_TEAM_MEMBERS: "create:team.members",
1763
- UPDATE_TEAM_MEMBERS: "update:team.members",
1764
- DELETE_TEAM_MEMBERS: "delete:team.members",
1765
- // Event content
1766
- MANAGE_EVENT_CONTENT: "manage:event.content",
1767
- READ_EVENT_CONTENT: "read:event.content",
1768
- CREATE_EVENT_CONTENT: "create:event.content",
1769
- UPDATE_EVENT_CONTENT: "update:event.content",
1770
- DELETE_EVENT_CONTENT: "delete:event.content",
1771
- // Event settings
1772
- MANAGE_EVENT_SETTINGS: "manage:event.settings",
1773
- READ_EVENT_SETTINGS: "read:event.settings",
1774
- UPDATE_EVENT_SETTINGS: "update:event.settings"
1775
- };
1776
- var PAGE_PERMISSIONS = {
1777
- // General page access
1778
- READ_PAGE: "read:page",
1779
- MANAGE_PAGE: "manage:page",
1780
- // Admin pages
1781
- READ_ADMIN: "read:admin",
1782
- MANAGE_ADMIN: "manage:admin",
1783
- // Dashboard pages
1784
- READ_DASHBOARD: "read:dashboard",
1785
- MANAGE_DASHBOARD: "manage:dashboard",
1786
- // Settings pages
1787
- READ_SETTINGS: "read:settings",
1788
- MANAGE_SETTINGS: "manage:settings",
1789
- // Reports pages
1790
- READ_REPORTS: "read:reports",
1791
- MANAGE_REPORTS: "manage:reports"
1792
- };
1793
- var PERMISSION_GROUPS = {
1794
- // Global admin permissions
1795
- GLOBAL_ADMIN: [
1796
- GLOBAL_PERMISSIONS.MANAGE_ALL,
1797
- GLOBAL_PERMISSIONS.READ_ALL,
1798
- GLOBAL_PERMISSIONS.CREATE_ALL,
1799
- GLOBAL_PERMISSIONS.UPDATE_ALL,
1800
- GLOBAL_PERMISSIONS.DELETE_ALL
1801
- ],
1802
- // Organisation admin permissions
1803
- ORG_ADMIN: [
1804
- ORGANISATION_PERMISSIONS.MANAGE_ORGANISATION,
1805
- ORGANISATION_PERMISSIONS.READ_ORGANISATION,
1806
- ORGANISATION_PERMISSIONS.UPDATE_ORGANISATION,
1807
- ORGANISATION_PERMISSIONS.MANAGE_USERS,
1808
- ORGANISATION_PERMISSIONS.READ_USERS,
1809
- ORGANISATION_PERMISSIONS.CREATE_USERS,
1810
- ORGANISATION_PERMISSIONS.UPDATE_USERS,
1811
- ORGANISATION_PERMISSIONS.DELETE_USERS,
1812
- ORGANISATION_PERMISSIONS.MANAGE_ROLES,
1813
- ORGANISATION_PERMISSIONS.READ_ROLES,
1814
- ORGANISATION_PERMISSIONS.CREATE_ROLES,
1815
- ORGANISATION_PERMISSIONS.UPDATE_ROLES,
1816
- ORGANISATION_PERMISSIONS.DELETE_ROLES,
1817
- ORGANISATION_PERMISSIONS.MANAGE_EVENTS,
1818
- ORGANISATION_PERMISSIONS.READ_EVENTS,
1819
- ORGANISATION_PERMISSIONS.CREATE_EVENTS,
1820
- ORGANISATION_PERMISSIONS.UPDATE_EVENTS,
1821
- ORGANISATION_PERMISSIONS.DELETE_EVENTS,
1822
- ORGANISATION_PERMISSIONS.MANAGE_APPS,
1823
- ORGANISATION_PERMISSIONS.READ_APPS,
1824
- ORGANISATION_PERMISSIONS.CREATE_APPS,
1825
- ORGANISATION_PERMISSIONS.UPDATE_APPS,
1826
- ORGANISATION_PERMISSIONS.DELETE_APPS
1827
- ],
1828
- // Event admin permissions
1829
- EVENT_ADMIN: [
1830
- EVENT_APP_PERMISSIONS.MANAGE_EVENT,
1831
- EVENT_APP_PERMISSIONS.READ_EVENT,
1832
- EVENT_APP_PERMISSIONS.UPDATE_EVENT,
1833
- EVENT_APP_PERMISSIONS.MANAGE_APP,
1834
- EVENT_APP_PERMISSIONS.READ_APP,
1835
- EVENT_APP_PERMISSIONS.UPDATE_APP,
1836
- EVENT_APP_PERMISSIONS.MANAGE_TEAM,
1837
- EVENT_APP_PERMISSIONS.READ_TEAM,
1838
- EVENT_APP_PERMISSIONS.CREATE_TEAM,
1839
- EVENT_APP_PERMISSIONS.UPDATE_TEAM,
1840
- EVENT_APP_PERMISSIONS.DELETE_TEAM,
1841
- EVENT_APP_PERMISSIONS.MANAGE_TEAM_MEMBERS,
1842
- EVENT_APP_PERMISSIONS.READ_TEAM_MEMBERS,
1843
- EVENT_APP_PERMISSIONS.CREATE_TEAM_MEMBERS,
1844
- EVENT_APP_PERMISSIONS.UPDATE_TEAM_MEMBERS,
1845
- EVENT_APP_PERMISSIONS.DELETE_TEAM_MEMBERS,
1846
- EVENT_APP_PERMISSIONS.MANAGE_EVENT_CONTENT,
1847
- EVENT_APP_PERMISSIONS.READ_EVENT_CONTENT,
1848
- EVENT_APP_PERMISSIONS.CREATE_EVENT_CONTENT,
1849
- EVENT_APP_PERMISSIONS.UPDATE_EVENT_CONTENT,
1850
- EVENT_APP_PERMISSIONS.DELETE_EVENT_CONTENT,
1851
- EVENT_APP_PERMISSIONS.MANAGE_EVENT_SETTINGS,
1852
- EVENT_APP_PERMISSIONS.READ_EVENT_SETTINGS,
1853
- EVENT_APP_PERMISSIONS.UPDATE_EVENT_SETTINGS
1854
- ],
1855
- // Planner permissions
1856
- PLANNER: [
1857
- EVENT_APP_PERMISSIONS.READ_EVENT,
1858
- EVENT_APP_PERMISSIONS.UPDATE_EVENT,
1859
- EVENT_APP_PERMISSIONS.READ_APP,
1860
- EVENT_APP_PERMISSIONS.UPDATE_APP,
1861
- EVENT_APP_PERMISSIONS.READ_TEAM,
1862
- EVENT_APP_PERMISSIONS.CREATE_TEAM,
1863
- EVENT_APP_PERMISSIONS.UPDATE_TEAM,
1864
- EVENT_APP_PERMISSIONS.READ_TEAM_MEMBERS,
1865
- EVENT_APP_PERMISSIONS.CREATE_TEAM_MEMBERS,
1866
- EVENT_APP_PERMISSIONS.UPDATE_TEAM_MEMBERS,
1867
- EVENT_APP_PERMISSIONS.READ_EVENT_CONTENT,
1868
- EVENT_APP_PERMISSIONS.CREATE_EVENT_CONTENT,
1869
- EVENT_APP_PERMISSIONS.UPDATE_EVENT_CONTENT,
1870
- EVENT_APP_PERMISSIONS.READ_EVENT_SETTINGS,
1871
- EVENT_APP_PERMISSIONS.UPDATE_EVENT_SETTINGS
1872
- ],
1873
- // Participant permissions
1874
- PARTICIPANT: [
1875
- EVENT_APP_PERMISSIONS.READ_EVENT,
1876
- EVENT_APP_PERMISSIONS.READ_APP,
1877
- EVENT_APP_PERMISSIONS.READ_TEAM,
1878
- EVENT_APP_PERMISSIONS.READ_TEAM_MEMBERS,
1879
- EVENT_APP_PERMISSIONS.READ_EVENT_CONTENT,
1880
- EVENT_APP_PERMISSIONS.READ_EVENT_SETTINGS
1881
- ],
1882
- // Viewer permissions
1883
- VIEWER: [
1884
- EVENT_APP_PERMISSIONS.READ_EVENT,
1885
- EVENT_APP_PERMISSIONS.READ_APP,
1886
- EVENT_APP_PERMISSIONS.READ_TEAM,
1887
- EVENT_APP_PERMISSIONS.READ_EVENT_CONTENT
1888
- ]
1889
- };
1890
- function isValidPermission(permission) {
1891
- const pattern = /^(read|create|update|delete|manage):[a-z0-9._-]+$|^(read|create|update|delete|manage):\*$/;
1892
- return pattern.test(permission);
1893
- }
1894
- function getPermissionsForRole(role) {
1895
- switch (role) {
1896
- case "super_admin":
1897
- return [...PERMISSION_GROUPS.GLOBAL_ADMIN];
1898
- case "org_admin":
1899
- return [...PERMISSION_GROUPS.ORG_ADMIN];
1900
- case "event_admin":
1901
- return [...PERMISSION_GROUPS.EVENT_ADMIN];
1902
- case "planner":
1903
- return [...PERMISSION_GROUPS.PLANNER];
1904
- case "participant":
1905
- return [...PERMISSION_GROUPS.PARTICIPANT];
1906
- case "viewer":
1907
- return [...PERMISSION_GROUPS.VIEWER];
1908
- default:
1909
- return [];
1910
- }
1911
- }
1912
- var ALL_PERMISSIONS = {
1913
- ...GLOBAL_PERMISSIONS,
1914
- ...ORGANISATION_PERMISSIONS,
1915
- ...EVENT_APP_PERMISSIONS,
1916
- ...PAGE_PERMISSIONS
1917
- };
1918
82
  export {
1919
83
  ALL_PERMISSIONS,
1920
84
  AccessLevelGuard,
@@ -1934,6 +98,7 @@ export {
1934
98
  RBACAuditManager,
1935
99
  RBACCache,
1936
100
  RBACEngine,
101
+ RBACProvider,
1937
102
  RoleBasedRouter,
1938
103
  SecureDataProvider,
1939
104
  SecureSupabaseClient,
@@ -1973,6 +138,8 @@ export {
1973
138
  useNavigationPermissions,
1974
139
  usePagePermissions,
1975
140
  usePermissions,
141
+ useRBAC2 as useRBAC,
142
+ useRBAC as useRBACProvider,
1976
143
  useRoleBasedRouter,
1977
144
  useSecureData,
1978
145
  withAccessLevelGuard,