@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.
- package/CHANGELOG.md +104 -0
- package/README.md +5 -403
- package/audit-tool/00-dependencies.cjs +394 -0
- package/audit-tool/audits/01-pace-core-compliance.cjs +556 -0
- package/audit-tool/audits/02-project-structure.cjs +255 -0
- package/audit-tool/audits/03-architecture.cjs +196 -0
- package/audit-tool/audits/04-code-quality.cjs +149 -0
- package/audit-tool/audits/05-styling.cjs +224 -0
- package/audit-tool/audits/06-security-rbac.cjs +544 -0
- package/audit-tool/audits/07-api-tech-stack.cjs +301 -0
- package/audit-tool/audits/08-testing-documentation.cjs +202 -0
- package/audit-tool/audits/09-operations.cjs +208 -0
- package/audit-tool/index.cjs +291 -0
- package/audit-tool/utils/code-utils.cjs +218 -0
- package/audit-tool/utils/file-utils.cjs +230 -0
- package/audit-tool/utils/report-utils.cjs +241 -0
- package/core-usage-manifest.json +93 -0
- package/cursor-rules/00-standards-overview.mdc +156 -0
- package/cursor-rules/01-pace-core-compliance.mdc +586 -0
- package/cursor-rules/02-project-structure.mdc +42 -4
- package/cursor-rules/{03-solid-principles.mdc → 03-architecture.mdc} +126 -10
- package/cursor-rules/04-code-quality.mdc +419 -0
- package/cursor-rules/{08-markup-quality.mdc → 05-styling.mdc} +104 -34
- package/cursor-rules/06-security-rbac.mdc +518 -0
- package/cursor-rules/07-api-tech-stack.mdc +377 -0
- package/cursor-rules/08-testing-documentation.mdc +324 -0
- package/cursor-rules/09-operations.mdc +365 -0
- package/dist/{AuthService-Cb34EQs3.d.ts → AuthService-DmfO5rGS.d.ts} +10 -0
- package/dist/DataTable-7PMH7XN7.js +15 -0
- package/dist/{DataTable-BMRU8a1j.d.ts → DataTable-DRUIgtUH.d.ts} +1 -1
- package/dist/{PublicPageProvider-QTFVrL-Z.d.ts → PublicPageProvider-DlsCaR5v.d.ts} +33 -72
- package/dist/UnifiedAuthProvider-ZT6TIGM7.js +7 -0
- package/dist/api-Y4MQWOFW.js +4 -0
- package/dist/audit-MYQXYZFU.js +3 -0
- package/dist/{chunk-DGUM43GV.js → chunk-3RG5ZIWI.js} +1 -4
- package/dist/{chunk-QXHPKYJV.js → chunk-4SXLQIZO.js} +1 -26
- package/dist/{chunk-UPPMRMYG.js → chunk-5X4QLXRG.js} +73 -151
- package/dist/chunk-6F3IILHI.js +62 -0
- package/dist/{chunk-E66EQZE6.js → chunk-6GLLNA6U.js} +3 -9
- package/dist/{chunk-ZSAAAMVR.js → chunk-6QYDGKQY.js} +1 -4
- package/dist/{chunk-FMUCXFII.js → chunk-7ILTDCL2.js} +9 -5
- package/dist/{chunk-M43Y4SSO.js → chunk-A3W6LW53.js} +15 -13
- package/dist/{chunk-63FOKYGO.js → chunk-AHU7G2R5.js} +2 -11
- package/dist/{chunk-HU2C6SSC.js → chunk-BM4CQ5P3.js} +606 -559
- package/dist/chunk-C7NSAPTL.js +1 -0
- package/dist/{chunk-J36DSWQK.js → chunk-FEJLJNWA.js} +7 -41
- package/dist/{chunk-IHB5DR3H.js → chunk-FTCRZOG2.js} +188 -387
- package/dist/{chunk-G37KK66H.js → chunk-FYHN4DD5.js} +60 -19
- package/dist/chunk-GHYHJTYV.js +994 -0
- package/dist/{chunk-VBXEHIUJ.js → chunk-HF6O3O37.js} +6 -88
- package/dist/{chunk-FFQEQTNW.js → chunk-IUBRCBSY.js} +134 -45
- package/dist/{chunk-6COVEUS7.js → chunk-JGWDVX64.js} +983 -1034
- package/dist/{chunk-RGAWHO7N.js → chunk-L4XMVJKY.js} +77 -222
- package/dist/chunk-MBADTM7L.js +64 -0
- package/dist/{chunk-M7MPQISP.js → chunk-OJ4SKRSV.js} +3 -16
- package/dist/{chunk-IVOFDYWT.js → chunk-Q7Q7V5NV.js} +2109 -1604
- package/dist/{chunk-JGRYX5UX.js → chunk-S7DKJPLT.js} +29 -58
- package/dist/{chunk-PWLANIRT.js → chunk-TTRFSOKR.js} +1 -7
- package/dist/{chunk-5DRSZLL2.js → chunk-UH3NTO3F.js} +1 -6
- package/dist/{chunk-NTM7ZSB6.js → chunk-VBCS3DUA.js} +261 -168
- package/dist/{chunk-EFN2EIMK.js → chunk-ZFYPMX46.js} +271 -87
- package/dist/{chunk-L4OXEN46.js → chunk-ZKAWKYT4.js} +10 -24
- package/dist/components.d.ts +7 -5
- package/dist/components.js +46 -257
- package/dist/{database.generated-CzIvgcPu.d.ts → database.generated-CcnC_DRc.d.ts} +4795 -3691
- package/dist/eslint-rules/index.cjs +35 -0
- package/{src/eslint-rules/pace-core-compliance.cjs → dist/eslint-rules/rules/01-pace-core-compliance.cjs} +234 -235
- package/dist/eslint-rules/rules/04-code-quality.cjs +290 -0
- package/dist/eslint-rules/rules/05-styling.cjs +61 -0
- package/dist/eslint-rules/rules/06-security-rbac.cjs +806 -0
- package/dist/eslint-rules/rules/07-api-tech-stack.cjs +263 -0
- package/dist/eslint-rules/rules/08-testing.cjs +94 -0
- package/dist/eslint-rules/utils/helpers.cjs +42 -0
- package/dist/eslint-rules/utils/manifest-loader.cjs +75 -0
- package/dist/hooks.d.ts +6 -6
- package/dist/hooks.js +62 -172
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +1 -0
- package/dist/index.d.ts +12 -11
- package/dist/index.js +67 -660
- package/dist/providers.d.ts +2 -2
- package/dist/providers.js +8 -35
- package/dist/rbac/eslint-rules.d.ts +46 -44
- package/dist/rbac/eslint-rules.js +7 -4
- package/dist/rbac/index.d.ts +109 -586
- package/dist/rbac/index.js +14 -207
- package/dist/styles/index.js +2 -12
- package/dist/theming/runtime.d.ts +14 -1
- package/dist/theming/runtime.js +3 -19
- package/dist/{timezone-CHhWg6b4.d.ts → timezone-BZe_eUxx.d.ts} +175 -1
- package/dist/{types-CkbwOr4Y.d.ts → types-DXstZpNI.d.ts} +4 -17
- package/dist/types-t9H8qKRw.d.ts +55 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.js +7 -94
- package/dist/{usePublicRouteParams-ClnV4tnv.d.ts → usePublicRouteParams-MamNgwqe.d.ts} +20 -20
- package/dist/utils.d.ts +24 -117
- package/dist/utils.js +54 -392
- package/docs/README.md +17 -7
- package/docs/api/README.md +4 -402
- package/docs/api/modules.md +301 -871
- package/docs/api-reference/components.md +21 -21
- package/docs/api-reference/deprecated.md +31 -6
- package/docs/api-reference/hooks.md +80 -80
- package/docs/api-reference/rpc-functions.md +78 -3
- package/docs/api-reference/types.md +1 -1
- package/docs/api-reference/utilities.md +1 -1
- package/docs/architecture/README.md +1 -1
- package/docs/core-concepts/events.md +3 -3
- package/docs/core-concepts/organisations.md +6 -6
- package/docs/core-concepts/permissions.md +6 -6
- package/docs/documentation-index.md +12 -18
- package/docs/getting-started/cursor-rules.md +3 -23
- package/docs/getting-started/dependencies.md +650 -0
- package/docs/getting-started/documentation-index.md +1 -1
- package/docs/getting-started/examples/README.md +4 -4
- package/docs/getting-started/examples/full-featured-app.md +1 -1
- package/docs/getting-started/faq.md +2 -2
- package/docs/getting-started/installation-guide.md +20 -7
- package/docs/getting-started/quick-reference.md +4 -4
- package/docs/getting-started/quick-start.md +23 -12
- package/docs/implementation-guides/authentication.md +15 -15
- package/docs/implementation-guides/component-styling.md +1 -1
- package/docs/implementation-guides/data-tables.md +126 -33
- package/docs/implementation-guides/datatable-rbac-usage.md +1 -1
- package/docs/implementation-guides/dynamic-colors.md +3 -3
- package/docs/implementation-guides/file-upload-storage.md +2 -2
- package/docs/implementation-guides/hierarchical-datatable.md +40 -60
- package/docs/implementation-guides/inactivity-tracking.md +3 -3
- package/docs/implementation-guides/large-datasets.md +3 -2
- package/docs/implementation-guides/organisation-security.md +2 -2
- package/docs/implementation-guides/performance.md +2 -2
- package/docs/implementation-guides/permission-enforcement.md +5 -1
- package/docs/migration/V0.3.44_organisation-context-timing-fix.md +1 -1
- package/docs/migration/V0.4.0_rbac-migration.md +6 -6
- package/docs/rbac/MIGRATION_GUIDE.md +819 -0
- package/docs/rbac/RBAC_CONTRACT.md +724 -0
- package/docs/rbac/README.md +17 -8
- package/docs/rbac/advanced-patterns.md +6 -6
- package/docs/rbac/api-reference.md +20 -20
- package/docs/rbac/edge-functions-guide.md +376 -0
- package/docs/rbac/event-based-apps.md +3 -3
- package/docs/rbac/examples.md +41 -41
- package/docs/rbac/getting-started.md +37 -37
- package/docs/rbac/performance.md +1 -1
- package/docs/rbac/quick-start.md +52 -52
- package/docs/rbac/secure-client-protection.md +1 -35
- package/docs/rbac/troubleshooting.md +1 -1
- package/docs/security/README.md +5 -5
- package/docs/standards/0-standards-overview.md +220 -0
- package/docs/standards/1-pace-core-compliance-standards.md +986 -0
- package/docs/standards/2-project-structure-standards.md +949 -0
- package/docs/standards/3-architecture-standards.md +606 -0
- package/docs/standards/4-code-quality-standards.md +728 -0
- package/docs/standards/5-styling-standards.md +348 -0
- package/docs/standards/{07-rbac-and-rls-standard.md → 6-security-rbac-standards.md} +269 -66
- package/docs/standards/7-api-tech-stack-standards.md +662 -0
- package/docs/standards/8-testing-documentation-standards.md +401 -0
- package/docs/standards/9-operations-standards.md +1102 -0
- package/docs/standards/README.md +185 -57
- package/docs/troubleshooting/README.md +4 -4
- package/docs/troubleshooting/common-issues.md +2 -2
- package/docs/troubleshooting/debugging.md +9 -9
- package/docs/troubleshooting/migration.md +4 -4
- package/docs/troubleshooting/organisation-context-setup.md +42 -19
- package/eslint-config-pace-core.cjs +33 -6
- package/package.json +35 -23
- package/scripts/install-cursor-rules.cjs +25 -6
- package/scripts/install-eslint-config.cjs +284 -0
- package/src/__tests__/fixtures/supabase.ts +1 -1
- package/src/__tests__/helpers/__tests__/component-test-utils.test.tsx +3 -3
- package/src/__tests__/helpers/__tests__/optimized-test-setup.test.ts +1 -1
- package/src/__tests__/helpers/__tests__/supabaseMock.test.ts +1 -1
- package/src/__tests__/helpers/__tests__/test-providers.test.tsx +2 -2
- package/src/__tests__/helpers/__tests__/test-utils.test.tsx +13 -13
- package/src/__tests__/helpers/component-test-utils.tsx +1 -1
- package/src/__tests__/helpers/supabaseMock.ts +2 -2
- package/src/__tests__/integration/UserProfile.test.tsx +14 -14
- package/src/__tests__/public-recipe-view.test.ts +38 -9
- package/src/__tests__/rbac/PagePermissionGuard.test.tsx +6 -6
- package/src/__tests__/templates/accessibility.test.template.tsx +9 -9
- package/src/__tests__/templates/component.test.template.tsx +18 -15
- package/src/components/Button/Button.tsx +5 -1
- package/src/components/Calendar/Calendar.tsx +201 -47
- package/src/components/ContextSelector/ContextSelector.tsx +106 -119
- package/src/components/DataTable/AUDIT_REPORT.md +293 -0
- package/src/components/DataTable/__tests__/DataTableCore.test.tsx +10 -2
- package/src/components/DataTable/__tests__/a11y.basic.test.tsx +10 -4
- package/src/components/DataTable/__tests__/test-utils/sharedTestUtils.tsx +9 -9
- package/src/components/DataTable/components/ColumnFilter.tsx +63 -74
- package/src/components/DataTable/components/ColumnVisibilityDropdown.tsx +43 -41
- package/src/components/DataTable/components/DataTableCore.tsx +186 -13
- package/src/components/DataTable/components/DataTableErrorBoundary.tsx +9 -11
- package/src/components/DataTable/components/DataTableLayout.tsx +35 -21
- package/src/components/DataTable/components/EditFields.tsx +23 -3
- package/src/components/DataTable/components/EditableRow.tsx +12 -9
- package/src/components/DataTable/components/EmptyState.tsx +10 -9
- package/src/components/DataTable/components/FilterRow.tsx +2 -4
- package/src/components/DataTable/components/ImportModal.tsx +124 -126
- package/src/components/DataTable/components/LoadingState.tsx +5 -6
- package/src/components/DataTable/components/RowComponent.tsx +12 -0
- package/src/components/DataTable/components/SortIndicator.tsx +50 -0
- package/src/components/DataTable/components/__tests__/COVERAGE_NOTE.md +4 -4
- package/src/components/DataTable/components/__tests__/ColumnFilter.test.tsx +23 -82
- package/src/components/DataTable/components/__tests__/DataTableErrorBoundary.test.tsx +37 -9
- package/src/components/DataTable/components/__tests__/EmptyState.test.tsx +7 -4
- package/src/components/DataTable/components/__tests__/FilterRow.test.tsx +12 -4
- package/src/components/DataTable/components/__tests__/LoadingState.test.tsx +41 -27
- package/src/components/DataTable/components/hooks/usePermissionTracking.ts +0 -4
- package/src/components/DataTable/components/index.ts +2 -1
- package/src/components/DataTable/hooks/__tests__/useDataTableState.test.ts +51 -47
- package/src/components/DataTable/hooks/useDataTablePermissions.ts +24 -21
- package/src/components/DataTable/hooks/useDataTableState.ts +125 -9
- package/src/components/DataTable/hooks/useTableColumns.ts +40 -2
- package/src/components/DataTable/hooks/useTableHandlers.ts +11 -0
- package/src/components/DataTable/types.ts +5 -18
- package/src/components/DataTable/utils/a11yUtils.ts +17 -0
- package/src/components/DatePickerWithTimezone/DatePickerWithTimezone.test.tsx +2 -1
- package/src/components/DatePickerWithTimezone/DatePickerWithTimezone.tsx +11 -15
- package/src/components/DateTimeField/DateTimeField.tsx +10 -9
- package/src/components/Dialog/Dialog.test.tsx +128 -104
- package/src/components/Dialog/Dialog.tsx +742 -24
- package/src/components/ErrorBoundary/ErrorBoundary.tsx +77 -79
- package/src/components/FileDisplay/FileDisplay.test.tsx +4 -2
- package/src/components/FileDisplay/FileDisplay.tsx +23 -17
- package/src/components/FileUpload/FileUpload.test.tsx +52 -14
- package/src/components/FileUpload/FileUpload.tsx +112 -130
- package/src/components/Form/Form.test.tsx +6 -8
- package/src/components/Form/Form.tsx +365 -4
- package/src/components/NavigationMenu/NavigationMenu.test.tsx +14 -13
- package/src/components/NavigationMenu/useNavigationFiltering.ts +11 -21
- package/src/components/PaceAppLayout/PaceAppLayout.test.tsx +6 -4
- package/src/components/PaceAppLayout/PaceAppLayout.tsx +11 -15
- package/src/components/PaceLoginPage/PaceLoginPage.test.tsx +108 -61
- package/src/components/PaceLoginPage/PaceLoginPage.tsx +27 -3
- package/src/components/Progress/Progress.tsx +2 -4
- package/src/components/ProtectedRoute/ProtectedRoute.tsx +8 -8
- package/src/components/Select/Select.tsx +109 -98
- package/src/components/Select/types.ts +4 -1
- package/src/components/UserMenu/UserMenu.tsx +9 -6
- package/src/hooks/__tests__/ServiceHooks.test.tsx +16 -16
- package/src/hooks/__tests__/hooks.integration.test.tsx +55 -57
- package/src/hooks/__tests__/useAppConfig.unit.test.ts +129 -67
- package/src/hooks/__tests__/useFocusTrap.unit.test.tsx +97 -97
- package/src/hooks/__tests__/usePublicEvent.simple.test.ts +149 -67
- package/src/hooks/__tests__/usePublicEvent.test.ts +149 -79
- package/src/hooks/__tests__/usePublicEvent.unit.test.ts +158 -109
- package/src/hooks/__tests__/useSessionDraft.test.ts +163 -0
- package/src/hooks/__tests__/useSessionRestoration.unit.test.tsx +10 -5
- package/src/hooks/public/usePublicEvent.ts +67 -195
- package/src/hooks/public/usePublicEventLogo.test.ts +70 -17
- package/src/hooks/public/usePublicEventLogo.ts +24 -14
- package/src/hooks/public/usePublicFileDisplay.ts +2 -2
- package/src/hooks/public/usePublicRouteParams.ts +5 -5
- package/src/hooks/useAppConfig.ts +28 -26
- package/src/hooks/useEventTheme.test.ts +217 -239
- package/src/hooks/useEventTheme.ts +16 -28
- package/src/hooks/useFileDisplay.ts +2 -2
- package/src/hooks/useOrganisationPermissions.ts +5 -7
- package/src/hooks/useQueryCache.ts +0 -1
- package/src/hooks/useSessionDraft.ts +380 -0
- package/src/hooks/useSessionRestoration.ts +3 -1
- package/src/icons/index.ts +27 -0
- package/src/index.ts +5 -0
- package/src/providers/OrganisationProvider.tsx +23 -14
- package/src/providers/UnifiedAuthProvider.smoke.test.tsx +21 -21
- package/src/providers/__tests__/AuthProvider.test.tsx +21 -21
- package/src/providers/__tests__/EventProvider.test.tsx +61 -61
- package/src/providers/__tests__/InactivityProvider.test.tsx +56 -56
- package/src/providers/__tests__/OrganisationProvider.test.tsx +75 -75
- package/src/providers/__tests__/ProviderLifecycle.test.tsx +37 -37
- package/src/providers/__tests__/UnifiedAuthProvider.test.tsx +103 -103
- package/src/providers/services/EventServiceProvider.tsx +1 -24
- package/src/providers/services/UnifiedAuthProvider.tsx +5 -48
- package/src/providers/services/__tests__/AuthServiceProvider.integration.test.tsx +7 -7
- package/src/providers/services/__tests__/UnifiedAuthProvider.integration.test.tsx +13 -10
- package/src/rbac/__tests__/adapters.comprehensive.test.tsx +7 -457
- package/src/rbac/__tests__/auth-rbac.e2e.test.tsx +33 -7
- package/src/rbac/adapters.tsx +7 -295
- package/src/rbac/api.test.ts +44 -56
- package/src/rbac/api.ts +10 -17
- package/src/rbac/cache-invalidation.ts +0 -1
- package/src/rbac/compliance/index.ts +10 -0
- package/src/rbac/compliance/pattern-detector.ts +553 -0
- package/src/rbac/compliance/runtime-compliance.ts +22 -0
- package/src/rbac/components/AccessDenied.tsx +150 -0
- package/src/rbac/components/NavigationGuard.tsx +12 -20
- package/src/rbac/components/PagePermissionGuard.tsx +4 -24
- package/src/rbac/components/__tests__/NavigationGuard.test.tsx +21 -8
- package/src/rbac/components/index.ts +3 -41
- package/src/rbac/eslint-rules.js +1 -1
- package/src/rbac/hooks/index.ts +0 -3
- package/src/rbac/hooks/permissions/index.ts +0 -3
- package/src/rbac/hooks/permissions/useAccessLevel.ts +4 -8
- package/src/rbac/hooks/usePermissions.ts +0 -3
- package/src/rbac/hooks/useResolvedScope.test.ts +57 -47
- package/src/rbac/hooks/useResolvedScope.ts +58 -140
- package/src/rbac/hooks/useResourcePermissions.test.ts +124 -38
- package/src/rbac/hooks/useResourcePermissions.ts +139 -48
- package/src/rbac/hooks/useRoleManagement.test.ts +65 -22
- package/src/rbac/hooks/useRoleManagement.ts +147 -19
- package/src/rbac/hooks/useSecureSupabase.ts +4 -8
- package/src/rbac/index.ts +7 -9
- package/src/rbac/utils/contextValidator.ts +9 -7
- package/src/services/AuthService.ts +130 -18
- package/src/services/EventService.ts +4 -97
- package/src/services/InactivityService.ts +16 -0
- package/src/services/OrganisationService.ts +7 -44
- package/src/services/__tests__/OrganisationService.test.ts +26 -8
- package/src/services/base/BaseService.ts +0 -3
- package/src/styles/core.css +7 -0
- package/src/theming/__tests__/parseEventColours.test.ts +9 -3
- package/src/theming/parseEventColours.ts +22 -10
- package/src/types/database.generated.ts +4733 -3809
- package/src/utils/__tests__/lazyLoad.unit.test.tsx +42 -39
- package/src/utils/__tests__/organisationContext.unit.test.ts +9 -10
- package/src/utils/context/organisationContext.test.ts +13 -28
- package/src/utils/context/organisationContext.ts +21 -52
- package/src/utils/dynamic/dynamicUtils.ts +1 -1
- package/src/utils/file-reference/index.ts +39 -15
- package/src/utils/formatting/formatDateTime.test.ts +3 -2
- package/src/utils/google-places/loadGoogleMapsScript.ts +29 -4
- package/src/utils/index.ts +4 -1
- package/src/utils/persistence/__tests__/keyDerivation.test.ts +135 -0
- package/src/utils/persistence/__tests__/sensitiveFieldDetection.test.ts +123 -0
- package/src/utils/persistence/keyDerivation.ts +304 -0
- package/src/utils/persistence/sensitiveFieldDetection.ts +212 -0
- package/src/utils/security/secureStorage.ts +5 -5
- package/src/utils/storage/README.md +1 -1
- package/src/utils/storage/helpers.ts +3 -3
- package/src/utils/supabase/createBaseClient.ts +147 -0
- package/src/utils/timezone/timezone.test.ts +1 -2
- package/src/utils/timezone/timezone.ts +1 -1
- package/src/utils/validation/csrf.ts +4 -4
- package/cursor-rules/00-pace-core-compliance.mdc +0 -331
- package/cursor-rules/01-standards-compliance.mdc +0 -244
- package/cursor-rules/04-testing-standards.mdc +0 -268
- package/cursor-rules/05-bug-reports-and-features.mdc +0 -246
- package/cursor-rules/06-code-quality.mdc +0 -309
- package/cursor-rules/07-tech-stack-compliance.mdc +0 -214
- package/cursor-rules/CHANGELOG.md +0 -119
- package/cursor-rules/README.md +0 -192
- package/dist/DataTable-AOVNCPTX.js +0 -175
- package/dist/DataTable-AOVNCPTX.js.map +0 -1
- package/dist/UnifiedAuthProvider-4SBX4LU5.js +0 -18
- package/dist/UnifiedAuthProvider-4SBX4LU5.js.map +0 -1
- package/dist/api-O6HTBX5Y.js +0 -52
- package/dist/api-O6HTBX5Y.js.map +0 -1
- package/dist/audit-V53FV5AG.js +0 -17
- package/dist/audit-V53FV5AG.js.map +0 -1
- package/dist/chunk-5DRSZLL2.js.map +0 -1
- package/dist/chunk-63FOKYGO.js.map +0 -1
- package/dist/chunk-6COVEUS7.js.map +0 -1
- package/dist/chunk-AFVQODI2.js +0 -263
- package/dist/chunk-AFVQODI2.js.map +0 -1
- package/dist/chunk-DGUM43GV.js.map +0 -1
- package/dist/chunk-E66EQZE6.js.map +0 -1
- package/dist/chunk-EFN2EIMK.js.map +0 -1
- package/dist/chunk-FFQEQTNW.js.map +0 -1
- package/dist/chunk-FMUCXFII.js.map +0 -1
- package/dist/chunk-G37KK66H.js.map +0 -1
- package/dist/chunk-G7QEZTYQ.js +0 -2053
- package/dist/chunk-G7QEZTYQ.js.map +0 -1
- package/dist/chunk-HU2C6SSC.js.map +0 -1
- package/dist/chunk-IHB5DR3H.js.map +0 -1
- package/dist/chunk-IVOFDYWT.js.map +0 -1
- package/dist/chunk-J36DSWQK.js.map +0 -1
- package/dist/chunk-JGRYX5UX.js.map +0 -1
- package/dist/chunk-KQCRWDSA.js +0 -1
- package/dist/chunk-KQCRWDSA.js.map +0 -1
- package/dist/chunk-L4OXEN46.js.map +0 -1
- package/dist/chunk-LMC26NLJ.js +0 -84
- package/dist/chunk-LMC26NLJ.js.map +0 -1
- package/dist/chunk-M43Y4SSO.js.map +0 -1
- package/dist/chunk-M7MPQISP.js.map +0 -1
- package/dist/chunk-NTM7ZSB6.js.map +0 -1
- package/dist/chunk-PWLANIRT.js.map +0 -1
- package/dist/chunk-QXHPKYJV.js.map +0 -1
- package/dist/chunk-RGAWHO7N.js.map +0 -1
- package/dist/chunk-UPPMRMYG.js.map +0 -1
- package/dist/chunk-VBXEHIUJ.js.map +0 -1
- package/dist/chunk-ZSAAAMVR.js.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/contextValidator-5OGXSPKS.js +0 -9
- package/dist/contextValidator-5OGXSPKS.js.map +0 -1
- package/dist/eslint-rules/pace-core-compliance.cjs +0 -510
- package/dist/hooks.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/providers.js.map +0 -1
- package/dist/rbac/eslint-rules.js.map +0 -1
- package/dist/rbac/index.js.map +0 -1
- package/dist/styles/index.js.map +0 -1
- package/dist/theming/runtime.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.js.map +0 -1
- package/docs/best-practices/README.md +0 -472
- package/docs/best-practices/accessibility.md +0 -601
- package/docs/best-practices/common-patterns.md +0 -516
- package/docs/best-practices/deployment.md +0 -1103
- package/docs/best-practices/performance.md +0 -1328
- package/docs/best-practices/security.md +0 -940
- package/docs/best-practices/testing.md +0 -1034
- package/docs/rbac/compliance/compliance-guide.md +0 -544
- package/docs/standards/01-architecture-standard.md +0 -44
- package/docs/standards/02-api-and-rpc-standard.md +0 -39
- package/docs/standards/03-component-standard.md +0 -32
- package/docs/standards/04-code-style-standard.md +0 -32
- package/docs/standards/05-security-standard.md +0 -44
- package/docs/standards/06-testing-and-docs-standard.md +0 -29
- package/docs/standards/pace-core-compliance.md +0 -432
- package/scripts/audit/core/checks/accessibility.cjs +0 -197
- package/scripts/audit/core/checks/api-usage.cjs +0 -191
- package/scripts/audit/core/checks/bundle.cjs +0 -142
- package/scripts/audit/core/checks/compliance.cjs +0 -2706
- package/scripts/audit/core/checks/config.cjs +0 -54
- package/scripts/audit/core/checks/coverage.cjs +0 -84
- package/scripts/audit/core/checks/dependencies.cjs +0 -994
- package/scripts/audit/core/checks/documentation.cjs +0 -268
- package/scripts/audit/core/checks/environment.cjs +0 -116
- package/scripts/audit/core/checks/error-handling.cjs +0 -340
- package/scripts/audit/core/checks/forms.cjs +0 -172
- package/scripts/audit/core/checks/heuristics.cjs +0 -68
- package/scripts/audit/core/checks/hooks.cjs +0 -334
- package/scripts/audit/core/checks/imports.cjs +0 -244
- package/scripts/audit/core/checks/performance.cjs +0 -325
- package/scripts/audit/core/checks/routes.cjs +0 -117
- package/scripts/audit/core/checks/state.cjs +0 -130
- package/scripts/audit/core/checks/structure.cjs +0 -65
- package/scripts/audit/core/checks/style.cjs +0 -584
- package/scripts/audit/core/checks/testing.cjs +0 -122
- package/scripts/audit/core/checks/typescript.cjs +0 -61
- package/scripts/audit/core/scanner.cjs +0 -199
- package/scripts/audit/core/utils.cjs +0 -137
- package/scripts/audit/index.cjs +0 -223
- package/scripts/audit/reporters/console.cjs +0 -151
- package/scripts/audit/reporters/json.cjs +0 -54
- package/scripts/audit/reporters/markdown.cjs +0 -124
- package/scripts/audit-consuming-app.cjs +0 -86
- package/src/components/DataTable/components/DataTableBody.tsx +0 -454
- package/src/components/DataTable/components/DraggableColumnHeader.tsx +0 -156
- package/src/components/DataTable/components/ExpandButton.tsx +0 -113
- package/src/components/DataTable/components/GroupHeader.tsx +0 -54
- package/src/components/DataTable/components/ViewRowModal.tsx +0 -68
- package/src/components/DataTable/components/VirtualizedDataTable.tsx +0 -525
- package/src/components/DataTable/components/__tests__/ExpandButton.test.tsx +0 -462
- package/src/components/DataTable/components/__tests__/GroupHeader.test.tsx +0 -393
- package/src/components/DataTable/components/__tests__/ViewRowModal.test.tsx +0 -476
- package/src/components/DataTable/components/__tests__/VirtualizedDataTable.test.tsx +0 -128
- package/src/components/DataTable/core/DataTableContext.tsx +0 -216
- package/src/components/DataTable/core/__tests__/DataTableContext.test.tsx +0 -136
- package/src/components/DataTable/hooks/__tests__/useColumnReordering.test.ts +0 -570
- package/src/components/DataTable/hooks/useColumnReordering.ts +0 -123
- package/src/components/DataTable/utils/debugTools.ts +0 -514
- package/src/eslint-rules/pace-core-compliance.js +0 -638
- package/src/rbac/components/EnhancedNavigationMenu.test.tsx +0 -555
- package/src/rbac/components/EnhancedNavigationMenu.tsx +0 -293
- package/src/rbac/components/NavigationProvider.test.tsx +0 -481
- package/src/rbac/components/NavigationProvider.tsx +0 -345
- package/src/rbac/components/PagePermissionProvider.test.tsx +0 -476
- package/src/rbac/components/PagePermissionProvider.tsx +0 -279
- package/src/rbac/components/PermissionEnforcer.tsx +0 -312
- package/src/rbac/components/RoleBasedRouter.tsx +0 -440
- package/src/rbac/components/SecureDataProvider.test.tsx +0 -543
- package/src/rbac/components/SecureDataProvider.tsx +0 -339
- package/src/rbac/components/__tests__/EnhancedNavigationMenu.test.tsx +0 -620
- package/src/rbac/components/__tests__/NavigationProvider.test.tsx +0 -726
- package/src/rbac/components/__tests__/PagePermissionProvider.test.tsx +0 -661
- package/src/rbac/components/__tests__/PermissionEnforcer.test.tsx +0 -881
- package/src/rbac/components/__tests__/RoleBasedRouter.test.tsx +0 -783
- package/src/rbac/components/__tests__/SecureDataProvider.fixed.test.tsx +0 -645
- package/src/rbac/components/__tests__/SecureDataProvider.test.tsx +0 -659
- package/src/rbac/hooks/permissions/useCachedPermissions.ts +0 -79
- package/src/rbac/hooks/permissions/useHasAllPermissions.ts +0 -90
- package/src/rbac/hooks/permissions/useHasAnyPermission.ts +0 -90
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./chunk-QXHPKYJV.js";
|
|
9
|
-
import {
|
|
10
|
-
secureStorage,
|
|
11
|
-
setOrganisationContext
|
|
12
|
-
} from "./chunk-VBXEHIUJ.js";
|
|
13
|
-
import {
|
|
14
|
-
createLogger,
|
|
15
|
-
logger
|
|
16
|
-
} from "./chunk-PWLANIRT.js";
|
|
17
|
-
|
|
18
|
-
// src/providers/services/UnifiedAuthProvider.tsx
|
|
19
|
-
import { createContext as createContext5, useContext as useContext6, useMemo as useMemo6, useCallback, useRef as useRef9, useEffect as useEffect10, useState as useState3, useReducer as useReducer5 } from "react";
|
|
20
|
-
|
|
21
|
-
// src/providers/services/AuthServiceProvider.tsx
|
|
22
|
-
import { createContext, useMemo, useEffect, useState, useRef } from "react";
|
|
23
|
-
|
|
24
|
-
// src/services/AuthService.ts
|
|
25
|
-
import { AuthError } from "@supabase/supabase-js";
|
|
1
|
+
import { isRBACInitialized, setupRBAC } from './chunk-ZFYPMX46.js';
|
|
2
|
+
import { assertOrganisationId, assertUserId } from './chunk-4SXLQIZO.js';
|
|
3
|
+
import { secureStorage } from './chunk-HF6O3O37.js';
|
|
4
|
+
import { createLogger, logger } from './chunk-TTRFSOKR.js';
|
|
5
|
+
import { createContext, useRef, useEffect, useState, useMemo, useContext, useReducer, useCallback } from 'react';
|
|
6
|
+
import { AuthError } from '@supabase/supabase-js';
|
|
7
|
+
import { jsx } from 'react/jsx-runtime';
|
|
26
8
|
|
|
27
9
|
// src/services/base/BaseService.ts
|
|
28
10
|
var BaseService = class {
|
|
@@ -49,9 +31,6 @@ var BaseService = class {
|
|
|
49
31
|
* This triggers React re-renders
|
|
50
32
|
*/
|
|
51
33
|
notify() {
|
|
52
|
-
const serviceName = this.constructor.name;
|
|
53
|
-
const instanceId = this.instanceId || "unknown";
|
|
54
|
-
logger.debug("BaseService", `[${serviceName} ID:${instanceId}] Notifying ${this.subscribers.length} subscribers`);
|
|
55
34
|
this.subscribers.forEach((callback) => {
|
|
56
35
|
try {
|
|
57
36
|
callback();
|
|
@@ -97,6 +76,7 @@ var BaseService = class {
|
|
|
97
76
|
|
|
98
77
|
// src/services/AuthService.ts
|
|
99
78
|
var _AuthService = class _AuthService extends BaseService {
|
|
79
|
+
// Track previous auth state to detect transitions
|
|
100
80
|
constructor(supabaseClient, appName) {
|
|
101
81
|
super();
|
|
102
82
|
this.user = null;
|
|
@@ -111,15 +91,18 @@ var _AuthService = class _AuthService extends BaseService {
|
|
|
111
91
|
restorationError: null
|
|
112
92
|
};
|
|
113
93
|
this.restorationTimeoutId = null;
|
|
114
|
-
|
|
94
|
+
// Increased timeout to handle hard refresh scenarios where localStorage access
|
|
95
|
+
// and session restoration may take longer, especially with organisation/event context
|
|
96
|
+
this.restorationTimeoutMs = 1e4;
|
|
97
|
+
// 10 seconds (increased from 5)
|
|
115
98
|
this.restorationStartTime = null;
|
|
116
99
|
this.appName = void 0;
|
|
117
100
|
this.errorHandler = null;
|
|
118
101
|
this.unhandledRejectionHandler = null;
|
|
102
|
+
this.wasAuthenticatedRef = false;
|
|
119
103
|
this.instanceId = ++_AuthService.instanceCount;
|
|
120
104
|
this.supabaseClient = supabaseClient;
|
|
121
105
|
this.appName = appName;
|
|
122
|
-
logger.debug("AuthService", `Instance created [ID:${this.instanceId}]`, { appName });
|
|
123
106
|
}
|
|
124
107
|
getInstanceId() {
|
|
125
108
|
return this.instanceId;
|
|
@@ -167,6 +150,10 @@ var _AuthService = class _AuthService extends BaseService {
|
|
|
167
150
|
this.authError = null;
|
|
168
151
|
this.user = data.user;
|
|
169
152
|
this.session = data.session;
|
|
153
|
+
if (!this.wasAuthenticatedRef && data.user) {
|
|
154
|
+
this.clearPersistenceOnLogin(null, true);
|
|
155
|
+
this.wasAuthenticatedRef = true;
|
|
156
|
+
}
|
|
170
157
|
}
|
|
171
158
|
this.notify();
|
|
172
159
|
return { user: data.user, session: data.session, error };
|
|
@@ -199,6 +186,10 @@ var _AuthService = class _AuthService extends BaseService {
|
|
|
199
186
|
this.authError = null;
|
|
200
187
|
this.user = data.user;
|
|
201
188
|
this.session = data.session;
|
|
189
|
+
if (!this.wasAuthenticatedRef && data.user) {
|
|
190
|
+
this.clearPersistenceOnLogin(null, true);
|
|
191
|
+
this.wasAuthenticatedRef = true;
|
|
192
|
+
}
|
|
202
193
|
}
|
|
203
194
|
this.notify();
|
|
204
195
|
return { user: data.user, session: data.session, error };
|
|
@@ -220,6 +211,11 @@ var _AuthService = class _AuthService extends BaseService {
|
|
|
220
211
|
}
|
|
221
212
|
try {
|
|
222
213
|
const { error } = await this.supabaseClient.auth.signOut();
|
|
214
|
+
try {
|
|
215
|
+
sessionStorage.clear();
|
|
216
|
+
} catch (storageError) {
|
|
217
|
+
logger.warn("AuthService", "Failed to clear sessionStorage", { error: storageError });
|
|
218
|
+
}
|
|
223
219
|
if (error) {
|
|
224
220
|
this.authError = error;
|
|
225
221
|
} else {
|
|
@@ -230,6 +226,11 @@ var _AuthService = class _AuthService extends BaseService {
|
|
|
230
226
|
this.notify();
|
|
231
227
|
return { user: null, session: null, error };
|
|
232
228
|
} catch (error) {
|
|
229
|
+
try {
|
|
230
|
+
sessionStorage.clear();
|
|
231
|
+
} catch (storageError) {
|
|
232
|
+
logger.warn("AuthService", "Failed to clear sessionStorage", { error: storageError });
|
|
233
|
+
}
|
|
233
234
|
const authError = error instanceof AuthError ? error : new AuthError(error instanceof Error ? error.message : "Authentication failed");
|
|
234
235
|
this.authError = authError;
|
|
235
236
|
this.user = null;
|
|
@@ -376,7 +377,7 @@ var _AuthService = class _AuthService extends BaseService {
|
|
|
376
377
|
}
|
|
377
378
|
this.clearRestorationTimeout();
|
|
378
379
|
const completedAt = Date.now();
|
|
379
|
-
|
|
380
|
+
this.restorationStartTime ? completedAt - this.restorationStartTime : null;
|
|
380
381
|
this.restorationStartTime = null;
|
|
381
382
|
const restorationComplete = !error;
|
|
382
383
|
this.sessionRestorationState = {
|
|
@@ -396,6 +397,43 @@ var _AuthService = class _AuthService extends BaseService {
|
|
|
396
397
|
this.restorationTimeoutId = null;
|
|
397
398
|
}
|
|
398
399
|
}
|
|
400
|
+
/**
|
|
401
|
+
* Clear pace-core persistence entries from sessionStorage
|
|
402
|
+
* This includes dialog, form, and datatable persistence
|
|
403
|
+
*
|
|
404
|
+
* @param userId - Optional user ID to clear only that user's persistence.
|
|
405
|
+
* If not provided, clears all pace-core persistence (for user changes).
|
|
406
|
+
* @param clearUnscoped - If true, also clears old unscoped keys (without :user: prefix)
|
|
407
|
+
*/
|
|
408
|
+
clearPersistenceOnLogin(userId, clearUnscoped = true) {
|
|
409
|
+
if (typeof window === "undefined" || !window.sessionStorage) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
try {
|
|
413
|
+
const keysToRemove = [];
|
|
414
|
+
for (let i = 0; i < sessionStorage.length; i++) {
|
|
415
|
+
const key = sessionStorage.key(i);
|
|
416
|
+
if (key && (key.startsWith("pace-core:draft:") || key.startsWith("pace-core:dialog:"))) {
|
|
417
|
+
if (userId && !key.includes(`:user:${userId}`)) {
|
|
418
|
+
if (clearUnscoped && !key.includes(":user:")) {
|
|
419
|
+
keysToRemove.push(key);
|
|
420
|
+
}
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
keysToRemove.push(key);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
keysToRemove.forEach((key) => {
|
|
427
|
+
try {
|
|
428
|
+
sessionStorage.removeItem(key);
|
|
429
|
+
} catch (error) {
|
|
430
|
+
logger.warn("AuthService", `Failed to remove persistence key: ${key}`, error);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
} catch (error) {
|
|
434
|
+
logger.warn("AuthService", `Failed to clear persistence [ID:${this.instanceId}]:`, error);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
399
437
|
async setupAuthStateListener() {
|
|
400
438
|
if (!this.supabaseClient) {
|
|
401
439
|
this.authLoading = false;
|
|
@@ -406,15 +444,16 @@ var _AuthService = class _AuthService extends BaseService {
|
|
|
406
444
|
const subscription = this.supabaseClient.auth.onAuthStateChange(
|
|
407
445
|
(event, session) => {
|
|
408
446
|
try {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
447
|
+
const wasAuthenticated = this.wasAuthenticatedRef;
|
|
448
|
+
const isNowAuthenticated = !!session?.user;
|
|
449
|
+
const previousUserId = this.user?.id || null;
|
|
450
|
+
const newUserId = session?.user?.id || null;
|
|
451
|
+
const userChanged = previousUserId !== null && newUserId !== null && previousUserId !== newUserId;
|
|
414
452
|
if (event === "SIGNED_OUT") {
|
|
415
453
|
this.session = null;
|
|
416
454
|
this.user = null;
|
|
417
455
|
this.authError = null;
|
|
456
|
+
this.wasAuthenticatedRef = false;
|
|
418
457
|
if (session?.user) {
|
|
419
458
|
this.trackSession("logout", session).catch((err) => {
|
|
420
459
|
logger.warn("AuthService", `Failed to track logout session [ID:${this.instanceId}]:`, err);
|
|
@@ -426,6 +465,12 @@ var _AuthService = class _AuthService extends BaseService {
|
|
|
426
465
|
if (session?.user) {
|
|
427
466
|
this.authError = null;
|
|
428
467
|
}
|
|
468
|
+
if (!wasAuthenticated && isNowAuthenticated && event === "SIGNED_IN") {
|
|
469
|
+
this.clearPersistenceOnLogin(null, true);
|
|
470
|
+
} else if (userChanged && previousUserId) {
|
|
471
|
+
this.clearPersistenceOnLogin(previousUserId, true);
|
|
472
|
+
}
|
|
473
|
+
this.wasAuthenticatedRef = isNowAuthenticated;
|
|
429
474
|
if (event === "SIGNED_IN" && session?.user) {
|
|
430
475
|
this.trackSession("login", session).catch((err) => {
|
|
431
476
|
logger.warn("AuthService", `Failed to track login session [ID:${this.instanceId}]:`, err);
|
|
@@ -433,32 +478,33 @@ var _AuthService = class _AuthService extends BaseService {
|
|
|
433
478
|
}
|
|
434
479
|
} else if (event === "INITIAL_SESSION") {
|
|
435
480
|
if (session) {
|
|
481
|
+
const previousUserId2 = this.user?.id || null;
|
|
482
|
+
const newUserId2 = session.user?.id || null;
|
|
483
|
+
const userChanged2 = previousUserId2 !== null && newUserId2 !== null && previousUserId2 !== newUserId2;
|
|
436
484
|
this.session = session;
|
|
437
485
|
this.user = session.user ?? null;
|
|
438
486
|
this.authError = null;
|
|
487
|
+
if (userChanged2 && previousUserId2) {
|
|
488
|
+
this.clearPersistenceOnLogin(previousUserId2, true);
|
|
489
|
+
} else if (!wasAuthenticated && !!session.user) {
|
|
490
|
+
this.clearPersistenceOnLogin(null, true);
|
|
491
|
+
}
|
|
492
|
+
this.wasAuthenticatedRef = !!session.user;
|
|
439
493
|
const hasTimeoutError = this.sessionRestorationState.restorationError?.name === "SessionRestorationTimeoutError";
|
|
440
494
|
if (this.sessionRestorationState.isRestoring || this.sessionRestorationState.restorationError || hasTimeoutError && session) {
|
|
441
495
|
this.finishSessionRestoration();
|
|
442
496
|
}
|
|
443
497
|
} else {
|
|
498
|
+
this.wasAuthenticatedRef = false;
|
|
444
499
|
if (this.sessionRestorationState.isRestoring) {
|
|
445
500
|
this.finishSessionRestoration();
|
|
446
501
|
}
|
|
447
502
|
}
|
|
448
503
|
this.authLoading = false;
|
|
449
|
-
logger.debug("AuthService", `State synchronized after INITIAL_SESSION [ID:${this.instanceId}]`, {
|
|
450
|
-
hasUser: !!this.user,
|
|
451
|
-
userId: this.user?.id
|
|
452
|
-
});
|
|
453
504
|
this.notify();
|
|
454
505
|
return;
|
|
455
506
|
}
|
|
456
507
|
this.authLoading = false;
|
|
457
|
-
logger.debug("AuthService", `State synchronized after event [ID:${this.instanceId}]`, {
|
|
458
|
-
event,
|
|
459
|
-
hasUser: !!this.user,
|
|
460
|
-
userId: this.user?.id
|
|
461
|
-
});
|
|
462
508
|
this.notify();
|
|
463
509
|
} catch (error) {
|
|
464
510
|
logger.warn("AuthService", `Error in auth state change handler [ID:${this.instanceId}]:`, error);
|
|
@@ -602,9 +648,6 @@ var _AuthService = class _AuthService extends BaseService {
|
|
|
602
648
|
};
|
|
603
649
|
_AuthService.instanceCount = 0;
|
|
604
650
|
var AuthService = _AuthService;
|
|
605
|
-
|
|
606
|
-
// src/providers/services/AuthServiceProvider.tsx
|
|
607
|
-
import { jsx } from "react/jsx-runtime";
|
|
608
651
|
var AuthServiceContext = createContext(null);
|
|
609
652
|
function AuthServiceProvider({ children, supabaseClient, appName }) {
|
|
610
653
|
const authServiceRef = useRef(null);
|
|
@@ -641,9 +684,6 @@ function AuthServiceProvider({ children, supabaseClient, appName }) {
|
|
|
641
684
|
return /* @__PURE__ */ jsx(AuthServiceContext.Provider, { value: contextValue, children });
|
|
642
685
|
}
|
|
643
686
|
|
|
644
|
-
// src/providers/services/OrganisationServiceProvider.tsx
|
|
645
|
-
import { createContext as createContext2, useMemo as useMemo2, useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
646
|
-
|
|
647
687
|
// src/services/OrganisationService.ts
|
|
648
688
|
var _OrganisationService = class _OrganisationService extends BaseService {
|
|
649
689
|
constructor(supabaseClient, user, session) {
|
|
@@ -671,10 +711,6 @@ var _OrganisationService = class _OrganisationService extends BaseService {
|
|
|
671
711
|
this.supabaseClient = supabaseClient;
|
|
672
712
|
this.user = user;
|
|
673
713
|
this.session = session;
|
|
674
|
-
logger.debug("OrganisationService", `Instance created [ID:${this.instanceId}]`, {
|
|
675
|
-
hasUser: !!user,
|
|
676
|
-
userId: user?.id
|
|
677
|
-
});
|
|
678
714
|
}
|
|
679
715
|
getInstanceId() {
|
|
680
716
|
return this.instanceId;
|
|
@@ -756,12 +792,7 @@ var _OrganisationService = class _OrganisationService extends BaseService {
|
|
|
756
792
|
const needsRetry = this._error !== null && !this.isLoadingRef;
|
|
757
793
|
const isEmpty = newUserId !== null && this._organisations.length === 0 && !this.isLoadingRef;
|
|
758
794
|
if (userChanged || needsRetry || isEmpty) {
|
|
759
|
-
if (userChanged) {
|
|
760
|
-
logger.debug("OrganisationService", `User changed [ID:${this.instanceId}], resetting initialization`, {
|
|
761
|
-
previousUserId,
|
|
762
|
-
newUserId
|
|
763
|
-
});
|
|
764
|
-
} else if (needsRetry) {
|
|
795
|
+
if (userChanged) ; else if (needsRetry) {
|
|
765
796
|
logger.debug("OrganisationService", `Previous error detected [ID:${this.instanceId}], retrying initialization`);
|
|
766
797
|
} else if (isEmpty) {
|
|
767
798
|
logger.debug("OrganisationService", `No organisations found [ID:${this.instanceId}], retrying initialization`);
|
|
@@ -848,7 +879,6 @@ var _OrganisationService = class _OrganisationService extends BaseService {
|
|
|
848
879
|
// Lifecycle methods
|
|
849
880
|
async initialize() {
|
|
850
881
|
if (!this.user) {
|
|
851
|
-
logger.debug("OrganisationService", "Skipping initialization - no user");
|
|
852
882
|
return;
|
|
853
883
|
}
|
|
854
884
|
await super.initialize();
|
|
@@ -877,25 +907,8 @@ var _OrganisationService = class _OrganisationService extends BaseService {
|
|
|
877
907
|
doCleanup() {
|
|
878
908
|
}
|
|
879
909
|
async setDatabaseOrganisationContext(organisation) {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
this._isContextReady = false;
|
|
883
|
-
this.notify();
|
|
884
|
-
return;
|
|
885
|
-
}
|
|
886
|
-
try {
|
|
887
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
888
|
-
setTimeout(() => reject(new Error("Context setting timeout after 5 seconds")), 5e3);
|
|
889
|
-
});
|
|
890
|
-
const contextPromise = setOrganisationContext(this.supabaseClient, organisation.id);
|
|
891
|
-
await Promise.race([contextPromise, timeoutPromise]);
|
|
892
|
-
this._isContextReady = true;
|
|
893
|
-
this.notify();
|
|
894
|
-
} catch (error) {
|
|
895
|
-
logger.error("OrganisationService", "Failed to set database organisation context:", error);
|
|
896
|
-
this._isContextReady = true;
|
|
897
|
-
this.notify();
|
|
898
|
-
}
|
|
910
|
+
this._isContextReady = true;
|
|
911
|
+
this.notify();
|
|
899
912
|
}
|
|
900
913
|
async loadUserOrganisations() {
|
|
901
914
|
if (!this.user || !this.session || !this.supabaseClient) {
|
|
@@ -932,9 +945,6 @@ var _OrganisationService = class _OrganisationService extends BaseService {
|
|
|
932
945
|
this._isLoading = true;
|
|
933
946
|
this._error = null;
|
|
934
947
|
this.notify();
|
|
935
|
-
logger.debug("OrganisationService", "Loading organisations for user", {
|
|
936
|
-
userId: this.user.id
|
|
937
|
-
});
|
|
938
948
|
try {
|
|
939
949
|
let memberships, membershipError, organisations = [];
|
|
940
950
|
try {
|
|
@@ -993,10 +1003,6 @@ var _OrganisationService = class _OrganisationService extends BaseService {
|
|
|
993
1003
|
}
|
|
994
1004
|
});
|
|
995
1005
|
organisations = Array.from(organisationsMap.values());
|
|
996
|
-
logger.debug("OrganisationService", "Query results", {
|
|
997
|
-
membershipsCount: memberships.length,
|
|
998
|
-
organisationsCount: organisations.length
|
|
999
|
-
});
|
|
1000
1006
|
} catch (queryError) {
|
|
1001
1007
|
if (queryError instanceof Error) {
|
|
1002
1008
|
membershipError = queryError;
|
|
@@ -1011,7 +1017,7 @@ var _OrganisationService = class _OrganisationService extends BaseService {
|
|
|
1011
1017
|
let userIsSuperAdmin = false;
|
|
1012
1018
|
if (this.user?.id) {
|
|
1013
1019
|
try {
|
|
1014
|
-
const { isSuperAdmin: checkSuperAdmin, isRBACInitialized: isRBACInitialized2, setupRBAC: setupRBAC2 } = await import(
|
|
1020
|
+
const { isSuperAdmin: checkSuperAdmin, isRBACInitialized: isRBACInitialized2, setupRBAC: setupRBAC2 } = await import('./api-Y4MQWOFW.js');
|
|
1015
1021
|
if (!isRBACInitialized2() && this.supabaseClient) {
|
|
1016
1022
|
setupRBAC2(this.supabaseClient);
|
|
1017
1023
|
}
|
|
@@ -1159,22 +1165,19 @@ var _OrganisationService = class _OrganisationService extends BaseService {
|
|
|
1159
1165
|
};
|
|
1160
1166
|
_OrganisationService.instanceCount = 0;
|
|
1161
1167
|
var OrganisationService = _OrganisationService;
|
|
1162
|
-
|
|
1163
|
-
// src/providers/services/OrganisationServiceProvider.tsx
|
|
1164
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
1165
|
-
var OrganisationServiceContext = createContext2(null);
|
|
1168
|
+
var OrganisationServiceContext = createContext(null);
|
|
1166
1169
|
function OrganisationServiceProvider({
|
|
1167
1170
|
children,
|
|
1168
1171
|
supabaseClient,
|
|
1169
1172
|
user,
|
|
1170
1173
|
session
|
|
1171
1174
|
}) {
|
|
1172
|
-
const organisationServiceRef =
|
|
1175
|
+
const organisationServiceRef = useRef(null);
|
|
1173
1176
|
if (!organisationServiceRef.current) {
|
|
1174
1177
|
organisationServiceRef.current = new OrganisationService(supabaseClient, user, session);
|
|
1175
1178
|
}
|
|
1176
1179
|
const organisationService = organisationServiceRef.current;
|
|
1177
|
-
|
|
1180
|
+
useEffect(() => {
|
|
1178
1181
|
organisationService.updateDependencies(user, session);
|
|
1179
1182
|
let isMounted = true;
|
|
1180
1183
|
organisationService.initialize().catch((error) => {
|
|
@@ -1191,20 +1194,17 @@ function OrganisationServiceProvider({
|
|
|
1191
1194
|
isMounted = false;
|
|
1192
1195
|
};
|
|
1193
1196
|
}, [organisationService, user, session]);
|
|
1194
|
-
|
|
1197
|
+
useEffect(() => {
|
|
1195
1198
|
return () => {
|
|
1196
1199
|
organisationService.cleanup();
|
|
1197
1200
|
};
|
|
1198
1201
|
}, [organisationService]);
|
|
1199
|
-
const contextValue =
|
|
1202
|
+
const contextValue = useMemo(() => ({
|
|
1200
1203
|
organisationService
|
|
1201
1204
|
}), [organisationService]);
|
|
1202
|
-
return /* @__PURE__ */
|
|
1205
|
+
return /* @__PURE__ */ jsx(OrganisationServiceContext.Provider, { value: contextValue, children });
|
|
1203
1206
|
}
|
|
1204
1207
|
|
|
1205
|
-
// src/providers/services/EventServiceProvider.tsx
|
|
1206
|
-
import { createContext as createContext3, useMemo as useMemo3, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
1207
|
-
|
|
1208
1208
|
// src/services/EventService.ts
|
|
1209
1209
|
var _EventService = class _EventService extends BaseService {
|
|
1210
1210
|
constructor(supabaseClient, user, session, appName, selectedOrganisation, setSelectedEventId) {
|
|
@@ -1236,11 +1236,6 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1236
1236
|
this.appName = appName;
|
|
1237
1237
|
this.selectedOrganisation = selectedOrganisation;
|
|
1238
1238
|
this.setSelectedEventId = setSelectedEventId;
|
|
1239
|
-
logger.debug("EventService", `Instance created [ID:${this.instanceId}]`, {
|
|
1240
|
-
appName,
|
|
1241
|
-
hasUser: !!user,
|
|
1242
|
-
userId: user?.id
|
|
1243
|
-
});
|
|
1244
1239
|
}
|
|
1245
1240
|
getInstanceId() {
|
|
1246
1241
|
return this.instanceId;
|
|
@@ -1258,7 +1253,7 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1258
1253
|
const newOrgId = selectedOrganisation?.id;
|
|
1259
1254
|
const previousUserId = this.user?.id || null;
|
|
1260
1255
|
const newUserId = user?.id || null;
|
|
1261
|
-
|
|
1256
|
+
this.appName;
|
|
1262
1257
|
if (previousUserId !== newUserId) {
|
|
1263
1258
|
if (previousUserId !== null) {
|
|
1264
1259
|
await this.clearEventSelectionForUser(previousUserId);
|
|
@@ -1272,11 +1267,6 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1272
1267
|
this.isFetchingRef = false;
|
|
1273
1268
|
this.userClearedEventRef = false;
|
|
1274
1269
|
this.hasAutoSelectedRef = false;
|
|
1275
|
-
logger.debug("EventService", `User changed [ID:${this.instanceId}]`, {
|
|
1276
|
-
previousUserId,
|
|
1277
|
-
newUserId,
|
|
1278
|
-
willInitialize: newUserId !== null
|
|
1279
|
-
});
|
|
1280
1270
|
}
|
|
1281
1271
|
this.supabaseClient = supabaseClient;
|
|
1282
1272
|
this.user = user;
|
|
@@ -1286,16 +1276,12 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1286
1276
|
this.setSelectedEventId = setSelectedEventId;
|
|
1287
1277
|
if (user?.id) {
|
|
1288
1278
|
try {
|
|
1289
|
-
const { isRBACInitialized: isRBACInitialized2, isSuperAdmin: checkSuperAdmin, setupRBAC: setupRBAC2 } = await import(
|
|
1279
|
+
const { isRBACInitialized: isRBACInitialized2, isSuperAdmin: checkSuperAdmin, setupRBAC: setupRBAC2 } = await import('./api-Y4MQWOFW.js');
|
|
1290
1280
|
if (!isRBACInitialized2() && this.supabaseClient) {
|
|
1291
1281
|
setupRBAC2(this.supabaseClient);
|
|
1292
1282
|
}
|
|
1293
1283
|
if (isRBACInitialized2()) {
|
|
1294
1284
|
this.isSuperAdmin = await checkSuperAdmin(user.id);
|
|
1295
|
-
logger.debug("EventService", "Super admin status updated in updateDependencies", {
|
|
1296
|
-
userId: user.id,
|
|
1297
|
-
isSuperAdmin: this.isSuperAdmin
|
|
1298
|
-
});
|
|
1299
1285
|
} else {
|
|
1300
1286
|
logger.warn("EventService", "RBAC not initialized in updateDependencies, keeping existing super admin status", {
|
|
1301
1287
|
userId: user.id,
|
|
@@ -1370,13 +1356,8 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1370
1356
|
logger.warn("EventService", "Failed to persist event selection:", error);
|
|
1371
1357
|
});
|
|
1372
1358
|
this.userClearedEventRef = false;
|
|
1373
|
-
logger.debug("EventService", "Event selected", {
|
|
1374
|
-
eventId: event.event_id,
|
|
1375
|
-
eventName: event.event_name,
|
|
1376
|
-
userClearedEventRef: this.userClearedEventRef
|
|
1377
|
-
});
|
|
1378
1359
|
} else {
|
|
1379
|
-
|
|
1360
|
+
this.selectedEvent?.event_id;
|
|
1380
1361
|
this.selectedEvent = null;
|
|
1381
1362
|
this.setSelectedEventId?.(null);
|
|
1382
1363
|
this.clearEventSelection().catch((error) => {
|
|
@@ -1384,11 +1365,6 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1384
1365
|
});
|
|
1385
1366
|
this.hasAutoSelectedRef = false;
|
|
1386
1367
|
this.userClearedEventRef = true;
|
|
1387
|
-
logger.debug("EventService", "Event cleared via setSelectedEvent(null)", {
|
|
1388
|
-
previousEventId,
|
|
1389
|
-
userClearedEventRef: this.userClearedEventRef,
|
|
1390
|
-
stackTrace: new Error().stack
|
|
1391
|
-
});
|
|
1392
1368
|
}
|
|
1393
1369
|
this.notify();
|
|
1394
1370
|
}
|
|
@@ -1478,11 +1454,9 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1478
1454
|
}
|
|
1479
1455
|
async doInitialize() {
|
|
1480
1456
|
if (this.isInitializedRef) {
|
|
1481
|
-
logger.debug("EventService", "Skipping initialization - already initialized");
|
|
1482
1457
|
return;
|
|
1483
1458
|
}
|
|
1484
1459
|
if (this.isFetchingRef) {
|
|
1485
|
-
logger.debug("EventService", "Skipping initialization - already fetching");
|
|
1486
1460
|
return;
|
|
1487
1461
|
}
|
|
1488
1462
|
try {
|
|
@@ -1493,22 +1467,10 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1493
1467
|
logger.warn("EventService", "Failed to clean up old storage keys:", error);
|
|
1494
1468
|
}
|
|
1495
1469
|
if (!this.user) {
|
|
1496
|
-
logger.debug("EventService", "Skipping initialization - no user");
|
|
1497
1470
|
return;
|
|
1498
1471
|
}
|
|
1499
|
-
logger.debug("EventService", "Initializing", {
|
|
1500
|
-
userId: this.user.id,
|
|
1501
|
-
appName: this.appName,
|
|
1502
|
-
hasSelectedOrganisation: !!this.selectedOrganisation,
|
|
1503
|
-
hasSupabaseClient: !!this.supabaseClient,
|
|
1504
|
-
hasSession: !!this.session
|
|
1505
|
-
});
|
|
1506
1472
|
await this.fetchEvents(false);
|
|
1507
1473
|
this.isInitializedRef = true;
|
|
1508
|
-
logger.debug("EventService", "Initialization complete", {
|
|
1509
|
-
eventsCount: this.events.length,
|
|
1510
|
-
hasError: !!this.error
|
|
1511
|
-
});
|
|
1512
1474
|
}
|
|
1513
1475
|
doCleanup() {
|
|
1514
1476
|
}
|
|
@@ -1528,17 +1490,13 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1528
1490
|
let organisationIdForRpc = null;
|
|
1529
1491
|
let userIsSuperAdmin = this.isSuperAdmin;
|
|
1530
1492
|
try {
|
|
1531
|
-
const { isRBACInitialized: isRBACInitialized2, isSuperAdmin: checkSuperAdmin, setupRBAC: setupRBAC2 } = await import(
|
|
1493
|
+
const { isRBACInitialized: isRBACInitialized2, isSuperAdmin: checkSuperAdmin, setupRBAC: setupRBAC2 } = await import('./api-Y4MQWOFW.js');
|
|
1532
1494
|
if (!isRBACInitialized2() && this.supabaseClient) {
|
|
1533
1495
|
setupRBAC2(this.supabaseClient);
|
|
1534
1496
|
}
|
|
1535
1497
|
if (isRBACInitialized2()) {
|
|
1536
1498
|
userIsSuperAdmin = await checkSuperAdmin(this.user.id);
|
|
1537
1499
|
this.isSuperAdmin = userIsSuperAdmin;
|
|
1538
|
-
logger.debug("EventService", "Super admin check completed", {
|
|
1539
|
-
userId: this.user.id,
|
|
1540
|
-
isSuperAdmin: userIsSuperAdmin
|
|
1541
|
-
});
|
|
1542
1500
|
} else {
|
|
1543
1501
|
if (this.isSuperAdmin) {
|
|
1544
1502
|
userIsSuperAdmin = true;
|
|
@@ -1563,10 +1521,6 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1563
1521
|
} else if (this.selectedOrganisation) {
|
|
1564
1522
|
organisationIdForRpc = this.selectedOrganisation.id;
|
|
1565
1523
|
} else {
|
|
1566
|
-
logger.debug("EventService", "No organisation context available, fetching all accessible events", {
|
|
1567
|
-
hasSelectedEvent: !!this.selectedEvent,
|
|
1568
|
-
hasSelectedOrganisation: !!this.selectedOrganisation
|
|
1569
|
-
});
|
|
1570
1524
|
organisationIdForRpc = null;
|
|
1571
1525
|
}
|
|
1572
1526
|
}
|
|
@@ -1592,24 +1546,11 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1592
1546
|
}
|
|
1593
1547
|
}
|
|
1594
1548
|
}
|
|
1595
|
-
logger.debug("EventService", "Fetching events", {
|
|
1596
|
-
userId: this.user.id,
|
|
1597
|
-
organisationIdForRpc,
|
|
1598
|
-
appName: this.appName,
|
|
1599
|
-
hasSelectedEvent: !!this.selectedEvent,
|
|
1600
|
-
hasSelectedOrganisation: !!this.selectedOrganisation,
|
|
1601
|
-
isSuperAdmin: userIsSuperAdmin
|
|
1602
|
-
});
|
|
1603
1549
|
let { data, error: rpcError } = await this.supabaseClient.rpc("data_user_events_get", {
|
|
1604
1550
|
p_user_id: this.user.id,
|
|
1605
1551
|
p_organisation_id: organisationIdForRpc,
|
|
1606
1552
|
p_app_name: this.appName
|
|
1607
1553
|
});
|
|
1608
|
-
logger.debug("EventService", "RPC response", {
|
|
1609
|
-
dataLength: data?.length || 0,
|
|
1610
|
-
hasError: !!rpcError,
|
|
1611
|
-
error: rpcError
|
|
1612
|
-
});
|
|
1613
1554
|
if (rpcError) {
|
|
1614
1555
|
logger.error("EventService", "RPC error fetching events:", rpcError);
|
|
1615
1556
|
throw new Error(rpcError.message || "Failed to fetch events");
|
|
@@ -1652,76 +1593,40 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1652
1593
|
this.selectedEvent = null;
|
|
1653
1594
|
this.setSelectedEventId?.(null);
|
|
1654
1595
|
this.userClearedEventRef = previousUserClearedRef;
|
|
1655
|
-
logger.debug("EventService", "Cleared selected event - no longer in events list", {
|
|
1656
|
-
previousEventId: selectedEventId,
|
|
1657
|
-
eventsCount: transformedEvents.length
|
|
1658
|
-
});
|
|
1659
1596
|
}
|
|
1660
1597
|
}
|
|
1661
1598
|
this.hasAutoSelectedRef = false;
|
|
1662
1599
|
if (!skipLoadPersisted) {
|
|
1663
1600
|
const persistedEventLoaded = await this.loadPersistedEvent(transformedEvents);
|
|
1664
|
-
logger.debug("EventService", "Event selection check", {
|
|
1665
|
-
persistedEventLoaded,
|
|
1666
|
-
userClearedEventRef: this.userClearedEventRef,
|
|
1667
|
-
eventsCount: transformedEvents.length,
|
|
1668
|
-
hasSelectedEvent: !!this.selectedEvent
|
|
1669
|
-
});
|
|
1670
1601
|
if (!persistedEventLoaded && !this.userClearedEventRef) {
|
|
1671
1602
|
const nextEvent = this.getNextEventByDate(transformedEvents);
|
|
1672
|
-
logger.debug("EventService", "Auto-selection attempt", {
|
|
1673
|
-
nextEventFound: !!nextEvent,
|
|
1674
|
-
nextEventId: nextEvent?.event_id,
|
|
1675
|
-
nextEventDate: nextEvent?.event_date
|
|
1676
|
-
});
|
|
1677
1603
|
if (nextEvent) {
|
|
1678
1604
|
this.hasAutoSelectedRef = true;
|
|
1679
1605
|
this.setSelectedEvent(nextEvent);
|
|
1680
|
-
logger.debug("EventService", "Auto-selected next event", {
|
|
1681
|
-
eventId: nextEvent.event_id,
|
|
1682
|
-
eventName: nextEvent.event_name,
|
|
1683
|
-
eventDate: nextEvent.event_date
|
|
1684
|
-
});
|
|
1685
|
-
} else {
|
|
1686
|
-
logger.debug("EventService", "No next event found for auto-selection", {
|
|
1687
|
-
eventsCount: transformedEvents.length,
|
|
1688
|
-
eventsWithDates: transformedEvents.filter((e) => e.event_date).length
|
|
1689
|
-
});
|
|
1690
1606
|
}
|
|
1691
1607
|
} else if (persistedEventLoaded) {
|
|
1692
|
-
logger.debug("EventService", "Skipped auto-selection - persisted event loaded");
|
|
1693
1608
|
} else if (this.userClearedEventRef) {
|
|
1694
|
-
logger.debug("EventService", "Skipped auto-selection - user explicitly cleared event");
|
|
1695
1609
|
}
|
|
1696
1610
|
} else {
|
|
1697
1611
|
if (!this.userClearedEventRef) {
|
|
1698
1612
|
const nextEvent = this.getNextEventByDate(transformedEvents);
|
|
1699
|
-
logger.debug("EventService", "Auto-selection attempt (skip persisted)", {
|
|
1700
|
-
nextEventFound: !!nextEvent,
|
|
1701
|
-
nextEventId: nextEvent?.event_id
|
|
1702
|
-
});
|
|
1703
1613
|
if (nextEvent) {
|
|
1704
1614
|
this.hasAutoSelectedRef = true;
|
|
1705
1615
|
this.setSelectedEvent(nextEvent);
|
|
1706
|
-
logger.debug("EventService", "Auto-selected next event (skip persisted)", {
|
|
1707
|
-
eventId: nextEvent.event_id,
|
|
1708
|
-
eventName: nextEvent.event_name
|
|
1709
|
-
});
|
|
1710
1616
|
}
|
|
1711
1617
|
} else {
|
|
1712
|
-
logger.debug("EventService", "Skipped auto-selection (skip persisted) - user explicitly cleared event");
|
|
1713
1618
|
}
|
|
1714
1619
|
}
|
|
1715
1620
|
}
|
|
1716
1621
|
} catch (err) {
|
|
1717
1622
|
logger.error("EventService", "Error fetching events:", err);
|
|
1718
1623
|
const _error = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
1719
|
-
|
|
1624
|
+
{
|
|
1720
1625
|
this.error = _error;
|
|
1721
1626
|
this.events = [];
|
|
1722
1627
|
}
|
|
1723
1628
|
} finally {
|
|
1724
|
-
|
|
1629
|
+
{
|
|
1725
1630
|
this._isLoading = false;
|
|
1726
1631
|
}
|
|
1727
1632
|
this.isFetchingRef = false;
|
|
@@ -1768,10 +1673,7 @@ var _EventService = class _EventService extends BaseService {
|
|
|
1768
1673
|
};
|
|
1769
1674
|
_EventService.instanceCount = 0;
|
|
1770
1675
|
var EventService = _EventService;
|
|
1771
|
-
|
|
1772
|
-
// src/providers/services/EventServiceProvider.tsx
|
|
1773
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1774
|
-
var EventServiceContext = createContext3(null);
|
|
1676
|
+
var EventServiceContext = createContext(null);
|
|
1775
1677
|
function EventServiceProvider({
|
|
1776
1678
|
children,
|
|
1777
1679
|
supabaseClient,
|
|
@@ -1781,51 +1683,29 @@ function EventServiceProvider({
|
|
|
1781
1683
|
selectedOrganisation,
|
|
1782
1684
|
setSelectedEventId
|
|
1783
1685
|
}) {
|
|
1784
|
-
const eventServiceRef =
|
|
1785
|
-
const initializingRef =
|
|
1686
|
+
const eventServiceRef = useRef(null);
|
|
1687
|
+
const initializingRef = useRef(false);
|
|
1786
1688
|
if (!eventServiceRef.current) {
|
|
1787
1689
|
eventServiceRef.current = new EventService(supabaseClient, user, session, appName, selectedOrganisation, setSelectedEventId);
|
|
1788
1690
|
}
|
|
1789
1691
|
const eventService = eventServiceRef.current;
|
|
1790
|
-
|
|
1692
|
+
useEffect(() => {
|
|
1791
1693
|
let isMounted = true;
|
|
1792
|
-
logger.debug("EventServiceProvider", "useEffect triggered", {
|
|
1793
|
-
hasUser: !!user,
|
|
1794
|
-
userId: user?.id,
|
|
1795
|
-
hasSession: !!session,
|
|
1796
|
-
appName,
|
|
1797
|
-
isInitializing: initializingRef.current
|
|
1798
|
-
});
|
|
1799
1694
|
if (initializingRef.current) {
|
|
1800
|
-
logger.debug("EventServiceProvider", "Skipping - already initializing");
|
|
1801
1695
|
return;
|
|
1802
1696
|
}
|
|
1803
1697
|
const updateAndInitialize = async () => {
|
|
1804
1698
|
initializingRef.current = true;
|
|
1805
1699
|
try {
|
|
1806
|
-
logger.debug("EventServiceProvider", "Updating dependencies and initializing", {
|
|
1807
|
-
hasUser: !!user,
|
|
1808
|
-
userId: user?.id,
|
|
1809
|
-
hasSession: !!session,
|
|
1810
|
-
appName,
|
|
1811
|
-
hasSelectedOrganisation: !!selectedOrganisation
|
|
1812
|
-
});
|
|
1813
1700
|
await eventService.updateDependencies(supabaseClient, user, session, appName, selectedOrganisation, setSelectedEventId);
|
|
1814
1701
|
if (!isMounted) return;
|
|
1815
1702
|
if (user && session && supabaseClient && appName) {
|
|
1816
|
-
logger.debug("EventServiceProvider", "Initializing event service");
|
|
1817
1703
|
await eventService.initialize().catch((error) => {
|
|
1818
1704
|
if (isMounted) {
|
|
1819
1705
|
logger.error("EventServiceProvider", "Failed to initialize event service:", error);
|
|
1820
1706
|
}
|
|
1821
1707
|
});
|
|
1822
1708
|
} else {
|
|
1823
|
-
logger.debug("EventServiceProvider", "Skipping initialization - missing required dependencies", {
|
|
1824
|
-
hasUser: !!user,
|
|
1825
|
-
hasSession: !!session,
|
|
1826
|
-
hasSupabaseClient: !!supabaseClient,
|
|
1827
|
-
appName
|
|
1828
|
-
});
|
|
1829
1709
|
}
|
|
1830
1710
|
} finally {
|
|
1831
1711
|
initializingRef.current = false;
|
|
@@ -1837,20 +1717,17 @@ function EventServiceProvider({
|
|
|
1837
1717
|
initializingRef.current = false;
|
|
1838
1718
|
};
|
|
1839
1719
|
}, [supabaseClient, user, session, appName, selectedOrganisation, setSelectedEventId]);
|
|
1840
|
-
|
|
1720
|
+
useEffect(() => {
|
|
1841
1721
|
return () => {
|
|
1842
1722
|
eventService.cleanup();
|
|
1843
1723
|
};
|
|
1844
1724
|
}, [eventService]);
|
|
1845
|
-
const contextValue =
|
|
1725
|
+
const contextValue = useMemo(() => ({
|
|
1846
1726
|
eventService
|
|
1847
1727
|
}), [eventService]);
|
|
1848
|
-
return /* @__PURE__ */
|
|
1728
|
+
return /* @__PURE__ */ jsx(EventServiceContext.Provider, { value: contextValue, children });
|
|
1849
1729
|
}
|
|
1850
1730
|
|
|
1851
|
-
// src/providers/services/InactivityServiceProvider.tsx
|
|
1852
|
-
import { createContext as createContext4, useMemo as useMemo4, useEffect as useEffect4, useRef as useRef4 } from "react";
|
|
1853
|
-
|
|
1854
1731
|
// src/services/InactivityService.ts
|
|
1855
1732
|
var InactivityService = class extends BaseService {
|
|
1856
1733
|
constructor(supabaseClient, user, session, idleTimeoutMs = 30 * 60 * 1e3, warnBeforeMs = 60 * 1e3, onIdleLogout) {
|
|
@@ -2001,6 +1878,11 @@ var InactivityService = class extends BaseService {
|
|
|
2001
1878
|
} catch (error) {
|
|
2002
1879
|
logger.error("InactivityService", "Error during idle logout:", error);
|
|
2003
1880
|
}
|
|
1881
|
+
try {
|
|
1882
|
+
sessionStorage.clear();
|
|
1883
|
+
} catch (storageError) {
|
|
1884
|
+
logger.warn("InactivityService", "Failed to clear sessionStorage", { error: storageError });
|
|
1885
|
+
}
|
|
2004
1886
|
this.onIdleLogout?.("inactivity");
|
|
2005
1887
|
this.notify();
|
|
2006
1888
|
}
|
|
@@ -2021,6 +1903,11 @@ var InactivityService = class extends BaseService {
|
|
|
2021
1903
|
} catch (error) {
|
|
2022
1904
|
logger.error("InactivityService", "Error during manual sign out:", error);
|
|
2023
1905
|
}
|
|
1906
|
+
try {
|
|
1907
|
+
sessionStorage.clear();
|
|
1908
|
+
} catch (storageError) {
|
|
1909
|
+
logger.warn("InactivityService", "Failed to clear sessionStorage", { error: storageError });
|
|
1910
|
+
}
|
|
2024
1911
|
this.onIdleLogout?.("inactivity");
|
|
2025
1912
|
this.notify();
|
|
2026
1913
|
}
|
|
@@ -2234,10 +2121,7 @@ var InactivityService = class extends BaseService {
|
|
|
2234
2121
|
this._isTracking = true;
|
|
2235
2122
|
}
|
|
2236
2123
|
};
|
|
2237
|
-
|
|
2238
|
-
// src/providers/services/InactivityServiceProvider.tsx
|
|
2239
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
2240
|
-
var InactivityServiceContext = createContext4(null);
|
|
2124
|
+
var InactivityServiceContext = createContext(null);
|
|
2241
2125
|
function InactivityServiceProvider({
|
|
2242
2126
|
children,
|
|
2243
2127
|
supabaseClient,
|
|
@@ -2249,12 +2133,12 @@ function InactivityServiceProvider({
|
|
|
2249
2133
|
// REQUIRED: No default - must be explicitly provided
|
|
2250
2134
|
onIdleLogout
|
|
2251
2135
|
}) {
|
|
2252
|
-
const inactivityServiceRef =
|
|
2136
|
+
const inactivityServiceRef = useRef(null);
|
|
2253
2137
|
if (!inactivityServiceRef.current) {
|
|
2254
2138
|
inactivityServiceRef.current = new InactivityService(supabaseClient, user, session, idleTimeoutMs, warnBeforeMs, onIdleLogout);
|
|
2255
2139
|
}
|
|
2256
2140
|
const inactivityService = inactivityServiceRef.current;
|
|
2257
|
-
|
|
2141
|
+
useEffect(() => {
|
|
2258
2142
|
inactivityService.updateDependencies(supabaseClient, user, session, idleTimeoutMs, warnBeforeMs, onIdleLogout);
|
|
2259
2143
|
let isMounted = true;
|
|
2260
2144
|
inactivityService.initialize().catch((error) => {
|
|
@@ -2266,27 +2150,24 @@ function InactivityServiceProvider({
|
|
|
2266
2150
|
isMounted = false;
|
|
2267
2151
|
};
|
|
2268
2152
|
}, [inactivityService, supabaseClient, user, session, idleTimeoutMs, warnBeforeMs, onIdleLogout]);
|
|
2269
|
-
|
|
2153
|
+
useEffect(() => {
|
|
2270
2154
|
return () => {
|
|
2271
2155
|
inactivityService.cleanup();
|
|
2272
2156
|
};
|
|
2273
2157
|
}, [inactivityService]);
|
|
2274
|
-
const contextValue =
|
|
2158
|
+
const contextValue = useMemo(() => ({
|
|
2275
2159
|
inactivityService
|
|
2276
2160
|
}), [inactivityService]);
|
|
2277
|
-
return /* @__PURE__ */
|
|
2161
|
+
return /* @__PURE__ */ jsx(InactivityServiceContext.Provider, { value: contextValue, children });
|
|
2278
2162
|
}
|
|
2279
|
-
|
|
2280
|
-
// src/hooks/services/useAuthService.ts
|
|
2281
|
-
import { useContext, useReducer, useEffect as useEffect5, useRef as useRef5 } from "react";
|
|
2282
2163
|
function useAuthService() {
|
|
2283
2164
|
const context = useContext(AuthServiceContext);
|
|
2284
2165
|
if (!context) {
|
|
2285
2166
|
throw new Error("useAuthService must be used within AuthServiceProvider");
|
|
2286
2167
|
}
|
|
2287
2168
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
2288
|
-
const timeoutRef =
|
|
2289
|
-
|
|
2169
|
+
const timeoutRef = useRef(null);
|
|
2170
|
+
useEffect(() => {
|
|
2290
2171
|
const debouncedUpdate = () => {
|
|
2291
2172
|
if (timeoutRef.current) {
|
|
2292
2173
|
clearTimeout(timeoutRef.current);
|
|
@@ -2306,17 +2187,14 @@ function useAuthService() {
|
|
|
2306
2187
|
}, [context.authService]);
|
|
2307
2188
|
return context.authService;
|
|
2308
2189
|
}
|
|
2309
|
-
|
|
2310
|
-
// src/hooks/services/useOrganisationService.ts
|
|
2311
|
-
import { useContext as useContext2, useReducer as useReducer2, useEffect as useEffect6, useRef as useRef6 } from "react";
|
|
2312
2190
|
function useOrganisationService() {
|
|
2313
|
-
const context =
|
|
2191
|
+
const context = useContext(OrganisationServiceContext);
|
|
2314
2192
|
if (!context) {
|
|
2315
2193
|
throw new Error("useOrganisationService must be used within OrganisationServiceProvider");
|
|
2316
2194
|
}
|
|
2317
|
-
const [, forceUpdate] =
|
|
2318
|
-
const timeoutRef =
|
|
2319
|
-
|
|
2195
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
2196
|
+
const timeoutRef = useRef(null);
|
|
2197
|
+
useEffect(() => {
|
|
2320
2198
|
const debouncedUpdate = () => {
|
|
2321
2199
|
if (timeoutRef.current) {
|
|
2322
2200
|
clearTimeout(timeoutRef.current);
|
|
@@ -2359,17 +2237,14 @@ function useOrganisations() {
|
|
|
2359
2237
|
getPrimaryOrganisation: () => organisationService.getPrimaryOrganisation()
|
|
2360
2238
|
};
|
|
2361
2239
|
}
|
|
2362
|
-
|
|
2363
|
-
// src/hooks/services/useEventService.ts
|
|
2364
|
-
import { useContext as useContext3, useReducer as useReducer3, useEffect as useEffect7, useRef as useRef7 } from "react";
|
|
2365
2240
|
function useEventService() {
|
|
2366
|
-
const context =
|
|
2241
|
+
const context = useContext(EventServiceContext);
|
|
2367
2242
|
if (!context) {
|
|
2368
2243
|
throw new Error("useEventService must be used within EventServiceProvider");
|
|
2369
2244
|
}
|
|
2370
|
-
const [, forceUpdate] =
|
|
2371
|
-
const timeoutRef =
|
|
2372
|
-
|
|
2245
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
2246
|
+
const timeoutRef = useRef(null);
|
|
2247
|
+
useEffect(() => {
|
|
2373
2248
|
const debouncedUpdate = () => {
|
|
2374
2249
|
if (timeoutRef.current) {
|
|
2375
2250
|
clearTimeout(timeoutRef.current);
|
|
@@ -2389,17 +2264,14 @@ function useEventService() {
|
|
|
2389
2264
|
}, [context.eventService]);
|
|
2390
2265
|
return context.eventService;
|
|
2391
2266
|
}
|
|
2392
|
-
|
|
2393
|
-
// src/hooks/services/useInactivityService.ts
|
|
2394
|
-
import { useContext as useContext4, useReducer as useReducer4, useEffect as useEffect8, useRef as useRef8 } from "react";
|
|
2395
2267
|
function useInactivityService() {
|
|
2396
|
-
const context =
|
|
2268
|
+
const context = useContext(InactivityServiceContext);
|
|
2397
2269
|
if (!context) {
|
|
2398
2270
|
throw new Error("useInactivityService must be used within InactivityServiceProvider");
|
|
2399
2271
|
}
|
|
2400
|
-
const [, forceUpdate] =
|
|
2401
|
-
const timeoutRef =
|
|
2402
|
-
|
|
2272
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
2273
|
+
const timeoutRef = useRef(null);
|
|
2274
|
+
useEffect(() => {
|
|
2403
2275
|
const debouncedUpdate = () => {
|
|
2404
2276
|
if (timeoutRef.current) {
|
|
2405
2277
|
clearTimeout(timeoutRef.current);
|
|
@@ -2419,19 +2291,16 @@ function useInactivityService() {
|
|
|
2419
2291
|
}, [context.inactivityService]);
|
|
2420
2292
|
return context.inactivityService;
|
|
2421
2293
|
}
|
|
2422
|
-
|
|
2423
|
-
// src/hooks/useSessionRestoration.ts
|
|
2424
|
-
import { useContext as useContext5, useMemo as useMemo5, useEffect as useEffect9, useState as useState2 } from "react";
|
|
2425
2294
|
var log = createLogger("useSessionRestoration");
|
|
2426
|
-
var SESSION_RESTORATION_TIMEOUT_MS =
|
|
2295
|
+
var SESSION_RESTORATION_TIMEOUT_MS = 1e4;
|
|
2427
2296
|
function useSessionRestoration() {
|
|
2428
|
-
const context =
|
|
2297
|
+
const context = useContext(AuthServiceContext);
|
|
2429
2298
|
if (!context) {
|
|
2430
2299
|
throw new Error("useSessionRestoration must be used within AuthServiceProvider");
|
|
2431
2300
|
}
|
|
2432
2301
|
const { sessionRestoration } = context;
|
|
2433
|
-
const [hasTimedOut, setHasTimedOut] =
|
|
2434
|
-
|
|
2302
|
+
const [hasTimedOut, setHasTimedOut] = useState(false);
|
|
2303
|
+
useEffect(() => {
|
|
2435
2304
|
let timeoutHandle = null;
|
|
2436
2305
|
if (sessionRestoration.isRestoring && !sessionRestoration.restorationComplete && !sessionRestoration.restorationError) {
|
|
2437
2306
|
setHasTimedOut(false);
|
|
@@ -2452,18 +2321,15 @@ function useSessionRestoration() {
|
|
|
2452
2321
|
sessionRestoration.restorationComplete,
|
|
2453
2322
|
sessionRestoration.restorationError
|
|
2454
2323
|
]);
|
|
2455
|
-
return
|
|
2324
|
+
return useMemo(() => ({
|
|
2456
2325
|
...sessionRestoration,
|
|
2457
2326
|
hasTimedOut,
|
|
2458
2327
|
timeoutMs: SESSION_RESTORATION_TIMEOUT_MS
|
|
2459
2328
|
}), [sessionRestoration, hasTimedOut]);
|
|
2460
2329
|
}
|
|
2461
|
-
|
|
2462
|
-
// src/providers/services/UnifiedAuthProvider.tsx
|
|
2463
|
-
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
2464
|
-
var UnifiedAuthContext = createContext5(void 0);
|
|
2330
|
+
var UnifiedAuthContext = createContext(void 0);
|
|
2465
2331
|
var useUnifiedAuth = () => {
|
|
2466
|
-
const context =
|
|
2332
|
+
const context = useContext(UnifiedAuthContext);
|
|
2467
2333
|
if (!context) {
|
|
2468
2334
|
logger.error("useUnifiedAuth", "useUnifiedAuth must be used within a UnifiedAuthProvider");
|
|
2469
2335
|
throw new Error("useUnifiedAuth must be used within a UnifiedAuthProvider");
|
|
@@ -2487,46 +2353,21 @@ function UnifiedAuthContextProvider({
|
|
|
2487
2353
|
restorationComplete,
|
|
2488
2354
|
restorationError
|
|
2489
2355
|
} = sessionRestorationState;
|
|
2490
|
-
const sessionRestoration =
|
|
2356
|
+
const sessionRestoration = useMemo(() => ({
|
|
2491
2357
|
isRestoring,
|
|
2492
2358
|
restorationComplete,
|
|
2493
2359
|
restorationError
|
|
2494
2360
|
}), [isRestoring, restorationComplete, restorationError]);
|
|
2495
|
-
|
|
2496
|
-
try {
|
|
2497
|
-
eventService = useEventService();
|
|
2498
|
-
} catch (error) {
|
|
2499
|
-
eventService = {
|
|
2500
|
-
getEvents: () => [],
|
|
2501
|
-
getSelectedEvent: () => null,
|
|
2502
|
-
isLoading: () => false,
|
|
2503
|
-
getError: () => null,
|
|
2504
|
-
setSelectedEvent: () => {
|
|
2505
|
-
},
|
|
2506
|
-
refreshEvents: async () => {
|
|
2507
|
-
},
|
|
2508
|
-
subscribe: () => () => {
|
|
2509
|
-
}
|
|
2510
|
-
// No-op subscribe/unsubscribe for fallback
|
|
2511
|
-
};
|
|
2512
|
-
}
|
|
2361
|
+
const eventService = useEventService();
|
|
2513
2362
|
const currentUser = authService.getUser();
|
|
2514
2363
|
const currentSession = authService.getSession();
|
|
2515
2364
|
const isAuth = !!(currentUser && currentSession);
|
|
2516
|
-
const supabase =
|
|
2517
|
-
const [appId, setAppId] =
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
hasSession: !!currentSession,
|
|
2523
|
-
isAuth
|
|
2524
|
-
});
|
|
2525
|
-
}, [currentUser?.id, currentSession?.access_token, isAuth, authService]);
|
|
2526
|
-
const isResolvingAppIdRef = useRef9(false);
|
|
2527
|
-
const resolvedAppIdRef = useRef9(void 0);
|
|
2528
|
-
const resolvedUserIdRef = useRef9(void 0);
|
|
2529
|
-
useEffect10(() => {
|
|
2365
|
+
const supabase = useMemo(() => supabaseClientProp, [supabaseClientProp]);
|
|
2366
|
+
const [appId, setAppId] = useState(void 0);
|
|
2367
|
+
const isResolvingAppIdRef = useRef(false);
|
|
2368
|
+
const resolvedAppIdRef = useRef(void 0);
|
|
2369
|
+
const resolvedUserIdRef = useRef(void 0);
|
|
2370
|
+
useEffect(() => {
|
|
2530
2371
|
if (!isAuth) {
|
|
2531
2372
|
resolvedAppIdRef.current = void 0;
|
|
2532
2373
|
resolvedUserIdRef.current = void 0;
|
|
@@ -2545,7 +2386,7 @@ function UnifiedAuthContextProvider({
|
|
|
2545
2386
|
resolvedUserIdRef.current = currentUserId;
|
|
2546
2387
|
const userId = currentUserId;
|
|
2547
2388
|
const appNameValue = appName;
|
|
2548
|
-
import(
|
|
2389
|
+
import('./api-Y4MQWOFW.js').then(async ({ resolveAppContext, setupRBAC: setupRBAC2 }) => {
|
|
2549
2390
|
try {
|
|
2550
2391
|
setupRBAC2(supabase);
|
|
2551
2392
|
const result = await resolveAppContext({
|
|
@@ -2575,8 +2416,8 @@ function UnifiedAuthContextProvider({
|
|
|
2575
2416
|
});
|
|
2576
2417
|
}
|
|
2577
2418
|
}, [isAuth, currentUser?.id, supabase, appName]);
|
|
2578
|
-
const [, forceUpdate] =
|
|
2579
|
-
const forceUpdateTimeoutRef =
|
|
2419
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
2420
|
+
const forceUpdateTimeoutRef = useRef(null);
|
|
2580
2421
|
const debouncedForceUpdate = useCallback(() => {
|
|
2581
2422
|
if (forceUpdateTimeoutRef.current) {
|
|
2582
2423
|
clearTimeout(forceUpdateTimeoutRef.current);
|
|
@@ -2586,17 +2427,17 @@ function UnifiedAuthContextProvider({
|
|
|
2586
2427
|
forceUpdateTimeoutRef.current = null;
|
|
2587
2428
|
}, 100);
|
|
2588
2429
|
}, [forceUpdate]);
|
|
2589
|
-
const authServiceRef =
|
|
2590
|
-
const organisationServiceRef =
|
|
2591
|
-
const eventServiceRef =
|
|
2592
|
-
const inactivityServiceRef =
|
|
2593
|
-
|
|
2430
|
+
const authServiceRef = useRef(authService);
|
|
2431
|
+
const organisationServiceRef = useRef(organisationService);
|
|
2432
|
+
const eventServiceRef = useRef(eventService);
|
|
2433
|
+
const inactivityServiceRef = useRef(inactivityService);
|
|
2434
|
+
useEffect(() => {
|
|
2594
2435
|
authServiceRef.current = authService;
|
|
2595
2436
|
organisationServiceRef.current = organisationService;
|
|
2596
2437
|
eventServiceRef.current = eventService;
|
|
2597
2438
|
inactivityServiceRef.current = inactivityService;
|
|
2598
2439
|
}, [authService, organisationService, eventService, inactivityService]);
|
|
2599
|
-
|
|
2440
|
+
useEffect(() => {
|
|
2600
2441
|
const unsubscribeAuth = authServiceRef.current.subscribe(debouncedForceUpdate);
|
|
2601
2442
|
const unsubscribeOrg = organisationServiceRef.current.subscribe(debouncedForceUpdate);
|
|
2602
2443
|
const unsubscribeEvent = eventServiceRef.current.subscribe(debouncedForceUpdate);
|
|
@@ -2626,19 +2467,19 @@ function UnifiedAuthContextProvider({
|
|
|
2626
2467
|
const rawEvents = eventService.getEvents();
|
|
2627
2468
|
const rawOrganisations = organisationService.getOrganisations();
|
|
2628
2469
|
const rawUserMemberships = organisationService.getUserMemberships();
|
|
2629
|
-
const events =
|
|
2470
|
+
const events = useMemo(() => {
|
|
2630
2471
|
return rawEvents;
|
|
2631
2472
|
}, [
|
|
2632
2473
|
// Create dependency string from event IDs - only changes when events actually change
|
|
2633
2474
|
rawEvents.map((e) => e.event_id || e.id).join(",")
|
|
2634
2475
|
]);
|
|
2635
|
-
const organisations =
|
|
2476
|
+
const organisations = useMemo(() => {
|
|
2636
2477
|
return rawOrganisations;
|
|
2637
2478
|
}, [
|
|
2638
2479
|
// Create dependency string from organisation IDs - only changes when orgs actually change
|
|
2639
2480
|
rawOrganisations.map((o) => o.id).join(",")
|
|
2640
2481
|
]);
|
|
2641
|
-
const userMemberships =
|
|
2482
|
+
const userMemberships = useMemo(() => {
|
|
2642
2483
|
return rawUserMemberships;
|
|
2643
2484
|
}, [
|
|
2644
2485
|
// Create dependency string from membership IDs - only changes when memberships actually change
|
|
@@ -2652,7 +2493,7 @@ function UnifiedAuthContextProvider({
|
|
|
2652
2493
|
const timeRemaining = inactivityService.getTimeRemaining();
|
|
2653
2494
|
const showWarning = inactivityService.isWarningShown();
|
|
2654
2495
|
const isTracking = inactivityService.isTracking();
|
|
2655
|
-
const inactivityState =
|
|
2496
|
+
const inactivityState = useMemo(() => ({
|
|
2656
2497
|
showInactivityWarning,
|
|
2657
2498
|
inactivityTimeRemaining,
|
|
2658
2499
|
isIdle,
|
|
@@ -2689,7 +2530,7 @@ function UnifiedAuthContextProvider({
|
|
|
2689
2530
|
const handleIdleLogout = () => inactivityService.handleIdleLogout();
|
|
2690
2531
|
const handleStaySignedIn = () => inactivityService.handleStaySignedIn();
|
|
2691
2532
|
const handleSignOutNow = () => inactivityService.handleSignOutNow();
|
|
2692
|
-
const prevStateRef =
|
|
2533
|
+
const prevStateRef = useRef(null);
|
|
2693
2534
|
const isDev = import.meta.env.DEV || import.meta.env.MODE === "development";
|
|
2694
2535
|
if (isDev) {
|
|
2695
2536
|
const currentState = {
|
|
@@ -2702,7 +2543,7 @@ function UnifiedAuthContextProvider({
|
|
|
2702
2543
|
prevStateRef.current = currentState;
|
|
2703
2544
|
}
|
|
2704
2545
|
}
|
|
2705
|
-
const contextValue =
|
|
2546
|
+
const contextValue = useMemo(() => {
|
|
2706
2547
|
return {
|
|
2707
2548
|
// Auth state
|
|
2708
2549
|
user: currentUser,
|
|
@@ -2820,7 +2661,7 @@ function UnifiedAuthContextProvider({
|
|
|
2820
2661
|
handleStaySignedIn,
|
|
2821
2662
|
handleSignOutNow
|
|
2822
2663
|
]);
|
|
2823
|
-
return /* @__PURE__ */
|
|
2664
|
+
return /* @__PURE__ */ jsx(UnifiedAuthContext.Provider, { value: contextValue, children });
|
|
2824
2665
|
}
|
|
2825
2666
|
function EventServiceProviderWrapper({
|
|
2826
2667
|
children,
|
|
@@ -2832,15 +2673,9 @@ function EventServiceProviderWrapper({
|
|
|
2832
2673
|
const { selectedOrganisation } = useOrganisations();
|
|
2833
2674
|
const setSelectedEventId = useCallback(() => {
|
|
2834
2675
|
}, []);
|
|
2835
|
-
|
|
2836
|
-
logger.debug("EventServiceProviderWrapper", "Rendering with props", {
|
|
2837
|
-
hasUser: !!user,
|
|
2838
|
-
userId: user?.id,
|
|
2839
|
-
hasSession: !!session,
|
|
2840
|
-
selectedOrganisationId: selectedOrganisation?.id
|
|
2841
|
-
});
|
|
2676
|
+
useEffect(() => {
|
|
2842
2677
|
}, [user?.id, session?.access_token, selectedOrganisation?.id]);
|
|
2843
|
-
return /* @__PURE__ */
|
|
2678
|
+
return /* @__PURE__ */ jsx(
|
|
2844
2679
|
EventServiceProvider,
|
|
2845
2680
|
{
|
|
2846
2681
|
supabaseClient,
|
|
@@ -2867,17 +2702,12 @@ function ServiceAwareProviders({
|
|
|
2867
2702
|
dangerouslyDisableInactivity
|
|
2868
2703
|
}) {
|
|
2869
2704
|
const authService = useAuthService();
|
|
2870
|
-
const [userState, setUserState] =
|
|
2871
|
-
const [sessionState, setSessionState] =
|
|
2872
|
-
|
|
2705
|
+
const [userState, setUserState] = useState(() => authService.getUser());
|
|
2706
|
+
const [sessionState, setSessionState] = useState(() => authService.getSession());
|
|
2707
|
+
useEffect(() => {
|
|
2873
2708
|
const unsubscribe = authService.subscribe(() => {
|
|
2874
2709
|
const newUser = authService.getUser();
|
|
2875
2710
|
const newSession = authService.getSession();
|
|
2876
|
-
logger.debug("ServiceAwareProviders", "Auth service notified, updating state", {
|
|
2877
|
-
hasUser: !!newUser,
|
|
2878
|
-
userId: newUser?.id,
|
|
2879
|
-
hasSession: !!newSession
|
|
2880
|
-
});
|
|
2881
2711
|
setUserState(newUser);
|
|
2882
2712
|
setSessionState(newSession);
|
|
2883
2713
|
});
|
|
@@ -2885,28 +2715,20 @@ function ServiceAwareProviders({
|
|
|
2885
2715
|
}, [authService]);
|
|
2886
2716
|
const user = userState;
|
|
2887
2717
|
const session = sessionState;
|
|
2888
|
-
|
|
2889
|
-
logger.debug("ServiceAwareProviders", `User/session state [AuthService ID:${authService.getInstanceId?.() || "unknown"}]`, {
|
|
2890
|
-
hasUser: !!user,
|
|
2891
|
-
userId: user?.id,
|
|
2892
|
-
hasSession: !!session,
|
|
2893
|
-
sessionToken: session?.access_token ? "present" : "missing"
|
|
2894
|
-
});
|
|
2895
|
-
}, [user?.id, session?.access_token, authService]);
|
|
2896
|
-
return /* @__PURE__ */ jsx5(
|
|
2718
|
+
return /* @__PURE__ */ jsx(
|
|
2897
2719
|
OrganisationServiceProvider,
|
|
2898
2720
|
{
|
|
2899
2721
|
supabaseClient,
|
|
2900
2722
|
user,
|
|
2901
2723
|
session,
|
|
2902
|
-
children: /* @__PURE__ */
|
|
2724
|
+
children: /* @__PURE__ */ jsx(
|
|
2903
2725
|
EventServiceProviderWrapper,
|
|
2904
2726
|
{
|
|
2905
2727
|
supabaseClient,
|
|
2906
2728
|
user,
|
|
2907
2729
|
session,
|
|
2908
2730
|
appName,
|
|
2909
|
-
children: /* @__PURE__ */
|
|
2731
|
+
children: /* @__PURE__ */ jsx(
|
|
2910
2732
|
InactivityServiceProvider,
|
|
2911
2733
|
{
|
|
2912
2734
|
supabaseClient,
|
|
@@ -2915,7 +2737,7 @@ function ServiceAwareProviders({
|
|
|
2915
2737
|
idleTimeoutMs,
|
|
2916
2738
|
warnBeforeMs,
|
|
2917
2739
|
onIdleLogout,
|
|
2918
|
-
children: /* @__PURE__ */
|
|
2740
|
+
children: /* @__PURE__ */ jsx(
|
|
2919
2741
|
UnifiedAuthContextProvider,
|
|
2920
2742
|
{
|
|
2921
2743
|
appName,
|
|
@@ -2954,8 +2776,8 @@ function UnifiedAuthProvider({
|
|
|
2954
2776
|
renderInactivityWarning,
|
|
2955
2777
|
dangerouslyDisableInactivity = false
|
|
2956
2778
|
}) {
|
|
2957
|
-
const clientRef =
|
|
2958
|
-
|
|
2779
|
+
const clientRef = useRef(supabaseClient);
|
|
2780
|
+
useEffect(() => {
|
|
2959
2781
|
if (clientRef.current !== supabaseClient) {
|
|
2960
2782
|
logger.warn("UnifiedAuthProvider", "Supabase client reference changed - this may indicate multiple client instances are being created", {
|
|
2961
2783
|
previousClient: clientRef.current,
|
|
@@ -2963,8 +2785,6 @@ function UnifiedAuthProvider({
|
|
|
2963
2785
|
note: 'Ensure you create the Supabase client once and reuse it. Creating multiple clients can cause performance issues and the "Multiple GoTrueClient instances" warning.'
|
|
2964
2786
|
});
|
|
2965
2787
|
clientRef.current = supabaseClient;
|
|
2966
|
-
} else {
|
|
2967
|
-
logger.debug("UnifiedAuthProvider", "Supabase client reference is stable");
|
|
2968
2788
|
}
|
|
2969
2789
|
}, [supabaseClient]);
|
|
2970
2790
|
if (supabaseClient && !isRBACInitialized()) {
|
|
@@ -2975,7 +2795,7 @@ function UnifiedAuthProvider({
|
|
|
2975
2795
|
logger.error("UnifiedAuthProvider", "Failed to initialize RBAC", err);
|
|
2976
2796
|
}
|
|
2977
2797
|
}
|
|
2978
|
-
return /* @__PURE__ */
|
|
2798
|
+
return /* @__PURE__ */ jsx(AuthServiceProvider, { supabaseClient, appName, children: /* @__PURE__ */ jsx(
|
|
2979
2799
|
ServiceAwareProviders,
|
|
2980
2800
|
{
|
|
2981
2801
|
supabaseClient,
|
|
@@ -2993,23 +2813,4 @@ function UnifiedAuthProvider({
|
|
|
2993
2813
|
) });
|
|
2994
2814
|
}
|
|
2995
2815
|
|
|
2996
|
-
export {
|
|
2997
|
-
AuthServiceContext,
|
|
2998
|
-
AuthServiceProvider,
|
|
2999
|
-
OrganisationServiceContext,
|
|
3000
|
-
OrganisationServiceProvider,
|
|
3001
|
-
EventServiceContext,
|
|
3002
|
-
EventServiceProvider,
|
|
3003
|
-
InactivityServiceContext,
|
|
3004
|
-
InactivityServiceProvider,
|
|
3005
|
-
useAuthService,
|
|
3006
|
-
useOrganisationService,
|
|
3007
|
-
useOrganisations,
|
|
3008
|
-
useEventService,
|
|
3009
|
-
useInactivityService,
|
|
3010
|
-
useSessionRestoration,
|
|
3011
|
-
UnifiedAuthContext,
|
|
3012
|
-
useUnifiedAuth,
|
|
3013
|
-
UnifiedAuthProvider
|
|
3014
|
-
};
|
|
3015
|
-
//# sourceMappingURL=chunk-IHB5DR3H.js.map
|
|
2816
|
+
export { AuthServiceContext, AuthServiceProvider, EventServiceContext, EventServiceProvider, InactivityServiceContext, InactivityServiceProvider, OrganisationServiceContext, OrganisationServiceProvider, UnifiedAuthContext, UnifiedAuthProvider, useAuthService, useEventService, useInactivityService, useOrganisationService, useOrganisations, useSessionRestoration, useUnifiedAuth };
|