@jmruthers/pace-core 0.6.5 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (473) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.md +5 -403
  3. package/audit-tool/00-dependencies.cjs +394 -0
  4. package/audit-tool/audits/01-pace-core-compliance.cjs +556 -0
  5. package/audit-tool/audits/02-project-structure.cjs +255 -0
  6. package/audit-tool/audits/03-architecture.cjs +196 -0
  7. package/audit-tool/audits/04-code-quality.cjs +149 -0
  8. package/audit-tool/audits/05-styling.cjs +224 -0
  9. package/audit-tool/audits/06-security-rbac.cjs +544 -0
  10. package/audit-tool/audits/07-api-tech-stack.cjs +301 -0
  11. package/audit-tool/audits/08-testing-documentation.cjs +202 -0
  12. package/audit-tool/audits/09-operations.cjs +208 -0
  13. package/audit-tool/index.cjs +291 -0
  14. package/audit-tool/utils/code-utils.cjs +218 -0
  15. package/audit-tool/utils/file-utils.cjs +230 -0
  16. package/audit-tool/utils/report-utils.cjs +241 -0
  17. package/core-usage-manifest.json +93 -0
  18. package/cursor-rules/00-standards-overview.mdc +156 -0
  19. package/cursor-rules/01-pace-core-compliance.mdc +586 -0
  20. package/cursor-rules/02-project-structure.mdc +42 -4
  21. package/cursor-rules/{03-solid-principles.mdc → 03-architecture.mdc} +126 -10
  22. package/cursor-rules/04-code-quality.mdc +419 -0
  23. package/cursor-rules/{08-markup-quality.mdc → 05-styling.mdc} +104 -34
  24. package/cursor-rules/06-security-rbac.mdc +518 -0
  25. package/cursor-rules/07-api-tech-stack.mdc +377 -0
  26. package/cursor-rules/08-testing-documentation.mdc +324 -0
  27. package/cursor-rules/09-operations.mdc +365 -0
  28. package/dist/{AuthService-Cb34EQs3.d.ts → AuthService-DmfO5rGS.d.ts} +10 -0
  29. package/dist/DataTable-7PMH7XN7.js +15 -0
  30. package/dist/{DataTable-BMRU8a1j.d.ts → DataTable-DRUIgtUH.d.ts} +1 -1
  31. package/dist/{PublicPageProvider-QTFVrL-Z.d.ts → PublicPageProvider-DlsCaR5v.d.ts} +33 -72
  32. package/dist/UnifiedAuthProvider-ZT6TIGM7.js +7 -0
  33. package/dist/api-Y4MQWOFW.js +4 -0
  34. package/dist/audit-MYQXYZFU.js +3 -0
  35. package/dist/{chunk-DGUM43GV.js → chunk-3RG5ZIWI.js} +1 -4
  36. package/dist/{chunk-QXHPKYJV.js → chunk-4SXLQIZO.js} +1 -26
  37. package/dist/{chunk-UPPMRMYG.js → chunk-5X4QLXRG.js} +73 -151
  38. package/dist/chunk-6F3IILHI.js +62 -0
  39. package/dist/{chunk-E66EQZE6.js → chunk-6GLLNA6U.js} +3 -9
  40. package/dist/{chunk-ZSAAAMVR.js → chunk-6QYDGKQY.js} +1 -4
  41. package/dist/{chunk-FMUCXFII.js → chunk-7ILTDCL2.js} +9 -5
  42. package/dist/{chunk-M43Y4SSO.js → chunk-A3W6LW53.js} +15 -13
  43. package/dist/{chunk-63FOKYGO.js → chunk-AHU7G2R5.js} +2 -11
  44. package/dist/{chunk-HU2C6SSC.js → chunk-BM4CQ5P3.js} +606 -559
  45. package/dist/chunk-C7NSAPTL.js +1 -0
  46. package/dist/{chunk-J36DSWQK.js → chunk-FEJLJNWA.js} +7 -41
  47. package/dist/{chunk-IHB5DR3H.js → chunk-FTCRZOG2.js} +188 -387
  48. package/dist/{chunk-G37KK66H.js → chunk-FYHN4DD5.js} +60 -19
  49. package/dist/chunk-GHYHJTYV.js +994 -0
  50. package/dist/{chunk-VBXEHIUJ.js → chunk-HF6O3O37.js} +6 -88
  51. package/dist/{chunk-FFQEQTNW.js → chunk-IUBRCBSY.js} +134 -45
  52. package/dist/{chunk-6COVEUS7.js → chunk-JGWDVX64.js} +983 -1034
  53. package/dist/{chunk-RGAWHO7N.js → chunk-L4XMVJKY.js} +77 -222
  54. package/dist/chunk-MBADTM7L.js +64 -0
  55. package/dist/{chunk-M7MPQISP.js → chunk-OJ4SKRSV.js} +3 -16
  56. package/dist/{chunk-IVOFDYWT.js → chunk-Q7Q7V5NV.js} +2109 -1604
  57. package/dist/{chunk-JGRYX5UX.js → chunk-S7DKJPLT.js} +29 -58
  58. package/dist/{chunk-PWLANIRT.js → chunk-TTRFSOKR.js} +1 -7
  59. package/dist/{chunk-5DRSZLL2.js → chunk-UH3NTO3F.js} +1 -6
  60. package/dist/{chunk-NTM7ZSB6.js → chunk-VBCS3DUA.js} +261 -168
  61. package/dist/{chunk-EFN2EIMK.js → chunk-ZFYPMX46.js} +271 -87
  62. package/dist/{chunk-L4OXEN46.js → chunk-ZKAWKYT4.js} +10 -24
  63. package/dist/components.d.ts +7 -5
  64. package/dist/components.js +46 -257
  65. package/dist/{database.generated-CzIvgcPu.d.ts → database.generated-CcnC_DRc.d.ts} +4795 -3691
  66. package/dist/eslint-rules/index.cjs +35 -0
  67. package/{src/eslint-rules/pace-core-compliance.cjs → dist/eslint-rules/rules/01-pace-core-compliance.cjs} +234 -235
  68. package/dist/eslint-rules/rules/04-code-quality.cjs +290 -0
  69. package/dist/eslint-rules/rules/05-styling.cjs +61 -0
  70. package/dist/eslint-rules/rules/06-security-rbac.cjs +806 -0
  71. package/dist/eslint-rules/rules/07-api-tech-stack.cjs +263 -0
  72. package/dist/eslint-rules/rules/08-testing.cjs +94 -0
  73. package/dist/eslint-rules/utils/helpers.cjs +42 -0
  74. package/dist/eslint-rules/utils/manifest-loader.cjs +75 -0
  75. package/dist/hooks.d.ts +6 -6
  76. package/dist/hooks.js +62 -172
  77. package/dist/icons/index.d.ts +1 -0
  78. package/dist/icons/index.js +1 -0
  79. package/dist/index.d.ts +12 -11
  80. package/dist/index.js +67 -660
  81. package/dist/providers.d.ts +2 -2
  82. package/dist/providers.js +8 -35
  83. package/dist/rbac/eslint-rules.d.ts +46 -44
  84. package/dist/rbac/eslint-rules.js +7 -4
  85. package/dist/rbac/index.d.ts +109 -586
  86. package/dist/rbac/index.js +14 -207
  87. package/dist/styles/index.js +2 -12
  88. package/dist/theming/runtime.d.ts +14 -1
  89. package/dist/theming/runtime.js +3 -19
  90. package/dist/{timezone-CHhWg6b4.d.ts → timezone-BZe_eUxx.d.ts} +175 -1
  91. package/dist/{types-CkbwOr4Y.d.ts → types-DXstZpNI.d.ts} +4 -17
  92. package/dist/types-t9H8qKRw.d.ts +55 -0
  93. package/dist/types.d.ts +1 -1
  94. package/dist/types.js +7 -94
  95. package/dist/{usePublicRouteParams-ClnV4tnv.d.ts → usePublicRouteParams-MamNgwqe.d.ts} +20 -20
  96. package/dist/utils.d.ts +24 -117
  97. package/dist/utils.js +54 -392
  98. package/docs/README.md +17 -7
  99. package/docs/api/README.md +4 -402
  100. package/docs/api/modules.md +301 -871
  101. package/docs/api-reference/components.md +21 -21
  102. package/docs/api-reference/deprecated.md +31 -6
  103. package/docs/api-reference/hooks.md +80 -80
  104. package/docs/api-reference/rpc-functions.md +78 -3
  105. package/docs/api-reference/types.md +1 -1
  106. package/docs/api-reference/utilities.md +1 -1
  107. package/docs/architecture/README.md +1 -1
  108. package/docs/core-concepts/events.md +3 -3
  109. package/docs/core-concepts/organisations.md +6 -6
  110. package/docs/core-concepts/permissions.md +6 -6
  111. package/docs/documentation-index.md +12 -18
  112. package/docs/getting-started/cursor-rules.md +3 -23
  113. package/docs/getting-started/dependencies.md +650 -0
  114. package/docs/getting-started/documentation-index.md +1 -1
  115. package/docs/getting-started/examples/README.md +4 -4
  116. package/docs/getting-started/examples/full-featured-app.md +1 -1
  117. package/docs/getting-started/faq.md +2 -2
  118. package/docs/getting-started/installation-guide.md +20 -7
  119. package/docs/getting-started/quick-reference.md +4 -4
  120. package/docs/getting-started/quick-start.md +23 -12
  121. package/docs/implementation-guides/authentication.md +15 -15
  122. package/docs/implementation-guides/component-styling.md +1 -1
  123. package/docs/implementation-guides/data-tables.md +126 -33
  124. package/docs/implementation-guides/datatable-rbac-usage.md +1 -1
  125. package/docs/implementation-guides/dynamic-colors.md +3 -3
  126. package/docs/implementation-guides/file-upload-storage.md +2 -2
  127. package/docs/implementation-guides/hierarchical-datatable.md +40 -60
  128. package/docs/implementation-guides/inactivity-tracking.md +3 -3
  129. package/docs/implementation-guides/large-datasets.md +3 -2
  130. package/docs/implementation-guides/organisation-security.md +2 -2
  131. package/docs/implementation-guides/performance.md +2 -2
  132. package/docs/implementation-guides/permission-enforcement.md +5 -1
  133. package/docs/migration/V0.3.44_organisation-context-timing-fix.md +1 -1
  134. package/docs/migration/V0.4.0_rbac-migration.md +6 -6
  135. package/docs/rbac/MIGRATION_GUIDE.md +819 -0
  136. package/docs/rbac/RBAC_CONTRACT.md +724 -0
  137. package/docs/rbac/README.md +17 -8
  138. package/docs/rbac/advanced-patterns.md +6 -6
  139. package/docs/rbac/api-reference.md +20 -20
  140. package/docs/rbac/edge-functions-guide.md +376 -0
  141. package/docs/rbac/event-based-apps.md +3 -3
  142. package/docs/rbac/examples.md +41 -41
  143. package/docs/rbac/getting-started.md +37 -37
  144. package/docs/rbac/performance.md +1 -1
  145. package/docs/rbac/quick-start.md +52 -52
  146. package/docs/rbac/secure-client-protection.md +1 -35
  147. package/docs/rbac/troubleshooting.md +1 -1
  148. package/docs/security/README.md +5 -5
  149. package/docs/standards/0-standards-overview.md +220 -0
  150. package/docs/standards/1-pace-core-compliance-standards.md +986 -0
  151. package/docs/standards/2-project-structure-standards.md +949 -0
  152. package/docs/standards/3-architecture-standards.md +606 -0
  153. package/docs/standards/4-code-quality-standards.md +728 -0
  154. package/docs/standards/5-styling-standards.md +348 -0
  155. package/docs/standards/{07-rbac-and-rls-standard.md → 6-security-rbac-standards.md} +269 -66
  156. package/docs/standards/7-api-tech-stack-standards.md +662 -0
  157. package/docs/standards/8-testing-documentation-standards.md +401 -0
  158. package/docs/standards/9-operations-standards.md +1102 -0
  159. package/docs/standards/README.md +185 -57
  160. package/docs/troubleshooting/README.md +4 -4
  161. package/docs/troubleshooting/common-issues.md +2 -2
  162. package/docs/troubleshooting/debugging.md +9 -9
  163. package/docs/troubleshooting/migration.md +4 -4
  164. package/docs/troubleshooting/organisation-context-setup.md +42 -19
  165. package/eslint-config-pace-core.cjs +33 -6
  166. package/package.json +35 -23
  167. package/scripts/install-cursor-rules.cjs +25 -6
  168. package/scripts/install-eslint-config.cjs +284 -0
  169. package/src/__tests__/fixtures/supabase.ts +1 -1
  170. package/src/__tests__/helpers/__tests__/component-test-utils.test.tsx +3 -3
  171. package/src/__tests__/helpers/__tests__/optimized-test-setup.test.ts +1 -1
  172. package/src/__tests__/helpers/__tests__/supabaseMock.test.ts +1 -1
  173. package/src/__tests__/helpers/__tests__/test-providers.test.tsx +2 -2
  174. package/src/__tests__/helpers/__tests__/test-utils.test.tsx +13 -13
  175. package/src/__tests__/helpers/component-test-utils.tsx +1 -1
  176. package/src/__tests__/helpers/supabaseMock.ts +2 -2
  177. package/src/__tests__/integration/UserProfile.test.tsx +14 -14
  178. package/src/__tests__/public-recipe-view.test.ts +38 -9
  179. package/src/__tests__/rbac/PagePermissionGuard.test.tsx +6 -6
  180. package/src/__tests__/templates/accessibility.test.template.tsx +9 -9
  181. package/src/__tests__/templates/component.test.template.tsx +18 -15
  182. package/src/components/Button/Button.tsx +5 -1
  183. package/src/components/Calendar/Calendar.tsx +201 -47
  184. package/src/components/ContextSelector/ContextSelector.tsx +106 -119
  185. package/src/components/DataTable/AUDIT_REPORT.md +293 -0
  186. package/src/components/DataTable/__tests__/DataTableCore.test.tsx +10 -2
  187. package/src/components/DataTable/__tests__/a11y.basic.test.tsx +10 -4
  188. package/src/components/DataTable/__tests__/test-utils/sharedTestUtils.tsx +9 -9
  189. package/src/components/DataTable/components/ColumnFilter.tsx +63 -74
  190. package/src/components/DataTable/components/ColumnVisibilityDropdown.tsx +43 -41
  191. package/src/components/DataTable/components/DataTableCore.tsx +186 -13
  192. package/src/components/DataTable/components/DataTableErrorBoundary.tsx +9 -11
  193. package/src/components/DataTable/components/DataTableLayout.tsx +35 -21
  194. package/src/components/DataTable/components/EditFields.tsx +23 -3
  195. package/src/components/DataTable/components/EditableRow.tsx +12 -9
  196. package/src/components/DataTable/components/EmptyState.tsx +10 -9
  197. package/src/components/DataTable/components/FilterRow.tsx +2 -4
  198. package/src/components/DataTable/components/ImportModal.tsx +124 -126
  199. package/src/components/DataTable/components/LoadingState.tsx +5 -6
  200. package/src/components/DataTable/components/RowComponent.tsx +12 -0
  201. package/src/components/DataTable/components/SortIndicator.tsx +50 -0
  202. package/src/components/DataTable/components/__tests__/COVERAGE_NOTE.md +4 -4
  203. package/src/components/DataTable/components/__tests__/ColumnFilter.test.tsx +23 -82
  204. package/src/components/DataTable/components/__tests__/DataTableErrorBoundary.test.tsx +37 -9
  205. package/src/components/DataTable/components/__tests__/EmptyState.test.tsx +7 -4
  206. package/src/components/DataTable/components/__tests__/FilterRow.test.tsx +12 -4
  207. package/src/components/DataTable/components/__tests__/LoadingState.test.tsx +41 -27
  208. package/src/components/DataTable/components/hooks/usePermissionTracking.ts +0 -4
  209. package/src/components/DataTable/components/index.ts +2 -1
  210. package/src/components/DataTable/hooks/__tests__/useDataTableState.test.ts +51 -47
  211. package/src/components/DataTable/hooks/useDataTablePermissions.ts +24 -21
  212. package/src/components/DataTable/hooks/useDataTableState.ts +125 -9
  213. package/src/components/DataTable/hooks/useTableColumns.ts +40 -2
  214. package/src/components/DataTable/hooks/useTableHandlers.ts +11 -0
  215. package/src/components/DataTable/types.ts +5 -18
  216. package/src/components/DataTable/utils/a11yUtils.ts +17 -0
  217. package/src/components/DatePickerWithTimezone/DatePickerWithTimezone.test.tsx +2 -1
  218. package/src/components/DatePickerWithTimezone/DatePickerWithTimezone.tsx +11 -15
  219. package/src/components/DateTimeField/DateTimeField.tsx +10 -9
  220. package/src/components/Dialog/Dialog.test.tsx +128 -104
  221. package/src/components/Dialog/Dialog.tsx +742 -24
  222. package/src/components/ErrorBoundary/ErrorBoundary.tsx +77 -79
  223. package/src/components/FileDisplay/FileDisplay.test.tsx +4 -2
  224. package/src/components/FileDisplay/FileDisplay.tsx +23 -17
  225. package/src/components/FileUpload/FileUpload.test.tsx +52 -14
  226. package/src/components/FileUpload/FileUpload.tsx +112 -130
  227. package/src/components/Form/Form.test.tsx +6 -8
  228. package/src/components/Form/Form.tsx +365 -4
  229. package/src/components/NavigationMenu/NavigationMenu.test.tsx +14 -13
  230. package/src/components/NavigationMenu/useNavigationFiltering.ts +11 -21
  231. package/src/components/PaceAppLayout/PaceAppLayout.test.tsx +6 -4
  232. package/src/components/PaceAppLayout/PaceAppLayout.tsx +11 -15
  233. package/src/components/PaceLoginPage/PaceLoginPage.test.tsx +108 -61
  234. package/src/components/PaceLoginPage/PaceLoginPage.tsx +27 -3
  235. package/src/components/Progress/Progress.tsx +2 -4
  236. package/src/components/ProtectedRoute/ProtectedRoute.tsx +8 -8
  237. package/src/components/Select/Select.tsx +109 -98
  238. package/src/components/Select/types.ts +4 -1
  239. package/src/components/UserMenu/UserMenu.tsx +9 -6
  240. package/src/hooks/__tests__/ServiceHooks.test.tsx +16 -16
  241. package/src/hooks/__tests__/hooks.integration.test.tsx +55 -57
  242. package/src/hooks/__tests__/useAppConfig.unit.test.ts +129 -67
  243. package/src/hooks/__tests__/useFocusTrap.unit.test.tsx +97 -97
  244. package/src/hooks/__tests__/usePublicEvent.simple.test.ts +149 -67
  245. package/src/hooks/__tests__/usePublicEvent.test.ts +149 -79
  246. package/src/hooks/__tests__/usePublicEvent.unit.test.ts +158 -109
  247. package/src/hooks/__tests__/useSessionDraft.test.ts +163 -0
  248. package/src/hooks/__tests__/useSessionRestoration.unit.test.tsx +10 -5
  249. package/src/hooks/public/usePublicEvent.ts +67 -195
  250. package/src/hooks/public/usePublicEventLogo.test.ts +70 -17
  251. package/src/hooks/public/usePublicEventLogo.ts +24 -14
  252. package/src/hooks/public/usePublicFileDisplay.ts +2 -2
  253. package/src/hooks/public/usePublicRouteParams.ts +5 -5
  254. package/src/hooks/useAppConfig.ts +28 -26
  255. package/src/hooks/useEventTheme.test.ts +217 -239
  256. package/src/hooks/useEventTheme.ts +16 -28
  257. package/src/hooks/useFileDisplay.ts +2 -2
  258. package/src/hooks/useOrganisationPermissions.ts +5 -7
  259. package/src/hooks/useQueryCache.ts +0 -1
  260. package/src/hooks/useSessionDraft.ts +380 -0
  261. package/src/hooks/useSessionRestoration.ts +3 -1
  262. package/src/icons/index.ts +27 -0
  263. package/src/index.ts +5 -0
  264. package/src/providers/OrganisationProvider.tsx +23 -14
  265. package/src/providers/UnifiedAuthProvider.smoke.test.tsx +21 -21
  266. package/src/providers/__tests__/AuthProvider.test.tsx +21 -21
  267. package/src/providers/__tests__/EventProvider.test.tsx +61 -61
  268. package/src/providers/__tests__/InactivityProvider.test.tsx +56 -56
  269. package/src/providers/__tests__/OrganisationProvider.test.tsx +75 -75
  270. package/src/providers/__tests__/ProviderLifecycle.test.tsx +37 -37
  271. package/src/providers/__tests__/UnifiedAuthProvider.test.tsx +103 -103
  272. package/src/providers/services/EventServiceProvider.tsx +1 -24
  273. package/src/providers/services/UnifiedAuthProvider.tsx +5 -48
  274. package/src/providers/services/__tests__/AuthServiceProvider.integration.test.tsx +7 -7
  275. package/src/providers/services/__tests__/UnifiedAuthProvider.integration.test.tsx +13 -10
  276. package/src/rbac/__tests__/adapters.comprehensive.test.tsx +7 -457
  277. package/src/rbac/__tests__/auth-rbac.e2e.test.tsx +33 -7
  278. package/src/rbac/adapters.tsx +7 -295
  279. package/src/rbac/api.test.ts +44 -56
  280. package/src/rbac/api.ts +10 -17
  281. package/src/rbac/cache-invalidation.ts +0 -1
  282. package/src/rbac/compliance/index.ts +10 -0
  283. package/src/rbac/compliance/pattern-detector.ts +553 -0
  284. package/src/rbac/compliance/runtime-compliance.ts +22 -0
  285. package/src/rbac/components/AccessDenied.tsx +150 -0
  286. package/src/rbac/components/NavigationGuard.tsx +12 -20
  287. package/src/rbac/components/PagePermissionGuard.tsx +4 -24
  288. package/src/rbac/components/__tests__/NavigationGuard.test.tsx +21 -8
  289. package/src/rbac/components/index.ts +3 -41
  290. package/src/rbac/eslint-rules.js +1 -1
  291. package/src/rbac/hooks/index.ts +0 -3
  292. package/src/rbac/hooks/permissions/index.ts +0 -3
  293. package/src/rbac/hooks/permissions/useAccessLevel.ts +4 -8
  294. package/src/rbac/hooks/usePermissions.ts +0 -3
  295. package/src/rbac/hooks/useResolvedScope.test.ts +57 -47
  296. package/src/rbac/hooks/useResolvedScope.ts +58 -140
  297. package/src/rbac/hooks/useResourcePermissions.test.ts +124 -38
  298. package/src/rbac/hooks/useResourcePermissions.ts +139 -48
  299. package/src/rbac/hooks/useRoleManagement.test.ts +65 -22
  300. package/src/rbac/hooks/useRoleManagement.ts +147 -19
  301. package/src/rbac/hooks/useSecureSupabase.ts +4 -8
  302. package/src/rbac/index.ts +7 -9
  303. package/src/rbac/utils/contextValidator.ts +9 -7
  304. package/src/services/AuthService.ts +130 -18
  305. package/src/services/EventService.ts +4 -97
  306. package/src/services/InactivityService.ts +16 -0
  307. package/src/services/OrganisationService.ts +7 -44
  308. package/src/services/__tests__/OrganisationService.test.ts +26 -8
  309. package/src/services/base/BaseService.ts +0 -3
  310. package/src/styles/core.css +7 -0
  311. package/src/theming/__tests__/parseEventColours.test.ts +9 -3
  312. package/src/theming/parseEventColours.ts +22 -10
  313. package/src/types/database.generated.ts +4733 -3809
  314. package/src/utils/__tests__/lazyLoad.unit.test.tsx +42 -39
  315. package/src/utils/__tests__/organisationContext.unit.test.ts +9 -10
  316. package/src/utils/context/organisationContext.test.ts +13 -28
  317. package/src/utils/context/organisationContext.ts +21 -52
  318. package/src/utils/dynamic/dynamicUtils.ts +1 -1
  319. package/src/utils/file-reference/index.ts +39 -15
  320. package/src/utils/formatting/formatDateTime.test.ts +3 -2
  321. package/src/utils/google-places/loadGoogleMapsScript.ts +29 -4
  322. package/src/utils/index.ts +4 -1
  323. package/src/utils/persistence/__tests__/keyDerivation.test.ts +135 -0
  324. package/src/utils/persistence/__tests__/sensitiveFieldDetection.test.ts +123 -0
  325. package/src/utils/persistence/keyDerivation.ts +304 -0
  326. package/src/utils/persistence/sensitiveFieldDetection.ts +212 -0
  327. package/src/utils/security/secureStorage.ts +5 -5
  328. package/src/utils/storage/README.md +1 -1
  329. package/src/utils/storage/helpers.ts +3 -3
  330. package/src/utils/supabase/createBaseClient.ts +147 -0
  331. package/src/utils/timezone/timezone.test.ts +1 -2
  332. package/src/utils/timezone/timezone.ts +1 -1
  333. package/src/utils/validation/csrf.ts +4 -4
  334. package/cursor-rules/00-pace-core-compliance.mdc +0 -331
  335. package/cursor-rules/01-standards-compliance.mdc +0 -244
  336. package/cursor-rules/04-testing-standards.mdc +0 -268
  337. package/cursor-rules/05-bug-reports-and-features.mdc +0 -246
  338. package/cursor-rules/06-code-quality.mdc +0 -309
  339. package/cursor-rules/07-tech-stack-compliance.mdc +0 -214
  340. package/cursor-rules/CHANGELOG.md +0 -119
  341. package/cursor-rules/README.md +0 -192
  342. package/dist/DataTable-AOVNCPTX.js +0 -175
  343. package/dist/DataTable-AOVNCPTX.js.map +0 -1
  344. package/dist/UnifiedAuthProvider-4SBX4LU5.js +0 -18
  345. package/dist/UnifiedAuthProvider-4SBX4LU5.js.map +0 -1
  346. package/dist/api-O6HTBX5Y.js +0 -52
  347. package/dist/api-O6HTBX5Y.js.map +0 -1
  348. package/dist/audit-V53FV5AG.js +0 -17
  349. package/dist/audit-V53FV5AG.js.map +0 -1
  350. package/dist/chunk-5DRSZLL2.js.map +0 -1
  351. package/dist/chunk-63FOKYGO.js.map +0 -1
  352. package/dist/chunk-6COVEUS7.js.map +0 -1
  353. package/dist/chunk-AFVQODI2.js +0 -263
  354. package/dist/chunk-AFVQODI2.js.map +0 -1
  355. package/dist/chunk-DGUM43GV.js.map +0 -1
  356. package/dist/chunk-E66EQZE6.js.map +0 -1
  357. package/dist/chunk-EFN2EIMK.js.map +0 -1
  358. package/dist/chunk-FFQEQTNW.js.map +0 -1
  359. package/dist/chunk-FMUCXFII.js.map +0 -1
  360. package/dist/chunk-G37KK66H.js.map +0 -1
  361. package/dist/chunk-G7QEZTYQ.js +0 -2053
  362. package/dist/chunk-G7QEZTYQ.js.map +0 -1
  363. package/dist/chunk-HU2C6SSC.js.map +0 -1
  364. package/dist/chunk-IHB5DR3H.js.map +0 -1
  365. package/dist/chunk-IVOFDYWT.js.map +0 -1
  366. package/dist/chunk-J36DSWQK.js.map +0 -1
  367. package/dist/chunk-JGRYX5UX.js.map +0 -1
  368. package/dist/chunk-KQCRWDSA.js +0 -1
  369. package/dist/chunk-KQCRWDSA.js.map +0 -1
  370. package/dist/chunk-L4OXEN46.js.map +0 -1
  371. package/dist/chunk-LMC26NLJ.js +0 -84
  372. package/dist/chunk-LMC26NLJ.js.map +0 -1
  373. package/dist/chunk-M43Y4SSO.js.map +0 -1
  374. package/dist/chunk-M7MPQISP.js.map +0 -1
  375. package/dist/chunk-NTM7ZSB6.js.map +0 -1
  376. package/dist/chunk-PWLANIRT.js.map +0 -1
  377. package/dist/chunk-QXHPKYJV.js.map +0 -1
  378. package/dist/chunk-RGAWHO7N.js.map +0 -1
  379. package/dist/chunk-UPPMRMYG.js.map +0 -1
  380. package/dist/chunk-VBXEHIUJ.js.map +0 -1
  381. package/dist/chunk-ZSAAAMVR.js.map +0 -1
  382. package/dist/components.js.map +0 -1
  383. package/dist/contextValidator-5OGXSPKS.js +0 -9
  384. package/dist/contextValidator-5OGXSPKS.js.map +0 -1
  385. package/dist/eslint-rules/pace-core-compliance.cjs +0 -510
  386. package/dist/hooks.js.map +0 -1
  387. package/dist/index.js.map +0 -1
  388. package/dist/providers.js.map +0 -1
  389. package/dist/rbac/eslint-rules.js.map +0 -1
  390. package/dist/rbac/index.js.map +0 -1
  391. package/dist/styles/index.js.map +0 -1
  392. package/dist/theming/runtime.js.map +0 -1
  393. package/dist/types.js.map +0 -1
  394. package/dist/utils.js.map +0 -1
  395. package/docs/best-practices/README.md +0 -472
  396. package/docs/best-practices/accessibility.md +0 -601
  397. package/docs/best-practices/common-patterns.md +0 -516
  398. package/docs/best-practices/deployment.md +0 -1103
  399. package/docs/best-practices/performance.md +0 -1328
  400. package/docs/best-practices/security.md +0 -940
  401. package/docs/best-practices/testing.md +0 -1034
  402. package/docs/rbac/compliance/compliance-guide.md +0 -544
  403. package/docs/standards/01-architecture-standard.md +0 -44
  404. package/docs/standards/02-api-and-rpc-standard.md +0 -39
  405. package/docs/standards/03-component-standard.md +0 -32
  406. package/docs/standards/04-code-style-standard.md +0 -32
  407. package/docs/standards/05-security-standard.md +0 -44
  408. package/docs/standards/06-testing-and-docs-standard.md +0 -29
  409. package/docs/standards/pace-core-compliance.md +0 -432
  410. package/scripts/audit/core/checks/accessibility.cjs +0 -197
  411. package/scripts/audit/core/checks/api-usage.cjs +0 -191
  412. package/scripts/audit/core/checks/bundle.cjs +0 -142
  413. package/scripts/audit/core/checks/compliance.cjs +0 -2706
  414. package/scripts/audit/core/checks/config.cjs +0 -54
  415. package/scripts/audit/core/checks/coverage.cjs +0 -84
  416. package/scripts/audit/core/checks/dependencies.cjs +0 -994
  417. package/scripts/audit/core/checks/documentation.cjs +0 -268
  418. package/scripts/audit/core/checks/environment.cjs +0 -116
  419. package/scripts/audit/core/checks/error-handling.cjs +0 -340
  420. package/scripts/audit/core/checks/forms.cjs +0 -172
  421. package/scripts/audit/core/checks/heuristics.cjs +0 -68
  422. package/scripts/audit/core/checks/hooks.cjs +0 -334
  423. package/scripts/audit/core/checks/imports.cjs +0 -244
  424. package/scripts/audit/core/checks/performance.cjs +0 -325
  425. package/scripts/audit/core/checks/routes.cjs +0 -117
  426. package/scripts/audit/core/checks/state.cjs +0 -130
  427. package/scripts/audit/core/checks/structure.cjs +0 -65
  428. package/scripts/audit/core/checks/style.cjs +0 -584
  429. package/scripts/audit/core/checks/testing.cjs +0 -122
  430. package/scripts/audit/core/checks/typescript.cjs +0 -61
  431. package/scripts/audit/core/scanner.cjs +0 -199
  432. package/scripts/audit/core/utils.cjs +0 -137
  433. package/scripts/audit/index.cjs +0 -223
  434. package/scripts/audit/reporters/console.cjs +0 -151
  435. package/scripts/audit/reporters/json.cjs +0 -54
  436. package/scripts/audit/reporters/markdown.cjs +0 -124
  437. package/scripts/audit-consuming-app.cjs +0 -86
  438. package/src/components/DataTable/components/DataTableBody.tsx +0 -454
  439. package/src/components/DataTable/components/DraggableColumnHeader.tsx +0 -156
  440. package/src/components/DataTable/components/ExpandButton.tsx +0 -113
  441. package/src/components/DataTable/components/GroupHeader.tsx +0 -54
  442. package/src/components/DataTable/components/ViewRowModal.tsx +0 -68
  443. package/src/components/DataTable/components/VirtualizedDataTable.tsx +0 -525
  444. package/src/components/DataTable/components/__tests__/ExpandButton.test.tsx +0 -462
  445. package/src/components/DataTable/components/__tests__/GroupHeader.test.tsx +0 -393
  446. package/src/components/DataTable/components/__tests__/ViewRowModal.test.tsx +0 -476
  447. package/src/components/DataTable/components/__tests__/VirtualizedDataTable.test.tsx +0 -128
  448. package/src/components/DataTable/core/DataTableContext.tsx +0 -216
  449. package/src/components/DataTable/core/__tests__/DataTableContext.test.tsx +0 -136
  450. package/src/components/DataTable/hooks/__tests__/useColumnReordering.test.ts +0 -570
  451. package/src/components/DataTable/hooks/useColumnReordering.ts +0 -123
  452. package/src/components/DataTable/utils/debugTools.ts +0 -514
  453. package/src/eslint-rules/pace-core-compliance.js +0 -638
  454. package/src/rbac/components/EnhancedNavigationMenu.test.tsx +0 -555
  455. package/src/rbac/components/EnhancedNavigationMenu.tsx +0 -293
  456. package/src/rbac/components/NavigationProvider.test.tsx +0 -481
  457. package/src/rbac/components/NavigationProvider.tsx +0 -345
  458. package/src/rbac/components/PagePermissionProvider.test.tsx +0 -476
  459. package/src/rbac/components/PagePermissionProvider.tsx +0 -279
  460. package/src/rbac/components/PermissionEnforcer.tsx +0 -312
  461. package/src/rbac/components/RoleBasedRouter.tsx +0 -440
  462. package/src/rbac/components/SecureDataProvider.test.tsx +0 -543
  463. package/src/rbac/components/SecureDataProvider.tsx +0 -339
  464. package/src/rbac/components/__tests__/EnhancedNavigationMenu.test.tsx +0 -620
  465. package/src/rbac/components/__tests__/NavigationProvider.test.tsx +0 -726
  466. package/src/rbac/components/__tests__/PagePermissionProvider.test.tsx +0 -661
  467. package/src/rbac/components/__tests__/PermissionEnforcer.test.tsx +0 -881
  468. package/src/rbac/components/__tests__/RoleBasedRouter.test.tsx +0 -783
  469. package/src/rbac/components/__tests__/SecureDataProvider.fixed.test.tsx +0 -645
  470. package/src/rbac/components/__tests__/SecureDataProvider.test.tsx +0 -659
  471. package/src/rbac/hooks/permissions/useCachedPermissions.ts +0 -79
  472. package/src/rbac/hooks/permissions/useHasAllPermissions.ts +0 -90
  473. package/src/rbac/hooks/permissions/useHasAnyPermission.ts +0 -90
