@jmruthers/pace-core 0.5.53 → 0.5.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/dist/{DataTable-7FMFXA7A.js → DataTable-4T627QFJ.js} +11 -11
- package/dist/{PublicLoadingSpinner-Bq_-BeK-.d.ts → PublicLoadingSpinner-SL8WaQN7.d.ts} +2 -21
- package/dist/{api-H5A3H4IR.js → api-LUNF5O6M.js} +3 -3
- package/dist/{appConfig-BVGyuvI7.d.ts → appConfig-DjpeG6P-.d.ts} +9 -1
- package/dist/{appNameResolver-7GHF5ED2.js → appNameResolver-UURKN7NF.js} +2 -2
- package/dist/{audit-BUW3LMJB.js → audit-6TOCAMKO.js} +2 -2
- package/dist/{chunk-MZBUOP4P.js → chunk-5BSLGBYI.js} +4 -3
- package/dist/chunk-5BSLGBYI.js.map +1 -0
- package/dist/{chunk-I5Z3QH5X.js → chunk-66C4BSAY.js} +2 -2
- package/dist/{chunk-I5Z3QH5X.js.map → chunk-66C4BSAY.js.map} +1 -1
- package/dist/{chunk-MYP2EGHX.js → chunk-AJ2KMES7.js} +21 -14
- package/dist/chunk-AJ2KMES7.js.map +1 -0
- package/dist/{chunk-EL2O4IUX.js → chunk-AQFRLC7K.js} +16 -24
- package/dist/{chunk-EL2O4IUX.js.map → chunk-AQFRLC7K.js.map} +1 -1
- package/dist/{chunk-7BNPOCLL.js → chunk-B2WTCLCV.js} +6 -2
- package/dist/chunk-B2WTCLCV.js.map +1 -0
- package/dist/{chunk-WJARTBCT.js → chunk-D7ARGIA3.js} +16 -7
- package/dist/chunk-D7ARGIA3.js.map +1 -0
- package/dist/{chunk-NRK4AIHQ.js → chunk-KBRACSJI.js} +3 -3
- package/dist/{chunk-NYUJ4FJR.js → chunk-KJDPSM64.js} +7 -7
- package/dist/chunk-KJDPSM64.js.map +1 -0
- package/dist/{chunk-GWSBHC4J.js → chunk-KLPVOPRI.js} +261 -38
- package/dist/chunk-KLPVOPRI.js.map +1 -0
- package/dist/{chunk-TRIZ7IB7.js → chunk-MPQDF75X.js} +148 -288
- package/dist/chunk-MPQDF75X.js.map +1 -0
- package/dist/{chunk-MSFACPQQ.js → chunk-PAEM3OWN.js} +11 -11
- package/dist/{chunk-MSFACPQQ.js.map → chunk-PAEM3OWN.js.map} +1 -1
- package/dist/{chunk-GIO7BFE7.js → chunk-RQD3D2CO.js} +66 -169
- package/dist/{chunk-GIO7BFE7.js.map → chunk-RQD3D2CO.js.map} +1 -1
- package/dist/{chunk-YDJW5XTN.js → chunk-STT7INZR.js} +25 -1
- package/dist/chunk-STT7INZR.js.map +1 -0
- package/dist/{chunk-6MTY77WU.js → chunk-TNMXZLDR.js} +3 -3
- package/dist/{chunk-BC3S53OZ.js → chunk-UQE2Y64H.js} +30 -14
- package/dist/chunk-UQE2Y64H.js.map +1 -0
- package/dist/{chunk-22KLBHPS.js → chunk-W66AZIOH.js} +2 -2
- package/dist/chunk-W66AZIOH.js.map +1 -0
- package/dist/{chunk-SS3E6QLB.js → chunk-YNUBMSMV.js} +2 -2
- package/dist/chunk-YNUBMSMV.js.map +1 -0
- package/dist/{chunk-NZ655MWE.js → chunk-ZOD2ZY6X.js} +5 -4
- package/dist/chunk-ZOD2ZY6X.js.map +1 -0
- package/dist/{chunk-74C6SNEC.js → chunk-ZPK5656W.js} +3 -3
- package/dist/{chunk-74C6SNEC.js.map → chunk-ZPK5656W.js.map} +1 -1
- package/dist/components.d.ts +22 -899
- package/dist/components.js +436 -3118
- package/dist/components.js.map +1 -1
- package/dist/file-reference-9xUOnwyt.d.ts +70 -0
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +10 -10
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +49 -9
- package/dist/index.js +190 -25
- package/dist/index.js.map +1 -1
- package/dist/{organisation-CO3Sh3_D.d.ts → organisation-t-vvQC3g.d.ts} +1 -8
- package/dist/providers.d.ts +2 -2
- package/dist/providers.js +5 -5
- package/dist/rbac/index.d.ts +65 -46
- package/dist/rbac/index.js +10 -12
- package/dist/styles/core.css +0 -125
- package/dist/types.d.ts +2 -1
- package/dist/types.js +3 -1
- package/dist/types.js.map +1 -1
- package/dist/{usePublicRouteParams-B2OcAsur.d.ts → usePublicRouteParams-CdoFxnJK.d.ts} +1 -1
- package/dist/utils.d.ts +3 -4
- package/dist/utils.js +44 -13
- package/dist/utils.js.map +1 -1
- package/docs/FILE_REFERENCE_SYSTEM.md +440 -0
- package/docs/INDEX.md +7 -5
- package/docs/README.md +0 -1
- package/docs/api/README.md +0 -4
- package/docs/api/classes/ErrorBoundary.md +1 -1
- package/docs/api/classes/InvalidScopeError.md +1 -1
- package/docs/api/classes/MissingUserContextError.md +1 -1
- package/docs/api/classes/OrganisationContextRequiredError.md +1 -1
- package/docs/api/classes/PermissionDeniedError.md +2 -2
- package/docs/api/classes/PublicErrorBoundary.md +1 -1
- package/docs/api/classes/RBACAuditManager.md +12 -12
- package/docs/api/classes/RBACCache.md +1 -1
- package/docs/api/classes/RBACEngine.md +6 -6
- package/docs/api/classes/RBACError.md +1 -1
- package/docs/api/classes/RBACNotInitializedError.md +1 -1
- package/docs/api/classes/SecureSupabaseClient.md +1 -1
- package/docs/api/classes/StorageUtils.md +281 -0
- package/docs/api/interfaces/AggregateConfig.md +1 -1
- package/docs/api/interfaces/ButtonProps.md +1 -1
- package/docs/api/interfaces/CardProps.md +1 -1
- package/docs/api/interfaces/ColorPalette.md +1 -1
- package/docs/api/interfaces/ColorShade.md +1 -1
- package/docs/api/interfaces/DataAccessRecord.md +1 -1
- package/docs/api/interfaces/DataTableAction.md +1 -1
- package/docs/api/interfaces/DataTableColumn.md +1 -1
- package/docs/api/interfaces/DataTableProps.md +1 -1
- package/docs/api/interfaces/DataTableToolbarButton.md +1 -1
- package/docs/api/interfaces/EmptyStateConfig.md +1 -1
- package/docs/api/interfaces/EnhancedNavigationMenuProps.md +1 -1
- package/docs/api/interfaces/EventContextType.md +1 -1
- package/docs/api/interfaces/EventLogoProps.md +1 -1
- package/docs/api/interfaces/EventProviderProps.md +1 -1
- package/docs/api/interfaces/FileSizeLimits.md +1 -1
- package/docs/api/interfaces/FileUploadProps.md +1 -1
- package/docs/api/interfaces/FooterProps.md +1 -1
- package/docs/api/interfaces/InactivityWarningModalProps.md +1 -1
- package/docs/api/interfaces/InputProps.md +1 -1
- package/docs/api/interfaces/LabelProps.md +1 -1
- package/docs/api/interfaces/LoginFormProps.md +1 -1
- package/docs/api/interfaces/NavigationAccessRecord.md +2 -2
- package/docs/api/interfaces/NavigationContextType.md +1 -1
- package/docs/api/interfaces/NavigationGuardProps.md +1 -1
- package/docs/api/interfaces/NavigationItem.md +1 -1
- package/docs/api/interfaces/NavigationMenuProps.md +1 -1
- package/docs/api/interfaces/NavigationProviderProps.md +1 -1
- package/docs/api/interfaces/Organisation.md +1 -1
- package/docs/api/interfaces/OrganisationContextType.md +1 -1
- package/docs/api/interfaces/OrganisationMembership.md +1 -1
- package/docs/api/interfaces/OrganisationProviderProps.md +1 -1
- package/docs/api/interfaces/OrganisationSecurityError.md +1 -1
- package/docs/api/interfaces/PaceAppLayoutProps.md +1 -1
- package/docs/api/interfaces/PaceLoginPageProps.md +1 -1
- package/docs/api/interfaces/PageAccessRecord.md +1 -1
- package/docs/api/interfaces/PagePermissionContextType.md +1 -1
- package/docs/api/interfaces/PagePermissionGuardProps.md +1 -1
- package/docs/api/interfaces/PagePermissionProviderProps.md +1 -1
- package/docs/api/interfaces/PaletteData.md +1 -1
- package/docs/api/interfaces/PermissionEnforcerProps.md +4 -4
- package/docs/api/interfaces/PublicErrorBoundaryProps.md +1 -1
- package/docs/api/interfaces/PublicErrorBoundaryState.md +1 -1
- package/docs/api/interfaces/PublicLoadingSpinnerProps.md +1 -1
- package/docs/api/interfaces/PublicPageFooterProps.md +1 -1
- package/docs/api/interfaces/PublicPageHeaderProps.md +1 -1
- package/docs/api/interfaces/PublicPageLayoutProps.md +1 -1
- package/docs/api/interfaces/RBACConfig.md +1 -1
- package/docs/api/interfaces/RBACContextType.md +1 -1
- package/docs/api/interfaces/RBACLogger.md +1 -1
- package/docs/api/interfaces/RBACProviderProps.md +1 -1
- package/docs/api/interfaces/RoleBasedRouterContextType.md +1 -1
- package/docs/api/interfaces/RoleBasedRouterProps.md +1 -1
- package/docs/api/interfaces/RouteAccessRecord.md +2 -2
- package/docs/api/interfaces/RouteConfig.md +2 -2
- package/docs/api/interfaces/SecureDataContextType.md +1 -1
- package/docs/api/interfaces/SecureDataProviderProps.md +1 -1
- package/docs/api/interfaces/StorageConfig.md +1 -1
- package/docs/api/interfaces/StorageFileInfo.md +1 -1
- package/docs/api/interfaces/StorageFileMetadata.md +1 -1
- package/docs/api/interfaces/StorageListOptions.md +1 -1
- package/docs/api/interfaces/StorageListResult.md +1 -1
- package/docs/api/interfaces/StorageUploadOptions.md +1 -1
- package/docs/api/interfaces/StorageUploadResult.md +1 -1
- package/docs/api/interfaces/StorageUrlOptions.md +1 -1
- package/docs/api/interfaces/StyleImport.md +1 -1
- package/docs/api/interfaces/ToastActionElement.md +1 -1
- package/docs/api/interfaces/ToastProps.md +1 -1
- package/docs/api/interfaces/UnifiedAuthContextType.md +1 -1
- package/docs/api/interfaces/UnifiedAuthProviderProps.md +1 -1
- package/docs/api/interfaces/UseInactivityTrackerOptions.md +1 -1
- package/docs/api/interfaces/UseInactivityTrackerReturn.md +1 -1
- package/docs/api/interfaces/UsePublicEventLogoOptions.md +1 -1
- package/docs/api/interfaces/UsePublicEventLogoReturn.md +1 -1
- package/docs/api/interfaces/UsePublicEventOptions.md +1 -1
- package/docs/api/interfaces/UsePublicEventReturn.md +1 -1
- package/docs/api/interfaces/UsePublicRouteParamsReturn.md +1 -1
- package/docs/api/interfaces/UserEventAccess.md +1 -1
- package/docs/api/interfaces/UserMenuProps.md +1 -1
- package/docs/api/interfaces/UserProfile.md +1 -1
- package/docs/api/modules.md +204 -200
- package/docs/api-reference/components.md +141 -163
- package/docs/api-reference/hooks.md +347 -0
- package/docs/core-concepts/rbac-system.md +69 -16
- package/docs/getting-started/examples/basic-auth-app.md +0 -1
- package/docs/implementation-guides/datatable-rbac-usage.md +12 -11
- package/docs/implementation-guides/file-upload-storage.md +733 -0
- package/docs/implementation-guides/inactivity-tracking.md +779 -0
- package/docs/implementation-guides/organisation-security.md +748 -0
- package/docs/implementation-guides/public-pages-advanced.md +1022 -0
- package/docs/migration/MIGRATION_GUIDE.md +684 -0
- package/docs/migration/README.md +13 -2
- package/docs/migration/rbac-migration.md +73 -0
- package/docs/rbac/examples/rbac-rls-integration-example.md +11 -13
- package/docs/style-guide.md +269 -1
- package/package.json +1 -1
- package/src/__tests__/TESTING_GUIDELINES.md +331 -18
- package/src/__tests__/helpers/supabaseMock.ts +99 -0
- package/src/__tests__/rbac/PagePermissionGuard.test.tsx +10 -7
- package/src/__tests__/shared.ts +6 -0
- package/src/components/DataTable/components/ActionButtons.tsx +2 -2
- package/src/components/DataTable/components/DataTableCore.tsx +2 -2
- package/src/components/DataTable/components/UnifiedTableBody.tsx +1 -1
- package/src/components/DataTable/utils/debugTools.ts +2 -2
- package/src/components/Dialog/Dialog.test.tsx +12 -2
- package/src/components/ErrorBoundary/ErrorBoundary.test.tsx +6 -6
- package/src/components/ErrorBoundary/ErrorBoundary.tsx +2 -2
- package/src/components/FileDisplay.tsx +233 -0
- package/src/components/FileUpload.tsx +176 -0
- package/src/components/Footer/Footer.test.tsx +7 -7
- package/src/components/NavigationMenu/NavigationMenu.test.tsx +13 -6
- package/src/components/OrganisationSelector/OrganisationSelector.test.tsx +30 -3
- package/src/components/OrganisationSelector/OrganisationSelector.tsx +1 -1
- package/src/components/PaceAppLayout/__tests__/PaceAppLayout.rbac.test.tsx +558 -0
- package/src/components/PublicLayout/PublicErrorBoundary.tsx +1 -1
- package/src/components/PublicLayout/PublicPageDebugger.tsx +2 -2
- package/src/components/PublicLayout/PublicPageDiagnostic.tsx +2 -2
- package/src/components/PublicLayout/PublicPageProvider.tsx +2 -2
- package/src/components/Select/Select.test.tsx +50 -15
- package/src/components/SuperAdminGuard.tsx +2 -2
- package/src/components/__tests__/SuperAdminGuard.test.tsx +559 -0
- package/src/components/index.ts +0 -183
- package/src/hooks/__tests__/useOrganisationPermissions.unit.test.tsx +2 -2
- package/src/hooks/__tests__/usePermissionCache.unit.test.ts +1 -1
- package/src/hooks/__tests__/useRBAC.unit.test.ts +191 -138
- package/src/hooks/public/usePublicEvent.ts +2 -2
- package/src/hooks/useAppConfig.ts +3 -3
- package/src/hooks/useComponentPerformance.ts +1 -1
- package/src/hooks/useDataTablePerformance.ts +1 -1
- package/src/hooks/useFileReference.ts +232 -0
- package/src/hooks/useOrganisationPermissions.test.ts +254 -344
- package/src/hooks/useOrganisationPermissions.ts +15 -7
- package/src/hooks/useOrganisationSecurity.test.ts +390 -402
- package/src/hooks/usePerformanceMonitor.ts +1 -1
- package/src/hooks/usePermissionCache.test.ts +264 -395
- package/src/hooks/usePermissionCache.ts +34 -4
- package/src/hooks/useSecureDataAccess.test.ts +486 -0
- package/src/hooks/useSecureDataAccess.ts +4 -1
- package/src/providers/InactivityProvider.tsx +2 -2
- package/src/providers/OrganisationProvider.test.simple.tsx +168 -0
- package/src/providers/OrganisationProvider.test.tsx +168 -0
- package/src/providers/OrganisationProvider.tsx +18 -31
- package/src/providers/UnifiedAuthProvider.test.simple.tsx +205 -0
- package/src/providers/UnifiedAuthProvider.test.tsx +128 -0
- package/src/providers/__tests__/InactivityProvider.test.tsx +3 -4
- package/src/providers/__tests__/OrganisationProvider.test.tsx +19 -14
- package/src/rbac/__tests__/integration.authflow.test.tsx +123 -0
- package/src/rbac/__tests__/integration.navigation.test.tsx +72 -0
- package/src/rbac/__tests__/integration.securedata.test.tsx +92 -0
- package/src/rbac/__tests__/integration.smoke.test.tsx +73 -0
- package/src/rbac/__tests__/rbac-core.test.tsx +26 -22
- package/src/rbac/__tests__/rbac-engine-core-logic.test.ts +411 -0
- package/src/rbac/__tests__/rbac-engine-simplified.test.ts +285 -0
- package/src/rbac/__tests__/rbac-functions.test.ts +655 -0
- package/src/rbac/__tests__/rbac-integration.test.ts +532 -0
- package/src/rbac/__tests__/scenarios.user-role.test.tsx +196 -0
- package/src/rbac/api.test.ts +6 -6
- package/src/rbac/api.ts +2 -2
- package/src/rbac/audit.test.ts +485 -0
- package/src/rbac/audit.ts +7 -1
- package/src/rbac/cache-invalidation.ts +318 -0
- package/src/rbac/cache.test.ts +286 -0
- package/src/rbac/components/EnhancedNavigationMenu.test.tsx +559 -0
- package/src/rbac/components/EnhancedNavigationMenu.tsx +29 -23
- package/src/rbac/components/NavigationProvider.test.tsx +449 -0
- package/src/rbac/components/PagePermissionGuard.tsx +4 -4
- package/src/rbac/components/PagePermissionProvider.test.tsx +479 -0
- package/src/rbac/components/SecureDataProvider.test.tsx +511 -0
- package/src/rbac/components/__tests__/PagePermissionGuard.race-condition.test.tsx +159 -430
- package/src/rbac/components/__tests__/PagePermissionGuard.test.tsx +4 -5
- package/src/rbac/components/__tests__/PagePermissionGuard.verification.test.tsx +112 -118
- package/src/rbac/config.test.ts +410 -0
- package/src/rbac/engine.test.simple.ts +237 -0
- package/src/rbac/engine.test.ts +233 -0
- package/src/rbac/engine.ts +37 -41
- package/src/rbac/examples/CompleteRBACExample.tsx +3 -3
- package/src/rbac/examples/EventBasedApp.tsx +4 -4
- package/src/rbac/hooks/useRBAC.simple.test.ts +16 -0
- package/src/rbac/hooks/useRBAC.test.ts +207 -455
- package/src/rbac/hooks/useRBAC.ts +30 -22
- package/src/rbac/permissions.test.ts +128 -0
- package/src/rbac/permissions.ts +56 -141
- package/src/rbac/providers/RBACProvider.tsx +1 -1
- package/src/rbac/secureClient.test.ts +444 -0
- package/src/rbac/security.test.ts +390 -0
- package/src/rbac/security.ts +1 -1
- package/src/rbac/types.test.ts +382 -0
- package/src/rbac/types.ts +2 -2
- package/src/styles/base.css +208 -0
- package/src/styles/core.css +0 -125
- package/src/styles/semantic.css +24 -0
- package/src/types/file-reference.ts +77 -0
- package/src/types/rbac-functions.ts +290 -0
- package/src/types/supabase.ts +10 -28
- package/src/types/unified.ts +4 -1
- package/src/utils/__tests__/bundleAnalysis.unit.test.ts +81 -55
- package/src/utils/__tests__/lazyLoad.unit.test.tsx +21 -12
- package/src/utils/__tests__/organisationContext.unit.test.ts +13 -7
- package/src/utils/__tests__/performanceBudgets.unit.test.ts +3 -3
- package/src/utils/__tests__/sessionTracking.unit.test.ts +32 -12
- package/src/utils/appConfig.ts +1 -1
- package/src/utils/appIdResolver.test.ts +503 -0
- package/src/utils/appIdResolver.ts +1 -1
- package/src/utils/appNameResolver.test.ts +494 -0
- package/src/utils/appNameResolver.ts +3 -2
- package/src/utils/bundleAnalysis.ts +3 -3
- package/src/utils/debugLogger.ts +1 -1
- package/src/utils/file-reference.ts +263 -0
- package/src/utils/formatDate.test.ts +2 -2
- package/src/utils/organisationContext.test.ts +340 -0
- package/src/utils/organisationContext.ts +19 -6
- package/src/utils/performanceBudgets.ts +2 -2
- package/src/utils/permissionUtils.test.ts +393 -0
- package/src/utils/permissionUtils.ts +5 -2
- package/src/utils/secureDataAccess.test.ts +715 -0
- package/src/utils/secureDataAccess.ts +21 -5
- package/src/utils/sessionTracking.ts +34 -4
- package/src/utils/storage/__tests__/helpers.unit.test.ts +328 -0
- package/src/utils/storage/__tests__/index.unit.test.ts +16 -0
- package/src/utils/storage/helpers.ts +20 -25
- package/src/utils/storage/index.ts +29 -1
- package/src/vite-env.d.ts +17 -0
- package/dist/chunk-22KLBHPS.js.map +0 -1
- package/dist/chunk-7BNPOCLL.js.map +0 -1
- package/dist/chunk-BC3S53OZ.js.map +0 -1
- package/dist/chunk-GWSBHC4J.js.map +0 -1
- package/dist/chunk-MYP2EGHX.js.map +0 -1
- package/dist/chunk-MZBUOP4P.js.map +0 -1
- package/dist/chunk-NYUJ4FJR.js.map +0 -1
- package/dist/chunk-NZ655MWE.js.map +0 -1
- package/dist/chunk-SS3E6QLB.js.map +0 -1
- package/dist/chunk-TRIZ7IB7.js.map +0 -1
- package/dist/chunk-WJARTBCT.js.map +0 -1
- package/dist/chunk-YDJW5XTN.js.map +0 -1
- package/docs/print-components/README.md +0 -258
- package/docs/print-components/api-reference.md +0 -636
- package/docs/print-components/examples/README.md +0 -204
- package/docs/print-components/examples/basic-report.tsx +0 -92
- package/docs/print-components/examples/card-catalog.tsx +0 -149
- package/docs/print-components/examples/cover-page-report.tsx +0 -163
- package/docs/print-components/quick-start.md +0 -363
- package/src/components/PrintButton/PrintButton.tsx +0 -321
- package/src/components/PrintButton/PrintButtonGroup.tsx +0 -84
- package/src/components/PrintButton/PrintToolbar.tsx +0 -94
- package/src/components/PrintButton/__tests__/PrintButton.test.tsx +0 -271
- package/src/components/PrintButton/examples/PrintButtonShowcase.tsx +0 -438
- package/src/components/PrintButton/index.ts +0 -33
- package/src/components/PrintButton/types.ts +0 -173
- package/src/components/PrintCard/PrintCard.tsx +0 -154
- package/src/components/PrintCard/PrintCardContent.tsx +0 -57
- package/src/components/PrintCard/PrintCardFooter.tsx +0 -60
- package/src/components/PrintCard/PrintCardGrid.tsx +0 -91
- package/src/components/PrintCard/PrintCardHeader.tsx +0 -78
- package/src/components/PrintCard/PrintCardImage.tsx +0 -81
- package/src/components/PrintCard/examples/PrintCardShowcase.tsx +0 -239
- package/src/components/PrintCard/index.ts +0 -34
- package/src/components/PrintCard/types.ts +0 -171
- package/src/components/PrintDataTable/PrintDataTable.tsx +0 -215
- package/src/components/PrintDataTable/PrintTableGroup.tsx +0 -90
- package/src/components/PrintDataTable/PrintTableRow.tsx +0 -76
- package/src/components/PrintDataTable/index.ts +0 -25
- package/src/components/PrintDataTable/types.ts +0 -67
- package/src/components/PrintFooter/PrintFooter.tsx +0 -183
- package/src/components/PrintFooter/PrintFooterContent.tsx +0 -71
- package/src/components/PrintFooter/PrintFooterInfo.tsx +0 -86
- package/src/components/PrintFooter/PrintPageNumber.tsx +0 -90
- package/src/components/PrintFooter/examples/PrintFooterShowcase.tsx +0 -390
- package/src/components/PrintFooter/index.ts +0 -30
- package/src/components/PrintFooter/types.ts +0 -149
- package/src/components/PrintGrid/PrintGrid.tsx +0 -180
- package/src/components/PrintGrid/PrintGridBreakpoint.tsx +0 -109
- package/src/components/PrintGrid/PrintGridContainer.tsx +0 -128
- package/src/components/PrintGrid/PrintGridItem.tsx +0 -220
- package/src/components/PrintGrid/examples/PrintGridShowcase.tsx +0 -359
- package/src/components/PrintGrid/index.ts +0 -31
- package/src/components/PrintGrid/types.ts +0 -159
- package/src/components/PrintHeader/PrintCoverHeader.tsx +0 -230
- package/src/components/PrintHeader/PrintHeader.tsx +0 -150
- package/src/components/PrintHeader/index.ts +0 -17
- package/src/components/PrintHeader/types.ts +0 -42
- package/src/components/PrintLayout/PrintLayout.tsx +0 -122
- package/src/components/PrintLayout/PrintLayoutContext.tsx +0 -66
- package/src/components/PrintLayout/PrintPageBreak.tsx +0 -52
- package/src/components/PrintLayout/examples/PrintShowcase.tsx +0 -230
- package/src/components/PrintLayout/index.ts +0 -19
- package/src/components/PrintLayout/types.ts +0 -37
- package/src/components/PrintPageBreak/PrintPageBreak.tsx +0 -120
- package/src/components/PrintPageBreak/PrintPageBreakGroup.tsx +0 -90
- package/src/components/PrintPageBreak/PrintPageBreakIndicator.tsx +0 -112
- package/src/components/PrintPageBreak/examples/PrintPageBreakShowcase.tsx +0 -279
- package/src/components/PrintPageBreak/index.ts +0 -23
- package/src/components/PrintPageBreak/types.ts +0 -94
- package/src/components/PrintSection/PrintColumn.tsx +0 -104
- package/src/components/PrintSection/PrintDivider.tsx +0 -101
- package/src/components/PrintSection/PrintSection.tsx +0 -129
- package/src/components/PrintSection/PrintSectionContent.tsx +0 -75
- package/src/components/PrintSection/PrintSectionHeader.tsx +0 -97
- package/src/components/PrintSection/examples/PrintSectionShowcase.tsx +0 -258
- package/src/components/PrintSection/index.ts +0 -33
- package/src/components/PrintSection/types.ts +0 -155
- package/src/components/PrintText/PrintText.tsx +0 -116
- package/src/components/PrintText/index.ts +0 -16
- package/src/components/PrintText/types.ts +0 -24
- package/src/rbac/__tests__/integration.test.tsx +0 -218
- package/src/utils/print/PrintDataProcessor.ts +0 -390
- package/src/utils/print/examples/PrintUtilitiesShowcase.tsx +0 -397
- package/src/utils/print/index.ts +0 -29
- package/src/utils/print/types.ts +0 -196
- package/src/utils/print/usePrintOptimization.ts +0 -272
- /package/dist/{DataTable-7FMFXA7A.js.map → DataTable-4T627QFJ.js.map} +0 -0
- /package/dist/{api-H5A3H4IR.js.map → api-LUNF5O6M.js.map} +0 -0
- /package/dist/{appNameResolver-7GHF5ED2.js.map → appNameResolver-UURKN7NF.js.map} +0 -0
- /package/dist/{audit-BUW3LMJB.js.map → audit-6TOCAMKO.js.map} +0 -0
- /package/dist/{chunk-NRK4AIHQ.js.map → chunk-KBRACSJI.js.map} +0 -0
- /package/dist/{chunk-6MTY77WU.js.map → chunk-TNMXZLDR.js.map} +0 -0
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file RBAC Functions Unit Tests
|
|
3
|
+
* @package @jmruthers/pace-core
|
|
4
|
+
* @module RBAC/Tests
|
|
5
|
+
* @since 1.0.0
|
|
6
|
+
*
|
|
7
|
+
* Comprehensive unit tests for all standardized RBAC functions.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
11
|
+
import { createClient } from '@supabase/supabase-js';
|
|
12
|
+
|
|
13
|
+
// Mock Supabase client
|
|
14
|
+
const mockSupabase = {
|
|
15
|
+
rpc: vi.fn(),
|
|
16
|
+
from: vi.fn(() => ({
|
|
17
|
+
select: vi.fn(() => ({
|
|
18
|
+
eq: vi.fn(() => ({
|
|
19
|
+
single: vi.fn()
|
|
20
|
+
}))
|
|
21
|
+
}))
|
|
22
|
+
}))
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Mock data
|
|
26
|
+
const mockUser = {
|
|
27
|
+
id: 'user-123',
|
|
28
|
+
email: 'test@example.com'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const mockOrganisation = {
|
|
32
|
+
id: 'org-123',
|
|
33
|
+
name: 'Test Organisation'
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const mockEvent = {
|
|
37
|
+
id: 'event-123',
|
|
38
|
+
name: 'Test Event',
|
|
39
|
+
organisation_id: 'org-123'
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const mockApp = {
|
|
43
|
+
id: 'app-123',
|
|
44
|
+
name: 'CAKE',
|
|
45
|
+
is_active: true
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
describe('RBAC Functions', () => {
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
vi.clearAllMocks();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
vi.restoreAllMocks();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('rbac_permission_check', () => {
|
|
58
|
+
it('should return false for null user_id', async () => {
|
|
59
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
60
|
+
data: [{ has_permission: false, role_name: null, permission_source: 'none', granted_at: null }],
|
|
61
|
+
error: null
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const result = await mockSupabase.rpc('rbac_permission_check', {
|
|
65
|
+
p_operation: 'read',
|
|
66
|
+
p_page_name: 'dashboard',
|
|
67
|
+
p_user_id: null
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(result.data[0].has_permission).toBe(false);
|
|
71
|
+
expect(result.data[0].permission_source).toBe('none');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should return true for super admin', async () => {
|
|
75
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
76
|
+
data: [{ has_permission: true, role_name: 'super_admin', permission_source: 'global', granted_at: expect.any(String) }],
|
|
77
|
+
error: null
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const result = await mockSupabase.rpc('rbac_permission_check', {
|
|
81
|
+
p_operation: 'read',
|
|
82
|
+
p_page_name: 'dashboard',
|
|
83
|
+
p_user_id: mockUser.id
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
expect(result.data[0].has_permission).toBe(true);
|
|
87
|
+
expect(result.data[0].role_name).toBe('super_admin');
|
|
88
|
+
expect(result.data[0].permission_source).toBe('global');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should return true for organisation admin', async () => {
|
|
92
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
93
|
+
data: [{ has_permission: true, role_name: 'org_admin', permission_source: 'organisation', granted_at: expect.any(String) }],
|
|
94
|
+
error: null
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const result = await mockSupabase.rpc('rbac_permission_check', {
|
|
98
|
+
p_operation: 'read',
|
|
99
|
+
p_page_name: 'dashboard',
|
|
100
|
+
p_user_id: mockUser.id,
|
|
101
|
+
p_organisation_id: mockOrganisation.id
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(result.data[0].has_permission).toBe(true);
|
|
105
|
+
expect(result.data[0].role_name).toBe('org_admin');
|
|
106
|
+
expect(result.data[0].permission_source).toBe('organisation');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should return false for invalid permission', async () => {
|
|
110
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
111
|
+
data: [{ has_permission: false, role_name: null, permission_source: 'none', granted_at: null }],
|
|
112
|
+
error: null
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const result = await mockSupabase.rpc('rbac_permission_check', {
|
|
116
|
+
p_operation: 'delete',
|
|
117
|
+
p_page_name: 'admin-panel',
|
|
118
|
+
p_user_id: mockUser.id,
|
|
119
|
+
p_organisation_id: mockOrganisation.id
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(result.data[0].has_permission).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('rbac_permissions_get', () => {
|
|
127
|
+
it('should return all permissions for super admin', async () => {
|
|
128
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
129
|
+
data: [{
|
|
130
|
+
permission_type: 'all_permissions',
|
|
131
|
+
role_name: 'super_admin',
|
|
132
|
+
has_permission: true,
|
|
133
|
+
granted_at: expect.any(String),
|
|
134
|
+
context_id: 'global'
|
|
135
|
+
}],
|
|
136
|
+
error: null
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const result = await mockSupabase.rpc('rbac_permissions_get', {
|
|
140
|
+
p_user_id: mockUser.id
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
expect(result.data[0].permission_type).toBe('all_permissions');
|
|
144
|
+
expect(result.data[0].role_name).toBe('super_admin');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should return organisation permissions', async () => {
|
|
148
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
149
|
+
data: [{
|
|
150
|
+
permission_type: 'organisation_access',
|
|
151
|
+
role_name: 'member',
|
|
152
|
+
has_permission: true,
|
|
153
|
+
granted_at: expect.any(String),
|
|
154
|
+
context_id: mockOrganisation.id
|
|
155
|
+
}],
|
|
156
|
+
error: null
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const result = await mockSupabase.rpc('rbac_permissions_get', {
|
|
160
|
+
p_user_id: mockUser.id,
|
|
161
|
+
p_organisation_id: mockOrganisation.id
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(result.data[0].permission_type).toBe('organisation_access');
|
|
165
|
+
expect(result.data[0].role_name).toBe('member');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('should return empty array for null user_id', async () => {
|
|
169
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
170
|
+
data: [],
|
|
171
|
+
error: null
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const result = await mockSupabase.rpc('rbac_permissions_get', {
|
|
175
|
+
p_user_id: null
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
expect(result.data).toEqual([]);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('rbac_access_validate', () => {
|
|
183
|
+
it('should return false for null user_id', async () => {
|
|
184
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
185
|
+
data: [{ has_access: false, access_level: 'none', context_id: null }],
|
|
186
|
+
error: null
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const result = await mockSupabase.rpc('rbac_access_validate', {
|
|
190
|
+
p_resource_type: 'organisation',
|
|
191
|
+
p_resource_id: mockOrganisation.id,
|
|
192
|
+
p_user_id: null
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
expect(result.data[0].has_access).toBe(false);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should return true for super admin', async () => {
|
|
199
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
200
|
+
data: [{ has_access: true, access_level: 'super_admin', context_id: 'global' }],
|
|
201
|
+
error: null
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
const result = await mockSupabase.rpc('rbac_access_validate', {
|
|
205
|
+
p_resource_type: 'organisation',
|
|
206
|
+
p_resource_id: mockOrganisation.id,
|
|
207
|
+
p_user_id: mockUser.id
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
expect(result.data[0].has_access).toBe(true);
|
|
211
|
+
expect(result.data[0].access_level).toBe('super_admin');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('should validate organisation access', async () => {
|
|
215
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
216
|
+
data: [{ has_access: true, access_level: 'organisation', context_id: mockOrganisation.id }],
|
|
217
|
+
error: null
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const result = await mockSupabase.rpc('rbac_access_validate', {
|
|
221
|
+
p_resource_type: 'organisation',
|
|
222
|
+
p_resource_id: mockOrganisation.id,
|
|
223
|
+
p_user_id: mockUser.id
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
expect(result.data[0].has_access).toBe(true);
|
|
227
|
+
expect(result.data[0].access_level).toBe('organisation');
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('should validate event access', async () => {
|
|
231
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
232
|
+
data: [{ has_access: true, access_level: 'event', context_id: mockEvent.id }],
|
|
233
|
+
error: null
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const result = await mockSupabase.rpc('rbac_access_validate', {
|
|
237
|
+
p_resource_type: 'event',
|
|
238
|
+
p_resource_id: mockEvent.id,
|
|
239
|
+
p_user_id: mockUser.id
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
expect(result.data[0].has_access).toBe(true);
|
|
243
|
+
expect(result.data[0].access_level).toBe('event');
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
describe('rbac_page_access_check', () => {
|
|
248
|
+
it('should return false for invalid access', async () => {
|
|
249
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
250
|
+
data: false,
|
|
251
|
+
error: null
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const result = await mockSupabase.rpc('rbac_page_access_check', {
|
|
255
|
+
p_app_id: mockApp.id,
|
|
256
|
+
p_page_id: 'admin-panel',
|
|
257
|
+
p_operation: 'delete',
|
|
258
|
+
p_user_id: mockUser.id
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
expect(result.data).toBe(false);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('should return true for valid access', async () => {
|
|
265
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
266
|
+
data: true,
|
|
267
|
+
error: null
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
const result = await mockSupabase.rpc('rbac_page_access_check', {
|
|
271
|
+
p_app_id: mockApp.id,
|
|
272
|
+
p_page_id: 'dashboard',
|
|
273
|
+
p_operation: 'read',
|
|
274
|
+
p_user_id: mockUser.id
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
expect(result.data).toBe(true);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe('rbac_role_grant', () => {
|
|
282
|
+
it('should grant global role successfully', async () => {
|
|
283
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
284
|
+
data: [{
|
|
285
|
+
success: true,
|
|
286
|
+
message: 'Role granted successfully',
|
|
287
|
+
role_id: 'role-123',
|
|
288
|
+
error_code: null
|
|
289
|
+
}],
|
|
290
|
+
error: null
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
const result = await mockSupabase.rpc('rbac_role_grant', {
|
|
294
|
+
p_user_id: mockUser.id,
|
|
295
|
+
p_role_type: 'global',
|
|
296
|
+
p_role_name: 'super_admin',
|
|
297
|
+
p_granted_by: 'admin-123'
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
expect(result.data[0].success).toBe(true);
|
|
301
|
+
expect(result.data[0].role_id).toBe('role-123');
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('should grant organisation role successfully', async () => {
|
|
305
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
306
|
+
data: [{
|
|
307
|
+
success: true,
|
|
308
|
+
message: 'Role granted successfully',
|
|
309
|
+
role_id: 'role-456',
|
|
310
|
+
error_code: null
|
|
311
|
+
}],
|
|
312
|
+
error: null
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
const result = await mockSupabase.rpc('rbac_role_grant', {
|
|
316
|
+
p_user_id: mockUser.id,
|
|
317
|
+
p_role_type: 'organisation',
|
|
318
|
+
p_role_name: 'member',
|
|
319
|
+
p_context_id: mockOrganisation.id,
|
|
320
|
+
p_granted_by: 'admin-123'
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
expect(result.data[0].success).toBe(true);
|
|
324
|
+
expect(result.data[0].role_id).toBe('role-456');
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('should grant event-app role successfully', async () => {
|
|
328
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
329
|
+
data: [{
|
|
330
|
+
success: true,
|
|
331
|
+
message: 'Role granted successfully',
|
|
332
|
+
role_id: 'role-789',
|
|
333
|
+
error_code: null
|
|
334
|
+
}],
|
|
335
|
+
error: null
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
const result = await mockSupabase.rpc('rbac_role_grant', {
|
|
339
|
+
p_user_id: mockUser.id,
|
|
340
|
+
p_role_type: 'event_app',
|
|
341
|
+
p_role_name: 'participant',
|
|
342
|
+
p_context_id: `${mockEvent.id}:${mockApp.id}`,
|
|
343
|
+
p_granted_by: 'admin-123'
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
expect(result.data[0].success).toBe(true);
|
|
347
|
+
expect(result.data[0].role_id).toBe('role-789');
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('should return error for invalid role type', async () => {
|
|
351
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
352
|
+
data: [{
|
|
353
|
+
success: false,
|
|
354
|
+
message: 'Invalid role type',
|
|
355
|
+
role_id: null,
|
|
356
|
+
error_code: 'INVALID_ROLE_TYPE'
|
|
357
|
+
}],
|
|
358
|
+
error: null
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
const result = await mockSupabase.rpc('rbac_role_grant', {
|
|
362
|
+
p_user_id: mockUser.id,
|
|
363
|
+
p_role_type: 'invalid',
|
|
364
|
+
p_role_name: 'member'
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
expect(result.data[0].success).toBe(false);
|
|
368
|
+
expect(result.data[0].error_code).toBe('INVALID_ROLE_TYPE');
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it('should return error for missing organisation ID', async () => {
|
|
372
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
373
|
+
data: [{
|
|
374
|
+
success: false,
|
|
375
|
+
message: 'Organisation ID required',
|
|
376
|
+
role_id: null,
|
|
377
|
+
error_code: 'MISSING_ORGANISATION_ID'
|
|
378
|
+
}],
|
|
379
|
+
error: null
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
const result = await mockSupabase.rpc('rbac_role_grant', {
|
|
383
|
+
p_user_id: mockUser.id,
|
|
384
|
+
p_role_type: 'organisation',
|
|
385
|
+
p_role_name: 'member',
|
|
386
|
+
p_context_id: null
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
expect(result.data[0].success).toBe(false);
|
|
390
|
+
expect(result.data[0].error_code).toBe('MISSING_ORGANISATION_ID');
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
describe('rbac_role_revoke', () => {
|
|
395
|
+
it('should revoke role successfully', async () => {
|
|
396
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
397
|
+
data: [{
|
|
398
|
+
success: true,
|
|
399
|
+
message: 'Role revoked successfully',
|
|
400
|
+
revoked_count: 1,
|
|
401
|
+
error_code: null
|
|
402
|
+
}],
|
|
403
|
+
error: null
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
const result = await mockSupabase.rpc('rbac_role_revoke', {
|
|
407
|
+
p_user_id: mockUser.id,
|
|
408
|
+
p_role_type: 'organisation',
|
|
409
|
+
p_role_name: 'member',
|
|
410
|
+
p_context_id: mockOrganisation.id,
|
|
411
|
+
p_revoked_by: 'admin-123'
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
expect(result.data[0].success).toBe(true);
|
|
415
|
+
expect(result.data[0].revoked_count).toBe(1);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it('should return error for role not found', async () => {
|
|
419
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
420
|
+
data: [{
|
|
421
|
+
success: false,
|
|
422
|
+
message: 'No matching role found',
|
|
423
|
+
revoked_count: 0,
|
|
424
|
+
error_code: 'ROLE_NOT_FOUND'
|
|
425
|
+
}],
|
|
426
|
+
error: null
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
const result = await mockSupabase.rpc('rbac_role_revoke', {
|
|
430
|
+
p_user_id: mockUser.id,
|
|
431
|
+
p_role_type: 'organisation',
|
|
432
|
+
p_role_name: 'nonexistent',
|
|
433
|
+
p_context_id: mockOrganisation.id
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
expect(result.data[0].success).toBe(false);
|
|
437
|
+
expect(result.data[0].error_code).toBe('ROLE_NOT_FOUND');
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
describe('rbac_roles_list', () => {
|
|
442
|
+
it('should list all user roles', async () => {
|
|
443
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
444
|
+
data: [
|
|
445
|
+
{
|
|
446
|
+
role_type: 'global',
|
|
447
|
+
role_name: 'super_admin',
|
|
448
|
+
context_id: 'system',
|
|
449
|
+
granted_at: expect.any(String),
|
|
450
|
+
status: 'active',
|
|
451
|
+
granted_by: 'admin-123'
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
role_type: 'organisation',
|
|
455
|
+
role_name: 'member',
|
|
456
|
+
context_id: mockOrganisation.id,
|
|
457
|
+
granted_at: expect.any(String),
|
|
458
|
+
status: 'active',
|
|
459
|
+
granted_by: 'admin-123'
|
|
460
|
+
}
|
|
461
|
+
],
|
|
462
|
+
error: null
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
const result = await mockSupabase.rpc('rbac_roles_list', {
|
|
466
|
+
p_user_id: mockUser.id
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
expect(result.data).toHaveLength(2);
|
|
470
|
+
expect(result.data[0].role_type).toBe('global');
|
|
471
|
+
expect(result.data[1].role_type).toBe('organisation');
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it('should filter by organisation', async () => {
|
|
475
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
476
|
+
data: [{
|
|
477
|
+
role_type: 'organisation',
|
|
478
|
+
role_name: 'member',
|
|
479
|
+
context_id: mockOrganisation.id,
|
|
480
|
+
granted_at: expect.any(String),
|
|
481
|
+
status: 'active',
|
|
482
|
+
granted_by: 'admin-123'
|
|
483
|
+
}],
|
|
484
|
+
error: null
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
const result = await mockSupabase.rpc('rbac_roles_list', {
|
|
488
|
+
p_user_id: mockUser.id,
|
|
489
|
+
p_organisation_id: mockOrganisation.id
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
expect(result.data).toHaveLength(1);
|
|
493
|
+
expect(result.data[0].role_type).toBe('organisation');
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
describe('rbac_role_validate', () => {
|
|
498
|
+
it('should validate active role', async () => {
|
|
499
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
500
|
+
data: [{
|
|
501
|
+
is_valid: true,
|
|
502
|
+
role_id: 'role-123',
|
|
503
|
+
granted_at: expect.any(String),
|
|
504
|
+
expires_at: null,
|
|
505
|
+
status: 'active'
|
|
506
|
+
}],
|
|
507
|
+
error: null
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
const result = await mockSupabase.rpc('rbac_role_validate', {
|
|
511
|
+
p_user_id: mockUser.id,
|
|
512
|
+
p_role_type: 'organisation',
|
|
513
|
+
p_role_name: 'member',
|
|
514
|
+
p_context_id: mockOrganisation.id
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
expect(result.data[0].is_valid).toBe(true);
|
|
518
|
+
expect(result.data[0].status).toBe('active');
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it('should return false for invalid role', async () => {
|
|
522
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
523
|
+
data: [{
|
|
524
|
+
is_valid: false,
|
|
525
|
+
role_id: null,
|
|
526
|
+
granted_at: null,
|
|
527
|
+
expires_at: null,
|
|
528
|
+
status: 'invalid_type'
|
|
529
|
+
}],
|
|
530
|
+
error: null
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
const result = await mockSupabase.rpc('rbac_role_validate', {
|
|
534
|
+
p_user_id: mockUser.id,
|
|
535
|
+
p_role_type: 'invalid',
|
|
536
|
+
p_role_name: 'member'
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
expect(result.data[0].is_valid).toBe(false);
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
describe('rbac_session_track', () => {
|
|
544
|
+
it('should track session successfully', async () => {
|
|
545
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
546
|
+
data: [{
|
|
547
|
+
success: true,
|
|
548
|
+
session_id: 'session-123',
|
|
549
|
+
message: 'Session tracked successfully',
|
|
550
|
+
error_code: null
|
|
551
|
+
}],
|
|
552
|
+
error: null
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
const result = await mockSupabase.rpc('rbac_session_track', {
|
|
556
|
+
p_user_id: mockUser.id,
|
|
557
|
+
p_session_type: 'web',
|
|
558
|
+
p_event_id: mockEvent.id,
|
|
559
|
+
p_app_id: mockApp.id,
|
|
560
|
+
p_ip_address: '192.168.1.1',
|
|
561
|
+
p_user_agent: 'Mozilla/5.0...'
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
expect(result.data[0].success).toBe(true);
|
|
565
|
+
expect(result.data[0].session_id).toBe('session-123');
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it('should return error for unauthenticated user', async () => {
|
|
569
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
570
|
+
data: [{
|
|
571
|
+
success: false,
|
|
572
|
+
session_id: null,
|
|
573
|
+
message: 'User not authenticated',
|
|
574
|
+
error_code: 'USER_NOT_AUTHENTICATED'
|
|
575
|
+
}],
|
|
576
|
+
error: null
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
const result = await mockSupabase.rpc('rbac_session_track', {
|
|
580
|
+
p_user_id: null,
|
|
581
|
+
p_session_type: 'web'
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
expect(result.data[0].success).toBe(false);
|
|
585
|
+
expect(result.data[0].error_code).toBe('USER_NOT_AUTHENTICATED');
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it('should return error for invalid session type', async () => {
|
|
589
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
590
|
+
data: [{
|
|
591
|
+
success: false,
|
|
592
|
+
session_id: null,
|
|
593
|
+
message: 'Invalid session type',
|
|
594
|
+
error_code: 'INVALID_SESSION_TYPE'
|
|
595
|
+
}],
|
|
596
|
+
error: null
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
const result = await mockSupabase.rpc('rbac_session_track', {
|
|
600
|
+
p_user_id: mockUser.id,
|
|
601
|
+
p_session_type: 'invalid'
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
expect(result.data[0].success).toBe(false);
|
|
605
|
+
expect(result.data[0].error_code).toBe('INVALID_SESSION_TYPE');
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
describe('rbac_audit_log', () => {
|
|
610
|
+
it('should log audit event successfully', async () => {
|
|
611
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
612
|
+
data: [{
|
|
613
|
+
success: true,
|
|
614
|
+
audit_id: 'audit-123',
|
|
615
|
+
message: 'Audit event logged successfully',
|
|
616
|
+
error_code: null
|
|
617
|
+
}],
|
|
618
|
+
error: null
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
const result = await mockSupabase.rpc('rbac_audit_log', {
|
|
622
|
+
p_event_type: 'role_granted',
|
|
623
|
+
p_user_id: mockUser.id,
|
|
624
|
+
p_organisation_id: mockOrganisation.id,
|
|
625
|
+
p_permission: 'member',
|
|
626
|
+
p_metadata: { entity_type: 'organisation_role' },
|
|
627
|
+
p_ip_address: '192.168.1.1',
|
|
628
|
+
p_user_agent: 'Mozilla/5.0...'
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
expect(result.data[0].success).toBe(true);
|
|
632
|
+
expect(result.data[0].audit_id).toBe('audit-123');
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
it('should return error for invalid event type', async () => {
|
|
636
|
+
mockSupabase.rpc.mockResolvedValue({
|
|
637
|
+
data: [{
|
|
638
|
+
success: false,
|
|
639
|
+
audit_id: null,
|
|
640
|
+
message: 'Invalid event type',
|
|
641
|
+
error_code: 'INVALID_EVENT_TYPE'
|
|
642
|
+
}],
|
|
643
|
+
error: null
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
const result = await mockSupabase.rpc('rbac_audit_log', {
|
|
647
|
+
p_event_type: 'invalid_event',
|
|
648
|
+
p_user_id: mockUser.id
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
expect(result.data[0].success).toBe(false);
|
|
652
|
+
expect(result.data[0].error_code).toBe('INVALID_EVENT_TYPE');
|
|
653
|
+
});
|
|
654
|
+
});
|
|
655
|
+
});
|