@@ -0,0 +1,994 @@
1
+ import { AccessDenied } from './chunk-6F3IILHI.js';
2
+ import { useResolvedScope, scopeEqual, useCan, useMultiplePermissions } from './chunk-BM4CQ5P3.js';
3
+ import { useUnifiedAuth } from './chunk-FTCRZOG2.js';
4
+ import { getRBACLogger, getRBACConfig, RBACNotInitializedError } from './chunk-ZFYPMX46.js';
5
+ import { createLogger } from './chunk-TTRFSOKR.js';
6
+ import React, { useRef, useMemo, useState, useEffect } from 'react';
7
+ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
8
+
9
+ // src/rbac/types/functions.ts
10
+ var RPCFunction = /* @__PURE__ */ ((RPCFunction2) => {
11
+ RPCFunction2["RBAC_PERMISSION_CHECK"] = "rbac_permission_check";
12
+ RPCFunction2["RBAC_PERMISSIONS_GET"] = "rbac_permissions_get";
13
+ RPCFunction2["RBAC_ACCESS_VALIDATE"] = "rbac_access_validate";
14
+ RPCFunction2["RBAC_PAGE_ACCESS_CHECK"] = "rbac_page_access_check";
15
+ RPCFunction2["RBAC_ROLE_GRANT"] = "rbac_role_grant";
16
+ RPCFunction2["RBAC_ROLE_REVOKE"] = "rbac_role_revoke";
17
+ RPCFunction2["RBAC_ROLES_LIST"] = "rbac_roles_list";
18
+ RPCFunction2["RBAC_ROLE_VALIDATE"] = "rbac_role_validate";
19
+ RPCFunction2["RBAC_SESSION_TRACK"] = "rbac_session_track";
20
+ RPCFunction2["RBAC_AUDIT_LOG"] = "rbac_audit_log";
21
+ return RPCFunction2;
22
+ })(RPCFunction || {});
23
+ var RBACErrorCode = /* @__PURE__ */ ((RBACErrorCode2) => {
24
+ RBACErrorCode2["USER_NOT_FOUND"] = "USER_NOT_FOUND";
25
+ RBACErrorCode2["INVALID_ROLE_TYPE"] = "INVALID_ROLE_TYPE";
26
+ RBACErrorCode2["INVALID_ROLE_NAME"] = "INVALID_ROLE_NAME";
27
+ RBACErrorCode2["MISSING_ORGANISATION_ID"] = "MISSING_ORGANISATION_ID";
28
+ RBACErrorCode2["MISSING_EVENT_APP_CONTEXT"] = "MISSING_EVENT_APP_CONTEXT";
29
+ RBACErrorCode2["ORGANISATION_NOT_FOUND"] = "ORGANISATION_NOT_FOUND";
30
+ RBACErrorCode2["EVENT_NOT_FOUND"] = "EVENT_NOT_FOUND";
31
+ RBACErrorCode2["APP_NOT_FOUND"] = "APP_NOT_FOUND";
32
+ RBACErrorCode2["INVALID_SESSION_TYPE"] = "INVALID_SESSION_TYPE";
33
+ RBACErrorCode2["INVALID_EVENT_TYPE"] = "INVALID_EVENT_TYPE";
34
+ RBACErrorCode2["DATABASE_ERROR"] = "DATABASE_ERROR";
35
+ RBACErrorCode2["ROLE_NOT_FOUND"] = "ROLE_NOT_FOUND";
36
+ RBACErrorCode2["USER_NOT_AUTHENTICATED"] = "USER_NOT_AUTHENTICATED";
37
+ RBACErrorCode2["INVALID_GLOBAL_ROLE"] = "INVALID_GLOBAL_ROLE";
38
+ RBACErrorCode2["INVALID_ORGANISATION_ROLE"] = "INVALID_ORGANISATION_ROLE";
39
+ RBACErrorCode2["INVALID_EVENT_APP_ROLE"] = "INVALID_EVENT_APP_ROLE";
40
+ RBACErrorCode2["INVALID_EVENT_APP_FORMAT"] = "INVALID_EVENT_APP_FORMAT";
41
+ RBACErrorCode2["MISSING_CONTEXT"] = "MISSING_CONTEXT";
42
+ RBACErrorCode2["INVALID_CONTEXT"] = "INVALID_CONTEXT";
43
+ RBACErrorCode2["GRANTED_BY_NOT_FOUND"] = "GRANTED_BY_NOT_FOUND";
44
+ return RBACErrorCode2;
45
+ })(RBACErrorCode || {});
46
+ var PagePermissionGuardComponent = ({
47
+ pageName,
48
+ operation,
49
+ children,
50
+ fallback = /* @__PURE__ */ jsx(AccessDenied, {}),
51
+ strictMode = true,
52
+ auditLog = true,
53
+ pageId,
54
+ scope,
55
+ onDenied,
56
+ loading = /* @__PURE__ */ jsx(DefaultLoading, {})
57
+ }) => {
58
+ const renderCountRef = useRef(0);
59
+ renderCountRef.current += 1;
60
+ useMemo(() => Math.random().toString(36).substr(2, 9), []);
61
+ const { user, selectedOrganisation, selectedEvent, supabase, appId: contextAppId, appName } = useUnifiedAuth();
62
+ const [hasChecked, setHasChecked] = useState(false);
63
+ const hasLoggedSuperAdminRef = useRef(false);
64
+ const effectivePageId = useMemo(() => {
65
+ return pageId || pageName;
66
+ }, [pageId, pageName]);
67
+ const [isSuperAdmin, setIsSuperAdmin] = useState(null);
68
+ useEffect(() => {
69
+ if (!user?.id) {
70
+ setIsSuperAdmin(false);
71
+ return;
72
+ }
73
+ let cancelled = false;
74
+ const checkSuperAdmin = async () => {
75
+ const startTime = Date.now();
76
+ try {
77
+ const { isSuperAdmin: checkSuperAdmin2 } = await import('./api-Y4MQWOFW.js');
78
+ const timeoutPromise = new Promise((_, reject) => {
79
+ setTimeout(() => reject(new Error("Super admin check timeout")), 1e4);
80
+ });
81
+ const isSuper = await Promise.race([
82
+ checkSuperAdmin2(user.id),
83
+ timeoutPromise
84
+ ]);
85
+ const elapsed = Date.now() - startTime;
86
+ if (!cancelled) {
87
+ setIsSuperAdmin(isSuper);
88
+ if (false) ;
89
+ }
90
+ } catch (err) {
91
+ const elapsed = Date.now() - startTime;
92
+ if (!cancelled) {
93
+ console.error("[PagePermissionGuard] Error checking super admin", {
94
+ error: err,
95
+ userId: user.id,
96
+ elapsedMs: elapsed
97
+ });
98
+ setIsSuperAdmin(false);
99
+ }
100
+ }
101
+ };
102
+ checkSuperAdmin();
103
+ return () => {
104
+ cancelled = true;
105
+ };
106
+ }, [user?.id]);
107
+ const { resolvedScope: hookResolvedScope, isLoading: scopeLoading, error: scopeError } = useResolvedScope({
108
+ supabase,
109
+ selectedOrganisationId: selectedOrganisation?.id || null,
110
+ selectedEventId: selectedEvent?.event_id || null,
111
+ selectedEventOrganisationId: selectedEvent?.organisation_id || null
112
+ });
113
+ const shouldBypassScopeForSuperAdmin = isSuperAdmin === true;
114
+ const allowsOptionalContexts = appName === "PORTAL" || appName === "ADMIN";
115
+ const effectiveScope = scope || (hookResolvedScope ? {
116
+ ...hookResolvedScope,
117
+ appId: hookResolvedScope.appId || (allowsOptionalContexts ? contextAppId : void 0)
118
+ } : allowsOptionalContexts && contextAppId ? {
119
+ organisationId: void 0,
120
+ eventId: void 0,
121
+ appId: contextAppId
122
+ } : selectedEvent?.event_id ? {
123
+ organisationId: void 0,
124
+ // Will be derived from event
125
+ eventId: selectedEvent.event_id,
126
+ appId: contextAppId || void 0
127
+ } : null);
128
+ const checkError = scopeError;
129
+ const permission = useMemo(() => {
130
+ return `${operation}:page.${pageName}`;
131
+ }, [operation, pageName]);
132
+ const prevScopeRef = useRef(null);
133
+ const stableScope = useMemo(() => {
134
+ if (allowsOptionalContexts && effectiveScope) {
135
+ const newScope2 = {
136
+ organisationId: effectiveScope.organisationId,
137
+ appId: effectiveScope.appId || contextAppId || void 0,
138
+ eventId: effectiveScope.eventId
139
+ };
140
+ if (scopeEqual(prevScopeRef.current, newScope2)) {
141
+ return prevScopeRef.current;
142
+ }
143
+ prevScopeRef.current = newScope2;
144
+ return newScope2;
145
+ }
146
+ const newScope = effectiveScope && effectiveScope.organisationId ? {
147
+ organisationId: effectiveScope.organisationId,
148
+ appId: effectiveScope.appId || contextAppId || void 0,
149
+ eventId: effectiveScope.eventId || void 0
150
+ } : {
151
+ organisationId: effectiveScope?.organisationId || void 0,
152
+ appId: effectiveScope?.appId || contextAppId || void 0,
153
+ eventId: effectiveScope?.eventId || selectedEvent?.event_id || void 0
154
+ };
155
+ if (scopeEqual(prevScopeRef.current, newScope)) {
156
+ return prevScopeRef.current;
157
+ }
158
+ prevScopeRef.current = newScope;
159
+ return newScope;
160
+ }, [effectiveScope, appName, contextAppId, selectedEvent?.event_id]);
161
+ const scopeForPermissionCheck = shouldBypassScopeForSuperAdmin && !stableScope?.organisationId ? {
162
+ organisationId: void 0,
163
+ appId: contextAppId || void 0,
164
+ eventId: selectedEvent?.event_id || void 0
165
+ } : stableScope;
166
+ const shouldSkipPermissionCheck = isSuperAdmin === true;
167
+ const { can, isLoading: canIsLoading, error: canError } = useCan(
168
+ user?.id || "",
169
+ shouldSkipPermissionCheck ? { organisationId: void 0, appId: contextAppId || void 0, eventId: void 0 } : scopeForPermissionCheck,
170
+ permission,
171
+ effectivePageId,
172
+ true,
173
+ // Use cache
174
+ isSuperAdmin,
175
+ // precomputedSuperAdmin - null if checking, true/false if checked
176
+ appName
177
+ // Pass appName for PORTAL/ADMIN special case
178
+ );
179
+ const effectiveCan = shouldSkipPermissionCheck ? true : can;
180
+ const effectiveIsLoading = shouldSkipPermissionCheck ? false : canIsLoading;
181
+ const isLoading = shouldBypassScopeForSuperAdmin ? effectiveIsLoading : scopeLoading || effectiveIsLoading;
182
+ const error = checkError || canError;
183
+ useEffect(() => {
184
+ if (!isLoading && !error) {
185
+ setHasChecked(true);
186
+ if (!effectiveCan && onDenied) {
187
+ onDenied(pageName, operation);
188
+ }
189
+ } else if (error) {
190
+ setHasChecked(true);
191
+ }
192
+ }, [effectiveCan, isLoading, error, pageName, operation, onDenied]);
193
+ useEffect(() => {
194
+ if (auditLog && hasChecked && !isLoading) {
195
+ const rbacLogger = getRBACLogger();
196
+ rbacLogger.debug("Page access attempt:", {
197
+ pageName,
198
+ operation,
199
+ userId: user?.id,
200
+ scope: effectiveScope,
201
+ allowed: effectiveCan,
202
+ isSuperAdmin,
203
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
204
+ });
205
+ }
206
+ }, [auditLog, hasChecked, isLoading, pageName, operation, user?.id, effectiveScope, effectiveCan, isSuperAdmin]);
207
+ useEffect(() => {
208
+ if (strictMode && hasChecked && !isLoading && !effectiveCan && !shouldBypassScopeForSuperAdmin) {
209
+ const logger = getRBACLogger();
210
+ logger.error(`STRICT MODE VIOLATION: User attempted to access protected page without permission`, {
211
+ pageName,
212
+ operation,
213
+ permission: `${operation}:page.${pageName}`,
214
+ pageId: effectivePageId,
215
+ userId: user?.id,
216
+ scope: effectiveScope,
217
+ scopeValid: allowsOptionalContexts ? true : effectiveScope !== null,
218
+ // PORTAL/ADMIN allow scope without org/event
219
+ checkError,
220
+ canError,
221
+ isSuperAdmin,
222
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
223
+ });
224
+ }
225
+ }, [strictMode, hasChecked, isLoading, effectiveCan, shouldBypassScopeForSuperAdmin, pageName, operation, effectivePageId, user?.id, effectiveScope, allowsOptionalContexts, checkError, canError, isSuperAdmin]);
226
+ const hasValidScopeForPagePermissions = shouldBypassScopeForSuperAdmin ? true : allowsOptionalContexts ? true : effectiveScope !== null;
227
+ const hasValidUser = user && user.id;
228
+ const isPermissionCheckComplete = hasChecked && !isLoading;
229
+ const shouldShowAccessDenied = isPermissionCheckComplete && hasValidScopeForPagePermissions && hasValidUser && !checkError && !effectiveCan;
230
+ const shouldShowContent = isPermissionCheckComplete && hasValidScopeForPagePermissions && hasValidUser && !checkError && effectiveCan;
231
+ effectiveScope ? `${effectiveScope.organisationId}-${effectiveScope.eventId}-${effectiveScope.appId}` : "no-scope";
232
+ useRef("");
233
+ useEffect(() => {
234
+ }, [pageName, user?.id, isSuperAdmin, isLoading, scopeLoading, canIsLoading, hasChecked, hasValidUser, effectiveCan, stableScope, effectiveScope]);
235
+ useEffect(() => {
236
+ if (isLoading && isSuperAdmin === null && hasValidUser) {
237
+ const timeout = setTimeout(() => {
238
+ console.warn("[PagePermissionGuard] Permission check taking longer than expected", {
239
+ pageName,
240
+ userId: user?.id,
241
+ isSuperAdmin,
242
+ scopeLoading,
243
+ canIsLoading,
244
+ hasChecked,
245
+ stableScope,
246
+ effectiveScope,
247
+ appName
248
+ });
249
+ }, 5e3);
250
+ return () => clearTimeout(timeout);
251
+ }
252
+ }, [isLoading, isSuperAdmin, hasValidUser, pageName, user?.id, scopeLoading, canIsLoading, hasChecked, stableScope, effectiveScope, appName]);
253
+ useEffect(() => {
254
+ if (isSuperAdmin === true && hasValidUser && !hasLoggedSuperAdminRef.current && false) ;
255
+ if (isSuperAdmin !== true) {
256
+ hasLoggedSuperAdminRef.current = false;
257
+ }
258
+ }, [isSuperAdmin, hasValidUser, pageName, user?.id, operation]);
259
+ if (isSuperAdmin === true && hasValidUser) {
260
+ return /* @__PURE__ */ jsx(Fragment, { children });
261
+ }
262
+ if (isLoading || !hasValidUser || !hasChecked || isSuperAdmin === null) {
263
+ return loading || /* @__PURE__ */ jsx("div", { children: "Checking permissions..." });
264
+ }
265
+ if (checkError && !can) {
266
+ return fallback;
267
+ }
268
+ if (shouldShowAccessDenied) {
269
+ return fallback;
270
+ }
271
+ if (shouldShowContent) {
272
+ return /* @__PURE__ */ jsx(Fragment, { children });
273
+ }
274
+ return fallback;
275
+ };
276
+ function DefaultLoading() {
277
+ return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center min-h-[200px] p-8", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-2", children: [
278
+ /* @__PURE__ */ jsx("div", { className: "animate-spin rounded-full size-8 border-b-2 border-main-600" }),
279
+ /* @__PURE__ */ jsx("span", { className: "text-sec-600", children: "Checking permissions..." })
280
+ ] }) });
281
+ }
282
+ var PagePermissionGuard = React.memo(PagePermissionGuardComponent);
283
+ function NavigationGuard({
284
+ navigationItem,
285
+ children,
286
+ fallback = /* @__PURE__ */ jsx(AccessDenied, {}),
287
+ strictMode = true,
288
+ auditLog = true,
289
+ scope,
290
+ onDenied,
291
+ loading = /* @__PURE__ */ jsx(DefaultLoading2, {}),
292
+ requireAll = true
293
+ }) {
294
+ const { user, selectedOrganisation, selectedEvent, supabase } = useUnifiedAuth();
295
+ const [hasChecked, setHasChecked] = useState(false);
296
+ const { resolvedScope: hookResolvedScope, isLoading: scopeLoading, error: scopeError } = useResolvedScope({
297
+ supabase,
298
+ selectedOrganisationId: selectedOrganisation?.id || null,
299
+ selectedEventId: selectedEvent?.event_id || null,
300
+ selectedEventOrganisationId: selectedEvent?.organisation_id || null
301
+ });
302
+ const effectiveScope = scope || hookResolvedScope;
303
+ const checkError = scopeError;
304
+ const validPermissions = (navigationItem.permissions || []).filter(
305
+ (p) => typeof p === "string" && (p.startsWith("read:") || p.startsWith("create:") || p.startsWith("update:") || p.startsWith("delete:"))
306
+ );
307
+ const { results: permissionResults, isLoading: permissionsLoading, error: permissionsError } = useMultiplePermissions(
308
+ user?.id || "",
309
+ effectiveScope || { eventId: selectedEvent?.event_id || void 0 },
310
+ validPermissions,
311
+ true
312
+ // Use cache
313
+ );
314
+ const isLoading = scopeLoading || permissionsLoading;
315
+ const error = checkError || permissionsError;
316
+ const hasRequiredPermissions = useMemo(() => {
317
+ if (!navigationItem.permissions || navigationItem.permissions.length === 0) return true;
318
+ if (requireAll) {
319
+ return Object.values(permissionResults).every((result) => result === true);
320
+ } else {
321
+ return Object.values(permissionResults).some((result) => result === true);
322
+ }
323
+ }, [navigationItem.permissions, permissionResults, requireAll]);
324
+ useEffect(() => {
325
+ if (!isLoading && !error) {
326
+ setHasChecked(true);
327
+ if (!hasRequiredPermissions && onDenied) {
328
+ onDenied(navigationItem);
329
+ }
330
+ } else if (error) {
331
+ setHasChecked(true);
332
+ }
333
+ }, [hasRequiredPermissions, isLoading, error, navigationItem, onDenied]);
334
+ useEffect(() => {
335
+ }, [auditLog, hasChecked, isLoading, navigationItem, user?.id, effectiveScope, hasRequiredPermissions, requireAll]);
336
+ useEffect(() => {
337
+ if (strictMode && hasChecked && !isLoading && !hasRequiredPermissions) {
338
+ const logger = getRBACLogger();
339
+ logger.error(`STRICT MODE VIOLATION: User attempted to access protected navigation item without permission`, {
340
+ navigationItem: navigationItem.id,
341
+ permissions: navigationItem.permissions,
342
+ userId: user?.id,
343
+ scope: effectiveScope,
344
+ requireAll,
345
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
346
+ });
347
+ }
348
+ }, [strictMode, hasChecked, isLoading, hasRequiredPermissions, navigationItem, user?.id, effectiveScope, requireAll]);
349
+ if (isLoading || !effectiveScope || !hasChecked) {
350
+ return /* @__PURE__ */ jsx(Fragment, { children: loading });
351
+ }
352
+ if (checkError) {
353
+ const logger = getRBACLogger();
354
+ logger.error(`Permission check failed for navigation item ${navigationItem.id}:`, checkError);
355
+ return /* @__PURE__ */ jsx(Fragment, { children: fallback });
356
+ }
357
+ if (!hasRequiredPermissions) {
358
+ return /* @__PURE__ */ jsx(Fragment, { children: fallback });
359
+ }
360
+ return /* @__PURE__ */ jsx(Fragment, { children });
361
+ }
362
+ function DefaultLoading2() {
363
+ return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center p-2", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-2", children: [
364
+ /* @__PURE__ */ jsx("div", { className: "animate-spin rounded-full size-4 border-b-2 border-main-600" }),
365
+ /* @__PURE__ */ jsx("span", { className: "text-sm text-sec-600", children: "Checking..." })
366
+ ] }) });
367
+ }
368
+
369
+ // src/rbac/adapters.tsx
370
+ function withPermissionGuard(config, handler) {
371
+ return async (...args) => {
372
+ const [req] = args;
373
+ const userId = req.user?.id;
374
+ const organisationId = req.organisationId;
375
+ const eventId = req.eventId;
376
+ const appId = req.appId;
377
+ if (!userId || !organisationId) {
378
+ throw new Error("User context required for permission check");
379
+ }
380
+ const { isPermitted: isPermitted2 } = await import('./api-Y4MQWOFW.js');
381
+ const hasPermission = await isPermitted2({
382
+ userId,
383
+ scope: { organisationId, eventId, appId },
384
+ permission: config.permission,
385
+ pageId: config.pageId
386
+ });
387
+ if (!hasPermission) {
388
+ throw new Error(`Permission denied: ${config.permission}`);
389
+ }
390
+ return handler(...args);
391
+ };
392
+ }
393
+ function withAccessLevelGuard(minLevel, handler) {
394
+ return async (...args) => {
395
+ const [req] = args;
396
+ const userId = req.user?.id;
397
+ const organisationId = req.organisationId;
398
+ const eventId = req.eventId;
399
+ const appId = req.appId;
400
+ if (!userId || !organisationId) {
401
+ throw new Error("User context required for access level check");
402
+ }
403
+ const { getAccessLevel: getAccessLevel2 } = await import('./api-Y4MQWOFW.js');
404
+ const accessLevel = await getAccessLevel2({
405
+ userId,
406
+ scope: { organisationId, eventId, appId }
407
+ });
408
+ const levelHierarchy = ["viewer", "participant", "planner", "admin", "super"];
409
+ const userLevelIndex = levelHierarchy.indexOf(accessLevel);
410
+ const requiredLevelIndex = levelHierarchy.indexOf(minLevel);
411
+ if (userLevelIndex < requiredLevelIndex) {
412
+ throw new Error(`Access level required: ${minLevel}, got: ${accessLevel}`);
413
+ }
414
+ return handler(...args);
415
+ };
416
+ }
417
+ function withRoleGuard(config, handler) {
418
+ return async (...args) => {
419
+ const [req] = args;
420
+ const userId = req.user?.id;
421
+ const organisationId = req.organisationId;
422
+ const eventId = req.eventId;
423
+ const appId = req.appId;
424
+ if (!userId || !organisationId) {
425
+ throw new Error("User context required for role check");
426
+ }
427
+ if (config.globalRoles && config.globalRoles.length > 0) {
428
+ const { isSuperAdmin } = await import('./api-Y4MQWOFW.js');
429
+ const isSuper = await isSuperAdmin(userId);
430
+ if (isSuper) {
431
+ if (organisationId) {
432
+ const { emitAuditEvent: emitAuditEvent2 } = await import('./audit-MYQXYZFU.js');
433
+ await emitAuditEvent2({
434
+ type: "permission_check",
435
+ userId,
436
+ organisationId,
437
+ eventId,
438
+ appId,
439
+ permission: "bypass:all",
440
+ decision: true,
441
+ source: "api",
442
+ bypass: true,
443
+ duration_ms: 0,
444
+ metadata: {
445
+ operation: "role_guard",
446
+ reason: "super_admin_bypass"
447
+ }
448
+ });
449
+ }
450
+ return handler(...args);
451
+ }
452
+ }
453
+ if (config.organisationRoles && config.organisationRoles.length > 0) {
454
+ const { isOrganisationAdmin } = await import('./api-Y4MQWOFW.js');
455
+ const isOrgAdmin = await isOrganisationAdmin(userId, organisationId);
456
+ if (!isOrgAdmin && config.requireAll !== false) {
457
+ throw new Error(`Organisation admin role required`);
458
+ }
459
+ }
460
+ if (config.eventAppRoles && config.eventAppRoles.length > 0 && eventId && appId) {
461
+ const { isEventAdmin } = await import('./api-Y4MQWOFW.js');
462
+ const isEventAdminUser = await isEventAdmin(userId, { organisationId, eventId, appId });
463
+ if (!isEventAdminUser && config.requireAll !== false) {
464
+ throw new Error(`Event admin role required`);
465
+ }
466
+ }
467
+ if (organisationId) {
468
+ const { emitAuditEvent: emitAuditEvent2 } = await import('./audit-MYQXYZFU.js');
469
+ await emitAuditEvent2({
470
+ type: "permission_check",
471
+ userId,
472
+ organisationId,
473
+ eventId,
474
+ appId,
475
+ permission: "role:check",
476
+ decision: true,
477
+ source: "api",
478
+ bypass: false,
479
+ duration_ms: 0,
480
+ metadata: {
481
+ operation: "role_guard"
482
+ }
483
+ });
484
+ }
485
+ return handler(...args);
486
+ };
487
+ }
488
+ function createRBACMiddleware(config) {
489
+ return async (req, res, next) => {
490
+ const { pathname } = req.nextUrl;
491
+ const userId = req.user?.id;
492
+ const organisationId = req.organisationId;
493
+ if (!userId || !organisationId) {
494
+ return res.redirect(config.fallbackUrl || "/login");
495
+ }
496
+ const protectedRoute = config.protectedRoutes.find(
497
+ (route) => pathname.startsWith(route.path)
498
+ );
499
+ if (protectedRoute) {
500
+ try {
501
+ const { isPermitted: isPermitted2 } = await import('./api-Y4MQWOFW.js');
502
+ const hasPermission = await isPermitted2({
503
+ userId,
504
+ scope: { organisationId },
505
+ permission: protectedRoute.permission,
506
+ pageId: protectedRoute.pageId
507
+ });
508
+ if (!hasPermission) {
509
+ return res.redirect(config.fallbackUrl || "/access-denied");
510
+ }
511
+ } catch (_error) {
512
+ return res.redirect(config.fallbackUrl || "/access-denied");
513
+ }
514
+ }
515
+ next();
516
+ };
517
+ }
518
+ function createRBACExpressMiddleware(config) {
519
+ return async (req, res, next) => {
520
+ const userId = req.user?.id;
521
+ const organisationId = req.organisationId;
522
+ const eventId = req.eventId;
523
+ const appId = req.appId;
524
+ if (!userId || !organisationId) {
525
+ return res.status(401).json({ error: "User context required" });
526
+ }
527
+ try {
528
+ const { isPermitted: isPermitted2 } = await import('./api-Y4MQWOFW.js');
529
+ const hasPermission = await isPermitted2({
530
+ userId,
531
+ scope: { organisationId, eventId, appId },
532
+ permission: config.permission,
533
+ pageId: config.pageId
534
+ });
535
+ if (!hasPermission) {
536
+ return res.status(403).json({ error: "Permission denied" });
537
+ }
538
+ next();
539
+ } catch (_error) {
540
+ return res.status(500).json({ error: "Permission check failed" });
541
+ }
542
+ };
543
+ }
544
+
545
+ // src/rbac/permissions.ts
546
+ createLogger("RBACPermissions");
547
+ var GLOBAL_PERMISSIONS = {
548
+ READ_ALL: "read:*",
549
+ CREATE_ALL: "create:*",
550
+ UPDATE_ALL: "update:*",
551
+ DELETE_ALL: "delete:*"
552
+ };
553
+ var ORGANISATION_PERMISSIONS = {
554
+ // Organisation management
555
+ READ_ORGANISATION: "read:organisation",
556
+ UPDATE_ORGANISATION: "update:organisation",
557
+ DELETE_ORGANISATION: "delete:organisation",
558
+ // User management
559
+ READ_USERS: "read:users",
560
+ CREATE_USERS: "create:users",
561
+ UPDATE_USERS: "update:users",
562
+ DELETE_USERS: "delete:users",
563
+ // Role management
564
+ READ_ROLES: "read:roles",
565
+ CREATE_ROLES: "create:roles",
566
+ UPDATE_ROLES: "update:roles",
567
+ DELETE_ROLES: "delete:roles",
568
+ // Event management
569
+ READ_EVENTS: "read:events",
570
+ CREATE_EVENTS: "create:events",
571
+ UPDATE_EVENTS: "update:events",
572
+ DELETE_EVENTS: "delete:events",
573
+ // App management
574
+ READ_APPS: "read:apps",
575
+ CREATE_APPS: "create:apps",
576
+ UPDATE_APPS: "update:apps",
577
+ DELETE_APPS: "delete:apps"
578
+ };
579
+ var EVENT_APP_PERMISSIONS = {
580
+ // Event management
581
+ READ_EVENT: "read:event",
582
+ CREATE_EVENT: "create:event",
583
+ UPDATE_EVENT: "update:event",
584
+ DELETE_EVENT: "delete:event",
585
+ // App management
586
+ READ_APP: "read:app",
587
+ CREATE_APP: "create:app",
588
+ UPDATE_APP: "update:app",
589
+ DELETE_APP: "delete:app",
590
+ // Team management
591
+ READ_TEAM: "read:team",
592
+ CREATE_TEAM: "create:team",
593
+ UPDATE_TEAM: "update:team",
594
+ DELETE_TEAM: "delete:team",
595
+ // Team members
596
+ READ_TEAM_MEMBERS: "read:team.members",
597
+ CREATE_TEAM_MEMBERS: "create:team.members",
598
+ UPDATE_TEAM_MEMBERS: "update:team.members",
599
+ DELETE_TEAM_MEMBERS: "delete:team.members",
600
+ // Event content
601
+ READ_EVENT_CONTENT: "read:event.content",
602
+ CREATE_EVENT_CONTENT: "create:event.content",
603
+ UPDATE_EVENT_CONTENT: "update:event.content",
604
+ DELETE_EVENT_CONTENT: "delete:event.content",
605
+ // Event settings
606
+ READ_EVENT_SETTINGS: "read:event.settings",
607
+ CREATE_EVENT_SETTINGS: "create:event.settings",
608
+ UPDATE_EVENT_SETTINGS: "update:event.settings",
609
+ DELETE_EVENT_SETTINGS: "delete:event.settings"
610
+ };
611
+ var PAGE_PERMISSIONS = {
612
+ // General page access (generic - used for wildcard checks)
613
+ READ_PAGE: "read:page",
614
+ CREATE_PAGE: "create:page",
615
+ UPDATE_PAGE: "update:page",
616
+ DELETE_PAGE: "delete:page",
617
+ // Admin pages
618
+ READ_ADMIN: "read:page.admin",
619
+ CREATE_ADMIN: "create:page.admin",
620
+ UPDATE_ADMIN: "update:page.admin",
621
+ DELETE_ADMIN: "delete:page.admin",
622
+ // Dashboard pages
623
+ READ_DASHBOARD: "read:page.dashboard",
624
+ CREATE_DASHBOARD: "create:page.dashboard",
625
+ UPDATE_DASHBOARD: "update:page.dashboard",
626
+ DELETE_DASHBOARD: "delete:page.dashboard",
627
+ // Settings pages
628
+ READ_SETTINGS: "read:page.settings",
629
+ CREATE_SETTINGS: "create:page.settings",
630
+ UPDATE_SETTINGS: "update:page.settings",
631
+ DELETE_SETTINGS: "delete:page.settings",
632
+ // Reports pages
633
+ READ_REPORTS: "read:page.reports",
634
+ CREATE_REPORTS: "create:page.reports",
635
+ UPDATE_REPORTS: "update:page.reports",
636
+ DELETE_REPORTS: "delete:page.reports"
637
+ };
638
+ function isValidPermission(permission) {
639
+ const pattern = /^(read|create|update|delete):[a-z0-9]+(\.[a-z0-9]+)*$|^(read|create|update|delete):\*$/;
640
+ return pattern.test(permission);
641
+ }
642
+ var ALL_PERMISSIONS = {
643
+ ...GLOBAL_PERMISSIONS,
644
+ ...ORGANISATION_PERMISSIONS,
645
+ ...EVENT_APP_PERMISSIONS,
646
+ ...PAGE_PERMISSIONS
647
+ };
648
+
649
+ // src/rbac/compliance/setup-validator.ts
650
+ function isRBACInitialized() {
651
+ try {
652
+ const config = getRBACConfig();
653
+ return config !== null && config.supabase !== null;
654
+ } catch (error) {
655
+ if (error instanceof RBACNotInitializedError) {
656
+ return false;
657
+ }
658
+ throw error;
659
+ }
660
+ }
661
+ function getSetupIssues() {
662
+ const issues = [];
663
+ const config = getRBACConfig();
664
+ if (!config) {
665
+ issues.push({
666
+ type: "not-initialized",
667
+ message: "RBAC system has not been initialized. setupRBAC() has not been called.",
668
+ recommendation: "Call setupRBAC(supabase) before using any RBAC features. This should be done in your main entry point (main.tsx or App.tsx) before rendering the app."
669
+ });
670
+ return issues;
671
+ }
672
+ if (!config.supabase) {
673
+ issues.push({
674
+ type: "missing-config",
675
+ message: "RBAC configuration is missing Supabase client.",
676
+ recommendation: "Ensure setupRBAC() is called with a valid Supabase client instance."
677
+ });
678
+ }
679
+ return issues;
680
+ }
681
+ function getProviderContextIssues() {
682
+ const issues = [];
683
+ if (!isRBACInitialized()) {
684
+ issues.push({
685
+ type: "not-initialized",
686
+ message: "RBAC system must be initialized before provider context can be used.",
687
+ recommendation: "Call setupRBAC(supabase) before rendering UnifiedAuthProvider."
688
+ });
689
+ }
690
+ return issues;
691
+ }
692
+ function validateRBACSetup() {
693
+ const issues = getSetupIssues();
694
+ const providerIssues = getProviderContextIssues();
695
+ return {
696
+ isCompliant: issues.length === 0 && providerIssues.length === 0,
697
+ issues: [...issues, ...providerIssues]
698
+ };
699
+ }
700
+
701
+ // src/rbac/compliance/runtime-compliance.ts
702
+ function checkRuntimeCompliance() {
703
+ const logger = getRBACLogger();
704
+ const setupValidation = validateRBACSetup();
705
+ const warnings = [];
706
+ if (!setupValidation.isCompliant) {
707
+ setupValidation.issues.forEach((issue) => {
708
+ const warning = `[RBAC Compliance] ${issue.message}
709
+ Recommendation: ${issue.recommendation}`;
710
+ warnings.push(warning);
711
+ logger.warn(warning);
712
+ });
713
+ }
714
+ const providerContextIssues = setupValidation.issues.filter(
715
+ (issue) => issue.type === "missing-provider-context" || issue.type === "not-initialized"
716
+ );
717
+ const providerContext = providerContextIssues.length > 0 ? {
718
+ available: false,
719
+ message: "UnifiedAuthProvider context may not be available. Ensure your app is wrapped with UnifiedAuthProvider from @jmruthers/pace-core."
720
+ } : {
721
+ available: true
722
+ };
723
+ return {
724
+ setup: setupValidation,
725
+ warnings,
726
+ providerContext
727
+ };
728
+ }
729
+ function validateAndWarn() {
730
+ if (import.meta.env.MODE === "development" || import.meta.env.DEV) {
731
+ checkRuntimeCompliance();
732
+ }
733
+ }
734
+
735
+ // src/rbac/compliance/database-validator.ts
736
+ async function validateDatabaseConfiguration(supabase, appName) {
737
+ const issues = [];
738
+ const recommendations = [];
739
+ let appConfigured = false;
740
+ let pagesConfigured = false;
741
+ let permissionsConfigured = false;
742
+ let rlsPoliciesActive = false;
743
+ let rolesConfigured = false;
744
+ try {
745
+ const { data: app, error: appError } = await supabase.from("rbac_apps").select("id, name").eq("name", appName).single();
746
+ if (appError || !app) {
747
+ issues.push({
748
+ type: "app-not-configured",
749
+ message: `App '${appName}' not found in rbac_apps table.`,
750
+ recommendation: `Register your app in the rbac_apps table with name '${appName}' (case-sensitive).`
751
+ });
752
+ } else {
753
+ appConfigured = true;
754
+ if (app.name !== appName) {
755
+ issues.push({
756
+ type: "app-name-mismatch",
757
+ message: `App name mismatch. Database has '${app.name}', but environment variable has '${appName}'.`,
758
+ recommendation: `Ensure VITE_APP_NAME (or NEXT_PUBLIC_APP_NAME) matches the app name in rbac_apps table exactly (case-sensitive).`
759
+ });
760
+ }
761
+ const { data: pages, error: pagesError } = await supabase.from("rbac_app_pages").select("id").eq("app_id", app.id).limit(1);
762
+ if (pagesError || !pages || pages.length === 0) {
763
+ issues.push({
764
+ type: "pages-not-configured",
765
+ message: `No pages found for app '${appName}' in rbac_app_pages table.`,
766
+ recommendation: "Register your app pages in the rbac_app_pages table. Each route/page should have an entry."
767
+ });
768
+ } else {
769
+ pagesConfigured = true;
770
+ const { data: permissions, error: permissionsError } = await supabase.from("rbac_page_permissions").select("id").in("page_id", pages.map((p) => p.id)).limit(1);
771
+ if (permissionsError || !permissions || permissions.length === 0) {
772
+ issues.push({
773
+ type: "permissions-not-configured",
774
+ message: `No permissions found for app '${appName}' pages in rbac_page_permissions table.`,
775
+ recommendation: "Configure permissions for your app pages in the rbac_page_permissions table. Each page should have permissions for different operations (read, create, update, delete)."
776
+ });
777
+ } else {
778
+ permissionsConfigured = true;
779
+ }
780
+ }
781
+ }
782
+ try {
783
+ const { data: rbacTables, error: rlsError } = await supabase.rpc("rbac_check_rls_status");
784
+ if (rlsError) {
785
+ rlsPoliciesActive = true;
786
+ recommendations.push("Consider adding an RLS status check function to validate RLS policies are active.");
787
+ } else {
788
+ rlsPoliciesActive = true;
789
+ }
790
+ } catch (error) {
791
+ rlsPoliciesActive = true;
792
+ recommendations.push("Consider adding an RLS status check function to validate RLS policies are active.");
793
+ }
794
+ const { data: orgRoles, error: rolesError } = await supabase.from("rbac_organisation_roles").select("id").limit(1);
795
+ if (rolesError) {
796
+ issues.push({
797
+ type: "roles-not-configured",
798
+ message: "Unable to query rbac_organisation_roles table. RLS might be blocking access or table might not exist.",
799
+ recommendation: "Ensure rbac_organisation_roles table exists and RLS policies allow read access for authenticated users."
800
+ });
801
+ } else {
802
+ rolesConfigured = true;
803
+ }
804
+ } catch (error) {
805
+ issues.push({
806
+ type: "app-not-configured",
807
+ message: `Error validating database configuration: ${error instanceof Error ? error.message : "Unknown error"}`,
808
+ recommendation: "Check your Supabase connection and ensure you have the necessary permissions to query RBAC tables."
809
+ });
810
+ }
811
+ return {
812
+ appConfigured,
813
+ pagesConfigured,
814
+ permissionsConfigured,
815
+ rlsPoliciesActive,
816
+ rolesConfigured,
817
+ issues,
818
+ recommendations
819
+ };
820
+ }
821
+
822
+ // src/rbac/compliance/quick-fix-suggestions.ts
823
+ function getCustomAuthCodeFixes(customCodeName, type) {
824
+ const fixes = {
825
+ "useAuth": {
826
+ issue: `Custom ${type} '${customCodeName}' detected`,
827
+ suggestion: `Replace with useUnifiedAuth from pace-core`,
828
+ codeExample: `// Before
829
+ import { useAuth } from './hooks/useAuth';
830
+
831
+ // After
832
+ import { useUnifiedAuth } from '@jmruthers/pace-core';`,
833
+ migrationSteps: [
834
+ "Remove custom useAuth hook",
835
+ "Import useUnifiedAuth from @jmruthers/pace-core",
836
+ "Update all usages to use useUnifiedAuth",
837
+ "Ensure UnifiedAuthProvider wraps your app"
838
+ ]
839
+ },
840
+ "usePermissions": {
841
+ issue: `Custom ${type} '${customCodeName}' detected`,
842
+ suggestion: `Replace with usePermissions from pace-core`,
843
+ codeExample: `// Before
844
+ import { usePermissions } from './hooks/usePermissions';
845
+
846
+ // After
847
+ import { usePermissions } from '@jmruthers/pace-core/rbac';`,
848
+ migrationSteps: [
849
+ "Remove custom usePermissions hook",
850
+ "Import usePermissions from @jmruthers/pace-core/rbac",
851
+ "Update all usages - ensure setupRBAC() has been called",
852
+ "Verify provider hierarchy is correct"
853
+ ]
854
+ },
855
+ "PermissionGuard": {
856
+ issue: `Custom ${type} '${customCodeName}' detected`,
857
+ suggestion: `Replace with PagePermissionGuard from pace-core`,
858
+ codeExample: `// Before
859
+ import { PermissionGuard } from './components/PermissionGuard';
860
+
861
+ // After
862
+ import { PagePermissionGuard } from '@jmruthers/pace-core/rbac';`,
863
+ migrationSteps: [
864
+ "Remove custom PermissionGuard component",
865
+ "Import PagePermissionGuard from @jmruthers/pace-core/rbac",
866
+ "Wrap pages with PagePermissionGuard",
867
+ "Use pageName and operation props instead of custom permission strings"
868
+ ]
869
+ },
870
+ "checkPermission": {
871
+ issue: `Custom ${type} '${customCodeName}' detected`,
872
+ suggestion: `Replace with isPermitted from pace-core`,
873
+ codeExample: `// Before
874
+ import { checkPermission } from './utils/permissions';
875
+
876
+ // After
877
+ import { isPermitted } from '@jmruthers/pace-core/rbac';`,
878
+ migrationSteps: [
879
+ "Remove custom checkPermission utility",
880
+ "Import isPermitted from @jmruthers/pace-core/rbac",
881
+ "Update all usages to use isPermitted with proper scope",
882
+ "Ensure setupRBAC() has been called"
883
+ ]
884
+ }
885
+ };
886
+ return fixes[customCodeName] || {
887
+ issue: `Custom ${type} '${customCodeName}' detected`,
888
+ suggestion: `Use pace-core's equivalent instead. Check @jmruthers/pace-core documentation for the correct import.`,
889
+ migrationSteps: [
890
+ `Remove custom ${customCodeName} ${type}`,
891
+ "Find equivalent in pace-core",
892
+ "Import from @jmruthers/pace-core or @jmruthers/pace-core/rbac",
893
+ "Update all usages"
894
+ ]
895
+ };
896
+ }
897
+ function getDuplicateConfigFixes() {
898
+ return {
899
+ issue: "Multiple Supabase client instantiations found",
900
+ suggestion: "Consolidate to a single Supabase client configuration",
901
+ codeExample: `// Before - Multiple createClient calls
902
+ // src/lib/supabase.ts
903
+ export const supabase = createClient(url, key);
904
+
905
+ // src/utils/api.ts
906
+ export const supabase = createClient(url, key);
907
+
908
+ // After - Single configuration
909
+ // src/lib/supabase.ts
910
+ export const supabase = createClient(
911
+ import.meta.env.VITE_SUPABASE_URL,
912
+ import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY
913
+ );
914
+
915
+ // src/utils/api.ts
916
+ import { supabase } from '../lib/supabase';`,
917
+ migrationSteps: [
918
+ "Create a single supabase.ts file in a shared location (e.g., src/lib/supabase.ts)",
919
+ "Move all Supabase client creation to this file",
920
+ "Export the client instance",
921
+ "Update all files to import from the shared location",
922
+ "Remove duplicate createClient calls"
923
+ ]
924
+ };
925
+ }
926
+ function getUnprotectedPageFixes() {
927
+ return {
928
+ issue: "Route/page found without PagePermissionGuard",
929
+ suggestion: "Wrap all routes with PagePermissionGuard",
930
+ codeExample: `// Before
931
+ <Route path="/dashboard" element={<Dashboard />} />
932
+
933
+ // After
934
+ <Route
935
+ path="/dashboard"
936
+ element={
937
+ <PagePermissionGuard pageName="dashboard" operation="read">
938
+ <Dashboard />
939
+ </PagePermissionGuard>
940
+ }
941
+ />`,
942
+ migrationSteps: [
943
+ "Import PagePermissionGuard from @jmruthers/pace-core/rbac",
944
+ "Wrap each route/page component with PagePermissionGuard",
945
+ "Set pageName prop to match your page name in rbac_app_pages table",
946
+ "Set operation prop (read, create, update, or delete)",
947
+ "Ensure setupRBAC() has been called and providers are set up correctly"
948
+ ]
949
+ };
950
+ }
951
+ function getDirectSupabaseAuthFixes() {
952
+ return {
953
+ issue: "Direct Supabase auth usage detected",
954
+ suggestion: "Use UnifiedAuthProvider and useUnifiedAuth from pace-core",
955
+ codeExample: `// Before
956
+ import { createClient } from '@supabase/supabase-js';
957
+ const supabase = createClient(url, key);
958
+ await supabase.auth.signInWithPassword({ email, password });
959
+
960
+ // After
961
+ import { useUnifiedAuth } from '@jmruthers/pace-core';
962
+ const { signIn } = useUnifiedAuth();
963
+ await signIn({ email, password });`,
964
+ migrationSteps: [
965
+ "Remove direct Supabase auth calls",
966
+ "Import useUnifiedAuth from @jmruthers/pace-core",
967
+ "Use the auth methods from useUnifiedAuth hook",
968
+ "Ensure UnifiedAuthProvider wraps your app",
969
+ "Update all auth-related code to use pace-core hooks"
970
+ ]
971
+ };
972
+ }
973
+ function getQuickFixes(issueType, details) {
974
+ const fixes = [];
975
+ switch (issueType) {
976
+ case "custom-auth-code":
977
+ if (details?.name && details?.type) {
978
+ fixes.push(getCustomAuthCodeFixes(details.name, details.type));
979
+ }
980
+ break;
981
+ case "duplicate-config":
982
+ fixes.push(getDuplicateConfigFixes());
983
+ break;
984
+ case "unprotected-pages":
985
+ fixes.push(getUnprotectedPageFixes());
986
+ break;
987
+ case "direct-supabase-auth":
988
+ fixes.push(getDirectSupabaseAuthFixes());
989
+ break;
990
+ }
991
+ return fixes;
992
+ }
993
+
994
+ export { ALL_PERMISSIONS, EVENT_APP_PERMISSIONS, GLOBAL_PERMISSIONS, NavigationGuard, ORGANISATION_PERMISSIONS, PAGE_PERMISSIONS, PagePermissionGuard, RBACErrorCode, RPCFunction, checkRuntimeCompliance, createRBACExpressMiddleware, createRBACMiddleware, getCustomAuthCodeFixes, getDirectSupabaseAuthFixes, getDuplicateConfigFixes, getQuickFixes, getSetupIssues, getUnprotectedPageFixes, isRBACInitialized, isValidPermission, validateAndWarn, validateDatabaseConfiguration, validateRBACSetup, withAccessLevelGuard, withPermissionGuard, withRoleGuard };