spine-framework 0.1.0
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/.framework/README.md +129 -0
- package/.framework/cli/bin.cjs +14 -0
- package/.framework/cli/commands/agents.ts +153 -0
- package/.framework/cli/commands/auth.ts +94 -0
- package/.framework/cli/commands/create-app.ts +185 -0
- package/.framework/cli/commands/dev.ts +295 -0
- package/.framework/cli/commands/doctor.ts +442 -0
- package/.framework/cli/commands/generate.ts +332 -0
- package/.framework/cli/commands/init.ts +272 -0
- package/.framework/cli/commands/install-app.ts +391 -0
- package/.framework/cli/commands/items.ts +253 -0
- package/.framework/cli/commands/migrations.ts +141 -0
- package/.framework/cli/commands/pipelines.ts +166 -0
- package/.framework/cli/commands/status.ts +197 -0
- package/.framework/cli/commands/system.ts +184 -0
- package/.framework/cli/commands/test.ts +227 -0
- package/.framework/cli/commands/uninstall-app.ts +166 -0
- package/.framework/cli/context.ts +268 -0
- package/.framework/cli/env-loader.ts +36 -0
- package/.framework/cli/index.ts +106 -0
- package/.framework/cli/welcome.cjs +45 -0
- package/.framework/docs/API.md +384 -0
- package/.framework/docs/STABILITY.md +52 -0
- package/.framework/docs/admin-routes.md +76 -0
- package/.framework/docs/api-docs-progress.md +38 -0
- package/.framework/docs/api-governance.md +146 -0
- package/.framework/docs/api-testing-results.md +212 -0
- package/.framework/docs/apis/admin-configs.md +567 -0
- package/.framework/docs/apis/admin-data.md +272 -0
- package/.framework/docs/apis/index.md +231 -0
- package/.framework/docs/apis/internal.md +295 -0
- package/.framework/docs/apis/runtime.md +537 -0
- package/.framework/docs/assembly-launch-guide.md +138 -0
- package/.framework/docs/audit-results.md +590 -0
- package/.framework/docs/authorization-model.md +170 -0
- package/.framework/docs/db-api-inventory.md +95 -0
- package/.framework/docs/examples/custom-app/README.md +77 -0
- package/.framework/docs/examples/custom-function/README.md +27 -0
- package/.framework/docs/examples/custom-function/handler.ts +48 -0
- package/.framework/docs/examples/custom-webhook/README.md +68 -0
- package/.framework/docs/gap-remediation-backlog.md +103 -0
- package/.framework/docs/guides/cli-guide.md +224 -0
- package/.framework/docs/guides/getting-started.md +103 -0
- package/.framework/docs/guides/import-guide.md +193 -0
- package/.framework/docs/guides/testing-guide.md +229 -0
- package/.framework/docs/permission-examples.md +326 -0
- package/.framework/docs/ui-adoption-verification.md +111 -0
- package/.framework/docs/ui-api-coverage.md +84 -0
- package/.framework/docs/v2-compatibility-audit.md +228 -0
- package/.framework/functions/.gitkeep +1 -0
- package/.framework/functions/_shared/agent-runner.ts +1097 -0
- package/.framework/functions/_shared/app-manifest.ts +184 -0
- package/.framework/functions/_shared/audit.ts +150 -0
- package/.framework/functions/_shared/db.ts +174 -0
- package/.framework/functions/_shared/index.ts +382 -0
- package/.framework/functions/_shared/middleware.ts +490 -0
- package/.framework/functions/_shared/permissions.ts +1325 -0
- package/.framework/functions/_shared/pipeline-runner.ts +731 -0
- package/.framework/functions/_shared/principal.ts +760 -0
- package/.framework/functions/_shared/schema-utils.ts +967 -0
- package/.framework/functions/_shared/testing.ts +258 -0
- package/.framework/functions/_shared/trigger-engine.ts +425 -0
- package/.framework/functions/_shared/webhook-registration.ts +168 -0
- package/.framework/functions/_shared/webhook-registry.ts +129 -0
- package/.framework/functions/account-nodes.ts +111 -0
- package/.framework/functions/admin-data.ts +606 -0
- package/.framework/functions/ai-agents.ts +323 -0
- package/.framework/functions/api-keys.ts +376 -0
- package/.framework/functions/apps.ts +483 -0
- package/.framework/functions/auth.ts +196 -0
- package/.framework/functions/debug-auth.ts +107 -0
- package/.framework/functions/embeddings.ts +556 -0
- package/.framework/functions/integration-routes.ts +523 -0
- package/.framework/functions/integrations.ts +319 -0
- package/.framework/functions/item-progress.ts +272 -0
- package/.framework/functions/logs.ts +438 -0
- package/.framework/functions/observability.ts +275 -0
- package/.framework/functions/pipeline-executions.ts +494 -0
- package/.framework/functions/pipelines.ts +485 -0
- package/.framework/functions/prompt-configs.ts +339 -0
- package/.framework/functions/roles.ts +387 -0
- package/.framework/functions/system-cron.ts +742 -0
- package/.framework/functions/system.ts +323 -0
- package/.framework/functions/tests.ts +119 -0
- package/.framework/functions/timers.ts +357 -0
- package/.framework/functions/triggers.ts +563 -0
- package/.framework/functions/types.ts +604 -0
- package/.framework/migrations/000_foundation.sql +1256 -0
- package/.framework/migrations/001_seed.sql +92 -0
- package/.framework/migrations/002_seed_constraints.sql +13 -0
- package/.framework/migrations/003_auth_user_trigger.sql +59 -0
- package/.framework/src/App.tsx +126 -0
- package/.framework/src/apps/admin/index.tsx +173 -0
- package/.framework/src/components/AppWrapper.tsx +56 -0
- package/.framework/src/components/CustomAppLoader.tsx +116 -0
- package/.framework/src/components/admin/AdminListPage.tsx +151 -0
- package/.framework/src/components/admin/AdminSidebar.tsx +166 -0
- package/.framework/src/components/admin/AdminStatsCard.tsx +62 -0
- package/.framework/src/components/admin/SortableTableHeader.tsx +42 -0
- package/.framework/src/components/app-shell/GenericAppShell.tsx +181 -0
- package/.framework/src/components/app-shell/GenericDetailPage.tsx +200 -0
- package/.framework/src/components/app-shell/GenericListPage.tsx +116 -0
- package/.framework/src/components/app-sidebar.tsx +228 -0
- package/.framework/src/components/auth/ProtectedRoute.tsx +88 -0
- package/.framework/src/components/layout/AppShell.tsx +91 -0
- package/.framework/src/components/layout/Header.tsx +88 -0
- package/.framework/src/components/layout/Layout.tsx +95 -0
- package/.framework/src/components/layout/Sidebar.tsx +329 -0
- package/.framework/src/components/runtime/DataDetailHeader.tsx +77 -0
- package/.framework/src/components/runtime/DataDetailPage.tsx +171 -0
- package/.framework/src/components/runtime/DataFilters.tsx +91 -0
- package/.framework/src/components/runtime/DataHeader.tsx +68 -0
- package/.framework/src/components/runtime/DataListPage.tsx +124 -0
- package/.framework/src/components/runtime/DataStats.tsx +70 -0
- package/.framework/src/components/runtime/DataTable.tsx +174 -0
- package/.framework/src/components/runtime/SchemaDetailForm.tsx +134 -0
- package/.framework/src/components/runtime/index.ts +18 -0
- package/.framework/src/components/search-form.tsx +29 -0
- package/.framework/src/components/shared/AgentView.tsx +213 -0
- package/.framework/src/components/shared/FieldRenderer.tsx +478 -0
- package/.framework/src/components/shared/SchemaFields.tsx +226 -0
- package/.framework/src/components/ui/DataTable.tsx +343 -0
- package/.framework/src/components/ui/Form.tsx +281 -0
- package/.framework/src/components/ui/ItemCard.tsx +296 -0
- package/.framework/src/components/ui/ItemListView.tsx +308 -0
- package/.framework/src/components/ui/LoadingSpinner.tsx +52 -0
- package/.framework/src/components/ui/Modal.tsx +61 -0
- package/.framework/src/components/ui/RichTextEditor.tsx +210 -0
- package/.framework/src/components/ui/accordion.tsx +82 -0
- package/.framework/src/components/ui/alert-dialog.tsx +197 -0
- package/.framework/src/components/ui/alert.tsx +76 -0
- package/.framework/src/components/ui/aspect-ratio.tsx +11 -0
- package/.framework/src/components/ui/avatar.tsx +110 -0
- package/.framework/src/components/ui/badge.tsx +49 -0
- package/.framework/src/components/ui/breadcrumb.tsx +122 -0
- package/.framework/src/components/ui/button-group.tsx +83 -0
- package/.framework/src/components/ui/button.tsx +65 -0
- package/.framework/src/components/ui/calendar.tsx +222 -0
- package/.framework/src/components/ui/card.tsx +100 -0
- package/.framework/src/components/ui/carousel.tsx +240 -0
- package/.framework/src/components/ui/chart.tsx +373 -0
- package/.framework/src/components/ui/checkbox.tsx +31 -0
- package/.framework/src/components/ui/collapsible.tsx +33 -0
- package/.framework/src/components/ui/combobox.tsx +299 -0
- package/.framework/src/components/ui/command.tsx +193 -0
- package/.framework/src/components/ui/context-menu.tsx +261 -0
- package/.framework/src/components/ui/dialog.tsx +165 -0
- package/.framework/src/components/ui/direction.tsx +22 -0
- package/.framework/src/components/ui/drawer.tsx +132 -0
- package/.framework/src/components/ui/dropdown-menu.tsx +269 -0
- package/.framework/src/components/ui/empty.tsx +104 -0
- package/.framework/src/components/ui/field.tsx +238 -0
- package/.framework/src/components/ui/hover-card.tsx +42 -0
- package/.framework/src/components/ui/input-group.tsx +153 -0
- package/.framework/src/components/ui/input-otp.tsx +87 -0
- package/.framework/src/components/ui/input.tsx +19 -0
- package/.framework/src/components/ui/item.tsx +196 -0
- package/.framework/src/components/ui/kbd.tsx +26 -0
- package/.framework/src/components/ui/label.tsx +22 -0
- package/.framework/src/components/ui/menubar.tsx +277 -0
- package/.framework/src/components/ui/native-select.tsx +61 -0
- package/.framework/src/components/ui/navigation-menu.tsx +164 -0
- package/.framework/src/components/ui/pagination.tsx +129 -0
- package/.framework/src/components/ui/popover.tsx +87 -0
- package/.framework/src/components/ui/progress.tsx +31 -0
- package/.framework/src/components/ui/radio-group.tsx +42 -0
- package/.framework/src/components/ui/resizable.tsx +50 -0
- package/.framework/src/components/ui/scroll-area.tsx +53 -0
- package/.framework/src/components/ui/select.tsx +195 -0
- package/.framework/src/components/ui/separator.tsx +26 -0
- package/.framework/src/components/ui/sheet.tsx +145 -0
- package/.framework/src/components/ui/sidebar.tsx +706 -0
- package/.framework/src/components/ui/skeleton.tsx +13 -0
- package/.framework/src/components/ui/slider.tsx +59 -0
- package/.framework/src/components/ui/sonner.tsx +47 -0
- package/.framework/src/components/ui/spinner.tsx +10 -0
- package/.framework/src/components/ui/switch.tsx +33 -0
- package/.framework/src/components/ui/table-primitives.tsx +141 -0
- package/.framework/src/components/ui/table.tsx +114 -0
- package/.framework/src/components/ui/tabs.tsx +90 -0
- package/.framework/src/components/ui/textarea.tsx +18 -0
- package/.framework/src/components/ui/toggle-group.tsx +89 -0
- package/.framework/src/components/ui/toggle.tsx +45 -0
- package/.framework/src/components/ui/tooltip.tsx +57 -0
- package/.framework/src/contexts/AppContext.tsx +133 -0
- package/.framework/src/contexts/AuthContext.tsx +371 -0
- package/.framework/src/hooks/use-mobile.ts +19 -0
- package/.framework/src/hooks/useApi.ts +526 -0
- package/.framework/src/hooks/useApps.ts +114 -0
- package/.framework/src/hooks/useEntityList.ts +190 -0
- package/.framework/src/hooks/useEntityRecord.ts +308 -0
- package/.framework/src/hooks/useForm.ts +307 -0
- package/.framework/src/hooks/useListSchema.ts +264 -0
- package/.framework/src/hooks/useSchemaRecord.ts +223 -0
- package/.framework/src/index.css +128 -0
- package/.framework/src/lib/api.ts +156 -0
- package/.framework/src/lib/supabase.ts +94 -0
- package/.framework/src/lib/utils.ts +317 -0
- package/.framework/src/main.tsx +27 -0
- package/.framework/src/pages/DashboardPage.tsx +181 -0
- package/.framework/src/pages/NotFoundPage.tsx +39 -0
- package/.framework/src/pages/admin/AIAgentDetailPage.tsx +161 -0
- package/.framework/src/pages/admin/AIAgentsPage.tsx +318 -0
- package/.framework/src/pages/admin/APIKeyDetailPage.tsx +199 -0
- package/.framework/src/pages/admin/APIKeysPage.tsx +303 -0
- package/.framework/src/pages/admin/AlertsConfigPage.tsx +523 -0
- package/.framework/src/pages/admin/AppDetailPage.tsx +493 -0
- package/.framework/src/pages/admin/AppsPage.tsx +355 -0
- package/.framework/src/pages/admin/DesignedPage.tsx +491 -0
- package/.framework/src/pages/admin/EmbeddingDetailPage.tsx +534 -0
- package/.framework/src/pages/admin/EmbeddingsPage.tsx +424 -0
- package/.framework/src/pages/admin/ExtendedShadcnTestPage.tsx +176 -0
- package/.framework/src/pages/admin/IncrementalShadcnTestPage.tsx +109 -0
- package/.framework/src/pages/admin/IntegratedDashboard.tsx +402 -0
- package/.framework/src/pages/admin/IntegrationDetailPage.tsx +187 -0
- package/.framework/src/pages/admin/IntegrationsPage.tsx +301 -0
- package/.framework/src/pages/admin/LogsPage.tsx +283 -0
- package/.framework/src/pages/admin/MinimalShadcnTestPage.tsx +85 -0
- package/.framework/src/pages/admin/ObservabilityDashboard.tsx +470 -0
- package/.framework/src/pages/admin/PipelineDetailPage.tsx +183 -0
- package/.framework/src/pages/admin/PipelineExecutionsPage.tsx +279 -0
- package/.framework/src/pages/admin/PipelinesPage.tsx +390 -0
- package/.framework/src/pages/admin/PromptConfigDetailPage.tsx +299 -0
- package/.framework/src/pages/admin/PromptConfigsPage.tsx +292 -0
- package/.framework/src/pages/admin/ProperlyDesignedPage.tsx +434 -0
- package/.framework/src/pages/admin/RoleDetailPage.tsx +273 -0
- package/.framework/src/pages/admin/RolesPage.tsx +292 -0
- package/.framework/src/pages/admin/SelectTestPage.tsx +61 -0
- package/.framework/src/pages/admin/ShadcnTestPage.tsx +588 -0
- package/.framework/src/pages/admin/SimpleDashboard.tsx +387 -0
- package/.framework/src/pages/admin/TestRunDetailPage.tsx +172 -0
- package/.framework/src/pages/admin/TestingDashboard.tsx +257 -0
- package/.framework/src/pages/admin/TimerDetailPage.tsx +151 -0
- package/.framework/src/pages/admin/TimersPage.tsx +376 -0
- package/.framework/src/pages/admin/TriggerDetailPage.tsx +149 -0
- package/.framework/src/pages/admin/TriggersPage.tsx +381 -0
- package/.framework/src/pages/admin/TypeDetailPage.tsx +694 -0
- package/.framework/src/pages/admin/TypesPage.tsx +295 -0
- package/.framework/src/pages/auth/LoginPage.tsx +188 -0
- package/.framework/src/pages/auth/RegisterPage.tsx +163 -0
- package/.framework/src/pages/spine-framework/APIPage.tsx +17 -0
- package/.framework/src/pages/spine-framework/CLIPage.tsx +25 -0
- package/.framework/src/types/auth.ts +125 -0
- package/.framework/src/types/types.ts +407 -0
- package/STRUCTURE.md +150 -0
- package/config/components.json +25 -0
- package/config/deno.lock +108 -0
- package/config/package-lock.json +17183 -0
- package/config/postcss.config.cjs +10 -0
- package/config/tailwind.config.cjs +78 -0
- package/config/tsconfig.build.json +32 -0
- package/config/tsconfig.cli.json +18 -0
- package/config/tsconfig.json +41 -0
- package/config/tsconfig.node.json +17 -0
- package/config/tsconfig.node.tsbuildinfo +1 -0
- package/config/tsconfig.tsbuildinfo +1 -0
- package/config/typedoc.json +16 -0
- package/config/vite.config.d.ts +2 -0
- package/config/vite.config.ts +72 -0
- package/dist/cli/commands/agents.d.ts +39 -0
- package/dist/cli/commands/agents.d.ts.map +1 -0
- package/dist/cli/commands/auth.d.ts +36 -0
- package/dist/cli/commands/auth.d.ts.map +1 -0
- package/dist/cli/commands/create-app.d.ts +23 -0
- package/dist/cli/commands/create-app.d.ts.map +1 -0
- package/dist/cli/commands/dev.d.ts +39 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/doctor.d.ts +42 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/generate.d.ts +36 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/init.d.ts +30 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/install-app.d.ts +30 -0
- package/dist/cli/commands/install-app.d.ts.map +1 -0
- package/dist/cli/commands/items.d.ts +45 -0
- package/dist/cli/commands/items.d.ts.map +1 -0
- package/dist/cli/commands/migrations.d.ts +41 -0
- package/dist/cli/commands/migrations.d.ts.map +1 -0
- package/dist/cli/commands/pipelines.d.ts +40 -0
- package/dist/cli/commands/pipelines.d.ts.map +1 -0
- package/dist/cli/commands/status.d.ts +23 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/system.d.ts +29 -0
- package/dist/cli/commands/system.d.ts.map +1 -0
- package/dist/cli/commands/test.d.ts +46 -0
- package/dist/cli/commands/test.d.ts.map +1 -0
- package/dist/cli/commands/uninstall-app.d.ts +23 -0
- package/dist/cli/commands/uninstall-app.d.ts.map +1 -0
- package/dist/cli/context.d.ts +88 -0
- package/dist/cli/context.d.ts.map +1 -0
- package/dist/cli/env-loader.d.ts +14 -0
- package/dist/cli/env-loader.d.ts.map +1 -0
- package/dist/cli/index.d.ts +41 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/functions/_shared/agent-runner.d.ts +156 -0
- package/dist/functions/_shared/agent-runner.d.ts.map +1 -0
- package/dist/functions/_shared/app-manifest.d.ts +68 -0
- package/dist/functions/_shared/app-manifest.d.ts.map +1 -0
- package/dist/functions/_shared/audit.d.ts +91 -0
- package/dist/functions/_shared/audit.d.ts.map +1 -0
- package/dist/functions/_shared/db.d.ts +125 -0
- package/dist/functions/_shared/db.d.ts.map +1 -0
- package/dist/functions/_shared/index.d.ts +298 -0
- package/dist/functions/_shared/index.d.ts.map +1 -0
- package/dist/functions/_shared/middleware.d.ts +315 -0
- package/dist/functions/_shared/middleware.d.ts.map +1 -0
- package/dist/functions/_shared/permissions.d.ts +626 -0
- package/dist/functions/_shared/permissions.d.ts.map +1 -0
- package/dist/functions/_shared/pipeline-runner.d.ts +124 -0
- package/dist/functions/_shared/pipeline-runner.d.ts.map +1 -0
- package/dist/functions/_shared/principal.d.ts +284 -0
- package/dist/functions/_shared/principal.d.ts.map +1 -0
- package/dist/functions/_shared/schema-utils.d.ts +181 -0
- package/dist/functions/_shared/schema-utils.d.ts.map +1 -0
- package/dist/functions/_shared/testing.d.ts +172 -0
- package/dist/functions/_shared/testing.d.ts.map +1 -0
- package/dist/functions/_shared/trigger-engine.d.ts +140 -0
- package/dist/functions/_shared/trigger-engine.d.ts.map +1 -0
- package/dist/functions/_shared/webhook-registration.d.ts +81 -0
- package/dist/functions/_shared/webhook-registration.d.ts.map +1 -0
- package/dist/functions/_shared/webhook-registry.d.ts +57 -0
- package/dist/functions/_shared/webhook-registry.d.ts.map +1 -0
- package/dist/functions/account-nodes.d.ts +48 -0
- package/dist/functions/account-nodes.d.ts.map +1 -0
- package/dist/functions/admin-data.d.ts +178 -0
- package/dist/functions/admin-data.d.ts.map +1 -0
- package/dist/functions/ai-agents.d.ts +125 -0
- package/dist/functions/ai-agents.d.ts.map +1 -0
- package/dist/functions/api-keys.d.ts +140 -0
- package/dist/functions/api-keys.d.ts.map +1 -0
- package/dist/functions/apps.d.ts +163 -0
- package/dist/functions/apps.d.ts.map +1 -0
- package/dist/functions/auth.d.ts +74 -0
- package/dist/functions/auth.d.ts.map +1 -0
- package/dist/functions/debug-auth.d.ts +33 -0
- package/dist/functions/debug-auth.d.ts.map +1 -0
- package/dist/functions/embeddings.d.ts +205 -0
- package/dist/functions/embeddings.d.ts.map +1 -0
- package/dist/functions/integration-routes.d.ts +45 -0
- package/dist/functions/integration-routes.d.ts.map +1 -0
- package/dist/functions/integrations.d.ts +124 -0
- package/dist/functions/integrations.d.ts.map +1 -0
- package/dist/functions/item-progress.d.ts +41 -0
- package/dist/functions/item-progress.d.ts.map +1 -0
- package/dist/functions/logs.d.ts +162 -0
- package/dist/functions/logs.d.ts.map +1 -0
- package/dist/functions/observability.d.ts +123 -0
- package/dist/functions/observability.d.ts.map +1 -0
- package/dist/functions/pipeline-executions.d.ts +190 -0
- package/dist/functions/pipeline-executions.d.ts.map +1 -0
- package/dist/functions/pipelines.d.ts +171 -0
- package/dist/functions/pipelines.d.ts.map +1 -0
- package/dist/functions/prompt-configs.d.ts +125 -0
- package/dist/functions/prompt-configs.d.ts.map +1 -0
- package/dist/functions/roles.d.ts +118 -0
- package/dist/functions/roles.d.ts.map +1 -0
- package/dist/functions/system-cron.d.ts +65 -0
- package/dist/functions/system-cron.d.ts.map +1 -0
- package/dist/functions/system.d.ts +29 -0
- package/dist/functions/system.d.ts.map +1 -0
- package/dist/functions/tests.d.ts +28 -0
- package/dist/functions/tests.d.ts.map +1 -0
- package/dist/functions/timers.d.ts +139 -0
- package/dist/functions/timers.d.ts.map +1 -0
- package/dist/functions/triggers.d.ts +203 -0
- package/dist/functions/triggers.d.ts.map +1 -0
- package/dist/functions/types.d.ts +151 -0
- package/dist/functions/types.d.ts.map +1 -0
- package/dist/src/types/types.d.ts +364 -0
- package/dist/src/types/types.d.ts.map +1 -0
- package/package.json +192 -0
- package/scripts/app-install-cli.ts +286 -0
- package/scripts/assemble-frontend.sh +79 -0
- package/scripts/assemble-functions.sh +62 -0
- package/scripts/assemble.sh +35 -0
- package/scripts/boundary-check.sh +106 -0
- package/scripts/build-manifest.sh +80 -0
- package/scripts/check-core-integrity.sh +82 -0
- package/scripts/ingest-chunks.cjs +202 -0
- package/scripts/kb-chunk-parser.cjs +312 -0
- package/scripts/kb-chunk-parser.ts +330 -0
- package/scripts/load-test-app-install.ts +484 -0
- package/scripts/netlify-dev-wrapper.sh +22 -0
- package/scripts/verify-integrity.sh +69 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react'
|
|
2
|
+
import { useParams, useSearchParams, useNavigate } from 'react-router-dom'
|
|
3
|
+
import { useEntityRecord } from '../../hooks/useEntityRecord'
|
|
4
|
+
import { DataDetailHeader } from '../runtime/DataDetailHeader'
|
|
5
|
+
import { SchemaDetailForm } from '../runtime/SchemaDetailForm'
|
|
6
|
+
|
|
7
|
+
interface GenericDetailPageProps {
|
|
8
|
+
typeSlug: string
|
|
9
|
+
viewSlug?: string
|
|
10
|
+
isCreating?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Schema-driven detail page for the Generic App Shell.
|
|
15
|
+
* Reuses the same runtime components as admin (DataDetailHeader, SchemaDetailForm)
|
|
16
|
+
* but scoped to a specific type from the app's nav_items.
|
|
17
|
+
*/
|
|
18
|
+
export function GenericDetailPage({ typeSlug, viewSlug, isCreating: forceCreate }: GenericDetailPageProps) {
|
|
19
|
+
const { id } = useParams<{ id: string }>()
|
|
20
|
+
const navigate = useNavigate()
|
|
21
|
+
const [searchParams, setSearchParams] = useSearchParams()
|
|
22
|
+
|
|
23
|
+
const isCreating = forceCreate || !id
|
|
24
|
+
const isEditing = searchParams.get('edit') === 'true' || isCreating
|
|
25
|
+
|
|
26
|
+
const config = {
|
|
27
|
+
entity: 'items',
|
|
28
|
+
typeSlug,
|
|
29
|
+
icon: 'database',
|
|
30
|
+
displayField: 'title',
|
|
31
|
+
api: {
|
|
32
|
+
endpoint: 'admin-data',
|
|
33
|
+
getAction: 'get',
|
|
34
|
+
createAction: 'create',
|
|
35
|
+
updateAction: 'update'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const {
|
|
40
|
+
record,
|
|
41
|
+
fieldPermissions,
|
|
42
|
+
loading,
|
|
43
|
+
error,
|
|
44
|
+
refetch,
|
|
45
|
+
save,
|
|
46
|
+
delete: deleteRecord,
|
|
47
|
+
saving,
|
|
48
|
+
deleting
|
|
49
|
+
} = useEntityRecord('items', id, config)
|
|
50
|
+
|
|
51
|
+
// Extract schema and view from the record itself
|
|
52
|
+
const schema = record?.design_schema || null
|
|
53
|
+
const resolvedDetailView = viewSlug
|
|
54
|
+
? schema?.views?.[viewSlug] || schema?.views?.default_detail
|
|
55
|
+
: schema?.views?.default_detail
|
|
56
|
+
const view = resolvedDetailView || null
|
|
57
|
+
|
|
58
|
+
// Derive display title
|
|
59
|
+
const displayField = schema?.display_field || config.displayField
|
|
60
|
+
const FALLBACK_FIELDS = ['full_name', 'display_name', 'name', 'title', 'slug', 'email']
|
|
61
|
+
const recordTitle = record?.[displayField]
|
|
62
|
+
?? FALLBACK_FIELDS.map(f => record?.[f]).find(v => v != null)
|
|
63
|
+
?? 'Untitled'
|
|
64
|
+
|
|
65
|
+
// Lifted form state
|
|
66
|
+
const [formData, setFormData] = useState<Record<string, any>>({})
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (record && view) {
|
|
70
|
+
const initialData: Record<string, any> = {}
|
|
71
|
+
view.sections?.forEach((section: any) => {
|
|
72
|
+
const fieldNames = Array.isArray(section.fields) ? section.fields : Object.keys(section.fields || {})
|
|
73
|
+
fieldNames.forEach((fieldName: string) => {
|
|
74
|
+
const fieldDef = schema?.fields?.[fieldName]
|
|
75
|
+
if (fieldDef?.system) {
|
|
76
|
+
initialData[fieldName] = record[fieldName]
|
|
77
|
+
} else {
|
|
78
|
+
initialData[fieldName] = record.data?.[fieldName]
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
setFormData(initialData)
|
|
83
|
+
} else if (isCreating) {
|
|
84
|
+
setFormData({})
|
|
85
|
+
}
|
|
86
|
+
}, [record, isCreating, view, schema])
|
|
87
|
+
|
|
88
|
+
const handleFieldChange = (key: string, value: any) => {
|
|
89
|
+
setFormData((prev) => ({ ...prev, [key]: value }))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const handleEdit = () => {
|
|
93
|
+
setSearchParams({ edit: 'true' })
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const handleCancel = () => {
|
|
97
|
+
if (isCreating) {
|
|
98
|
+
navigate(-1)
|
|
99
|
+
} else {
|
|
100
|
+
setSearchParams({})
|
|
101
|
+
if (record && view) {
|
|
102
|
+
const initialData: Record<string, any> = {}
|
|
103
|
+
view.sections?.forEach((section: any) => {
|
|
104
|
+
const fieldNames = Array.isArray(section.fields) ? section.fields : Object.keys(section.fields || {})
|
|
105
|
+
fieldNames.forEach((fieldName: string) => {
|
|
106
|
+
const fieldDef = schema?.fields?.[fieldName]
|
|
107
|
+
if (fieldDef?.system) {
|
|
108
|
+
initialData[fieldName] = record[fieldName]
|
|
109
|
+
} else {
|
|
110
|
+
initialData[fieldName] = record.data?.[fieldName]
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
setFormData(initialData)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const handleSave = async () => {
|
|
120
|
+
try {
|
|
121
|
+
await save(formData)
|
|
122
|
+
if (isCreating) {
|
|
123
|
+
navigate(-1)
|
|
124
|
+
} else {
|
|
125
|
+
setSearchParams({})
|
|
126
|
+
}
|
|
127
|
+
} catch (err) {
|
|
128
|
+
console.error('Save failed:', err)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const handleDelete = async () => {
|
|
133
|
+
if (window.confirm('Are you sure you want to delete this record?')) {
|
|
134
|
+
try {
|
|
135
|
+
await deleteRecord()
|
|
136
|
+
navigate(-1)
|
|
137
|
+
} catch (err) {
|
|
138
|
+
console.error('Delete failed:', err)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (loading) {
|
|
144
|
+
return (
|
|
145
|
+
<div className="p-8 text-center">
|
|
146
|
+
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto"></div>
|
|
147
|
+
<p className="mt-2 text-sm text-slate-500">Loading record...</p>
|
|
148
|
+
</div>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (error && !isCreating) {
|
|
153
|
+
return (
|
|
154
|
+
<div className="p-8 text-center">
|
|
155
|
+
<h2 className="text-lg font-medium text-red-600">Error</h2>
|
|
156
|
+
<p className="mt-2 text-sm text-slate-500">{error}</p>
|
|
157
|
+
</div>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!schema && !isCreating) {
|
|
162
|
+
return (
|
|
163
|
+
<div className="p-8 text-center">
|
|
164
|
+
<h2 className="text-lg font-medium text-slate-900">No schema available</h2>
|
|
165
|
+
<p className="mt-2 text-sm text-slate-500">This record does not have a design_schema.</p>
|
|
166
|
+
</div>
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<div className="space-y-6">
|
|
172
|
+
<DataDetailHeader
|
|
173
|
+
entity="items"
|
|
174
|
+
title={isCreating ? `New ${typeSlug}` : recordTitle}
|
|
175
|
+
icon="database"
|
|
176
|
+
isEditing={isEditing}
|
|
177
|
+
isCreating={isCreating}
|
|
178
|
+
saving={saving}
|
|
179
|
+
deleting={deleting}
|
|
180
|
+
onEdit={handleEdit}
|
|
181
|
+
onCancel={handleCancel}
|
|
182
|
+
onSave={handleSave}
|
|
183
|
+
onDelete={!isCreating ? handleDelete : undefined}
|
|
184
|
+
/>
|
|
185
|
+
|
|
186
|
+
{schema && view && (
|
|
187
|
+
<SchemaDetailForm
|
|
188
|
+
schema={schema}
|
|
189
|
+
view={view}
|
|
190
|
+
record={record}
|
|
191
|
+
isEditing={isEditing}
|
|
192
|
+
isCreating={isCreating}
|
|
193
|
+
permissions={fieldPermissions}
|
|
194
|
+
formData={formData}
|
|
195
|
+
onFieldChange={handleFieldChange}
|
|
196
|
+
/>
|
|
197
|
+
)}
|
|
198
|
+
</div>
|
|
199
|
+
)
|
|
200
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { useListSchema } from '../../hooks/useListSchema'
|
|
2
|
+
import { useEntityList } from '../../hooks/useEntityList'
|
|
3
|
+
import { DataHeader } from '../runtime/DataHeader'
|
|
4
|
+
import { DataStats } from '../runtime/DataStats'
|
|
5
|
+
import { DataFilters } from '../runtime/DataFilters'
|
|
6
|
+
import { DataTable } from '../runtime/DataTable'
|
|
7
|
+
|
|
8
|
+
interface GenericListPageProps {
|
|
9
|
+
typeSlug: string
|
|
10
|
+
viewSlug?: string
|
|
11
|
+
appPrefix: string
|
|
12
|
+
detailPath: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Schema-driven list page for the Generic App Shell.
|
|
17
|
+
* Resolves the type's design_schema and renders using the specified view
|
|
18
|
+
* (or default_list if not specified).
|
|
19
|
+
*/
|
|
20
|
+
export function GenericListPage({ typeSlug, viewSlug, appPrefix, detailPath }: GenericListPageProps) {
|
|
21
|
+
const resolvedViewSlug = viewSlug || 'default_list'
|
|
22
|
+
|
|
23
|
+
// Resolve schema and view — uses the same hook as admin runtime
|
|
24
|
+
const { schema, view, loading: schemaLoading, error: schemaError } = useListSchema({
|
|
25
|
+
entity: 'items',
|
|
26
|
+
viewSlug: resolvedViewSlug
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// Build config from resolved schema + view
|
|
30
|
+
const config = view && schema ? {
|
|
31
|
+
entity: 'items',
|
|
32
|
+
typeSlug,
|
|
33
|
+
icon: 'database',
|
|
34
|
+
api: {
|
|
35
|
+
endpoint: 'admin-data',
|
|
36
|
+
listAction: 'list'
|
|
37
|
+
},
|
|
38
|
+
list: {
|
|
39
|
+
defaultSort: (view as any).default_sort || { field: 'created_at', direction: 'desc' },
|
|
40
|
+
stats: (view as any).stats || [],
|
|
41
|
+
filters: (view as any).filters || [],
|
|
42
|
+
columns: Object.entries((view as any).fields || {}).map(([key, fieldConfig]: [string, any]) => ({
|
|
43
|
+
key,
|
|
44
|
+
label: schema.fields[key]?.label || key,
|
|
45
|
+
sortable: fieldConfig.sortable !== false,
|
|
46
|
+
display_type: fieldConfig.display_type
|
|
47
|
+
}))
|
|
48
|
+
}
|
|
49
|
+
} : null
|
|
50
|
+
|
|
51
|
+
const {
|
|
52
|
+
data,
|
|
53
|
+
loading,
|
|
54
|
+
error,
|
|
55
|
+
refetch,
|
|
56
|
+
filters,
|
|
57
|
+
setFilters,
|
|
58
|
+
sort,
|
|
59
|
+
setSort
|
|
60
|
+
} = useEntityList('items', config)
|
|
61
|
+
|
|
62
|
+
if (schemaLoading) {
|
|
63
|
+
return (
|
|
64
|
+
<div className="p-8 text-center">
|
|
65
|
+
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto"></div>
|
|
66
|
+
<p className="mt-2 text-sm text-slate-500">Loading schema...</p>
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (schemaError || !config) {
|
|
72
|
+
return (
|
|
73
|
+
<div className="p-8 text-center">
|
|
74
|
+
<h2 className="text-lg font-medium text-red-600">Error</h2>
|
|
75
|
+
<p className="mt-2 text-sm text-slate-500">{schemaError || 'Failed to load entity configuration'}</p>
|
|
76
|
+
</div>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div className="space-y-6">
|
|
82
|
+
<DataHeader
|
|
83
|
+
title={schema?.fields ? Object.keys(schema.fields).length > 0 ? (view as any)?.label || typeSlug : typeSlug : typeSlug}
|
|
84
|
+
icon={config.icon}
|
|
85
|
+
description={`Manage ${typeSlug}`}
|
|
86
|
+
newButtonHref={`${appPrefix}/${detailPath}/new`}
|
|
87
|
+
/>
|
|
88
|
+
|
|
89
|
+
<DataStats
|
|
90
|
+
stats={config.list.stats}
|
|
91
|
+
data={data}
|
|
92
|
+
loading={loading}
|
|
93
|
+
/>
|
|
94
|
+
|
|
95
|
+
<DataFilters
|
|
96
|
+
filters={config.list.filters}
|
|
97
|
+
values={filters}
|
|
98
|
+
onChange={setFilters}
|
|
99
|
+
onClear={() => setFilters({})}
|
|
100
|
+
/>
|
|
101
|
+
|
|
102
|
+
<DataTable
|
|
103
|
+
columns={config.list.columns}
|
|
104
|
+
data={data}
|
|
105
|
+
loading={loading}
|
|
106
|
+
error={error}
|
|
107
|
+
onRetry={refetch}
|
|
108
|
+
sort={sort}
|
|
109
|
+
onSort={setSort}
|
|
110
|
+
entity="items"
|
|
111
|
+
emptyMessage={`No ${typeSlug} found`}
|
|
112
|
+
emptyIcon={config.icon}
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { SearchForm } from "./search-form"
|
|
4
|
+
import {
|
|
5
|
+
Collapsible,
|
|
6
|
+
CollapsibleContent,
|
|
7
|
+
CollapsibleTrigger,
|
|
8
|
+
} from "./ui/collapsible"
|
|
9
|
+
import {
|
|
10
|
+
Sidebar,
|
|
11
|
+
SidebarContent,
|
|
12
|
+
SidebarGroup,
|
|
13
|
+
SidebarHeader,
|
|
14
|
+
SidebarMenu,
|
|
15
|
+
SidebarMenuButton,
|
|
16
|
+
SidebarMenuItem,
|
|
17
|
+
SidebarMenuSub,
|
|
18
|
+
SidebarMenuSubButton,
|
|
19
|
+
SidebarMenuSubItem,
|
|
20
|
+
SidebarRail,
|
|
21
|
+
} from "./ui/sidebar"
|
|
22
|
+
import { GalleryVerticalEndIcon, PlusIcon, MinusIcon } from "lucide-react"
|
|
23
|
+
|
|
24
|
+
// This is sample data.
|
|
25
|
+
const data = {
|
|
26
|
+
navMain: [
|
|
27
|
+
{
|
|
28
|
+
title: "Getting Started",
|
|
29
|
+
url: "#",
|
|
30
|
+
items: [
|
|
31
|
+
{
|
|
32
|
+
title: "Installation",
|
|
33
|
+
url: "#",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
title: "Project Structure",
|
|
37
|
+
url: "#",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
title: "Build Your Application",
|
|
43
|
+
url: "#",
|
|
44
|
+
items: [
|
|
45
|
+
{
|
|
46
|
+
title: "Routing",
|
|
47
|
+
url: "#",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
title: "Data Fetching",
|
|
51
|
+
url: "#",
|
|
52
|
+
isActive: true,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
title: "Rendering",
|
|
56
|
+
url: "#",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
title: "Caching",
|
|
60
|
+
url: "#",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
title: "Styling",
|
|
64
|
+
url: "#",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
title: "Optimizing",
|
|
68
|
+
url: "#",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
title: "Configuring",
|
|
72
|
+
url: "#",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
title: "Testing",
|
|
76
|
+
url: "#",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
title: "Authentication",
|
|
80
|
+
url: "#",
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
title: "Deploying",
|
|
84
|
+
url: "#",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
title: "Upgrading",
|
|
88
|
+
url: "#",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
title: "Examples",
|
|
92
|
+
url: "#",
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
title: "API Reference",
|
|
98
|
+
url: "#",
|
|
99
|
+
items: [
|
|
100
|
+
{
|
|
101
|
+
title: "Components",
|
|
102
|
+
url: "#",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
title: "File Conventions",
|
|
106
|
+
url: "#",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
title: "Functions",
|
|
110
|
+
url: "#",
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
title: "next.config.js Options",
|
|
114
|
+
url: "#",
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
title: "CLI",
|
|
118
|
+
url: "#",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
title: "Edge Runtime",
|
|
122
|
+
url: "#",
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
title: "Architecture",
|
|
128
|
+
url: "#",
|
|
129
|
+
items: [
|
|
130
|
+
{
|
|
131
|
+
title: "Accessibility",
|
|
132
|
+
url: "#",
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
title: "Fast Refresh",
|
|
136
|
+
url: "#",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
title: "Next.js Compiler",
|
|
140
|
+
url: "#",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
title: "Supported Browsers",
|
|
144
|
+
url: "#",
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
title: "Turbopack",
|
|
148
|
+
url: "#",
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
title: "Community",
|
|
154
|
+
url: "#",
|
|
155
|
+
items: [
|
|
156
|
+
{
|
|
157
|
+
title: "Contribution Guide",
|
|
158
|
+
url: "#",
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
|
166
|
+
return (
|
|
167
|
+
<Sidebar {...props}>
|
|
168
|
+
<SidebarHeader>
|
|
169
|
+
<SidebarMenu>
|
|
170
|
+
<SidebarMenuItem>
|
|
171
|
+
<SidebarMenuButton size="lg" asChild>
|
|
172
|
+
<a href="#">
|
|
173
|
+
<div className="flex aspect-square size-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground">
|
|
174
|
+
<GalleryVerticalEndIcon className="size-4" />
|
|
175
|
+
</div>
|
|
176
|
+
<div className="flex flex-col gap-0.5 leading-none">
|
|
177
|
+
<span className="font-medium">Documentation</span>
|
|
178
|
+
<span className="">v1.0.0</span>
|
|
179
|
+
</div>
|
|
180
|
+
</a>
|
|
181
|
+
</SidebarMenuButton>
|
|
182
|
+
</SidebarMenuItem>
|
|
183
|
+
</SidebarMenu>
|
|
184
|
+
<SearchForm />
|
|
185
|
+
</SidebarHeader>
|
|
186
|
+
<SidebarContent>
|
|
187
|
+
<SidebarGroup>
|
|
188
|
+
<SidebarMenu>
|
|
189
|
+
{data.navMain.map((item, index) => (
|
|
190
|
+
<Collapsible
|
|
191
|
+
key={item.title}
|
|
192
|
+
defaultOpen={index === 1}
|
|
193
|
+
className="group/collapsible"
|
|
194
|
+
>
|
|
195
|
+
<SidebarMenuItem>
|
|
196
|
+
<CollapsibleTrigger asChild>
|
|
197
|
+
<SidebarMenuButton>
|
|
198
|
+
{item.title}{" "}
|
|
199
|
+
<PlusIcon className="ml-auto group-data-[state=open]/collapsible:hidden" />
|
|
200
|
+
<MinusIcon className="ml-auto group-data-[state=closed]/collapsible:hidden" />
|
|
201
|
+
</SidebarMenuButton>
|
|
202
|
+
</CollapsibleTrigger>
|
|
203
|
+
{item.items?.length ? (
|
|
204
|
+
<CollapsibleContent>
|
|
205
|
+
<SidebarMenuSub>
|
|
206
|
+
{item.items.map((item) => (
|
|
207
|
+
<SidebarMenuSubItem key={item.title}>
|
|
208
|
+
<SidebarMenuSubButton
|
|
209
|
+
asChild
|
|
210
|
+
isActive={item.isActive}
|
|
211
|
+
>
|
|
212
|
+
<a href={item.url}>{item.title}</a>
|
|
213
|
+
</SidebarMenuSubButton>
|
|
214
|
+
</SidebarMenuSubItem>
|
|
215
|
+
))}
|
|
216
|
+
</SidebarMenuSub>
|
|
217
|
+
</CollapsibleContent>
|
|
218
|
+
) : null}
|
|
219
|
+
</SidebarMenuItem>
|
|
220
|
+
</Collapsible>
|
|
221
|
+
))}
|
|
222
|
+
</SidebarMenu>
|
|
223
|
+
</SidebarGroup>
|
|
224
|
+
</SidebarContent>
|
|
225
|
+
<SidebarRail />
|
|
226
|
+
</Sidebar>
|
|
227
|
+
)
|
|
228
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module src/components/auth/ProtectedRoute
|
|
3
|
+
* @audience installer
|
|
4
|
+
* @layer frontend-component
|
|
5
|
+
* @stability stable
|
|
6
|
+
*
|
|
7
|
+
* React Router route guard that enforces authentication and optional
|
|
8
|
+
* system-admin role checks. Wrap any `<Route>` element that requires
|
|
9
|
+
* a logged-in user.
|
|
10
|
+
*
|
|
11
|
+
* **Auth check:** If `AuthContext.user` is null (not yet logged in or
|
|
12
|
+
* session expired), redirects to `/login` using `<Navigate replace>`.
|
|
13
|
+
*
|
|
14
|
+
* **System-admin check:** When `requireSystemAdmin=true`, verifies that
|
|
15
|
+
* `user.roles` includes `'system_admin'`. On failure it renders an
|
|
16
|
+
* access-denied screen rather than redirecting, to avoid redirect loops.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <Route path="/admin" element={
|
|
21
|
+
* <ProtectedRoute requireSystemAdmin>
|
|
22
|
+
* <AdminLayout />
|
|
23
|
+
* </ProtectedRoute>
|
|
24
|
+
* } />
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @seeAlso src/contexts/AuthContext.tsx
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import React from 'react'
|
|
31
|
+
import { Navigate } from 'react-router-dom'
|
|
32
|
+
import { useAuth } from '../../contexts/AuthContext'
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Props for `ProtectedRoute`.
|
|
36
|
+
*
|
|
37
|
+
* @prop children - The protected route content
|
|
38
|
+
* @prop requireSystemAdmin - If true, also requires the `system_admin` role
|
|
39
|
+
*/
|
|
40
|
+
interface ProtectedRouteProps {
|
|
41
|
+
children: React.ReactNode
|
|
42
|
+
requireSystemAdmin?: boolean
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Route guard component.
|
|
47
|
+
*
|
|
48
|
+
* @param props - `ProtectedRouteProps`
|
|
49
|
+
* @returns `children` when authorised, a redirect to `/login` when
|
|
50
|
+
* unauthenticated, or an access-denied screen when role check fails
|
|
51
|
+
* @sideEffects none (navigation is declarative via `<Navigate>`)
|
|
52
|
+
*/
|
|
53
|
+
export function ProtectedRoute({ children, requireSystemAdmin = false }: ProtectedRouteProps) {
|
|
54
|
+
const { user } = useAuth()
|
|
55
|
+
|
|
56
|
+
if (!user) {
|
|
57
|
+
return <Navigate to="/login" replace />
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (requireSystemAdmin && !user.roles?.includes('system_admin')) {
|
|
61
|
+
// Show access denied message instead of redirect to avoid loops
|
|
62
|
+
return (
|
|
63
|
+
<div className="min-h-screen flex items-center justify-center bg-slate-50">
|
|
64
|
+
<div className="text-center p-8">
|
|
65
|
+
<div className="w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4">
|
|
66
|
+
<svg className="w-8 h-8 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
67
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z" />
|
|
68
|
+
</svg>
|
|
69
|
+
</div>
|
|
70
|
+
<h1 className="text-2xl font-bold text-slate-900 mb-2">Access Denied</h1>
|
|
71
|
+
<p className="text-slate-600 mb-6">You need system administrator privileges to access this page.</p>
|
|
72
|
+
<div className="bg-slate-100 rounded-lg p-4 text-left">
|
|
73
|
+
<p className="text-sm text-slate-600 mb-2"><strong>Your roles:</strong> {user.roles?.join(', ') || 'None'}</p>
|
|
74
|
+
<p className="text-sm text-slate-600"><strong>Required:</strong> system_admin</p>
|
|
75
|
+
</div>
|
|
76
|
+
<button
|
|
77
|
+
onClick={() => window.location.href = '/dashboard'}
|
|
78
|
+
className="mt-6 px-4 py-2 bg-navy text-white rounded-lg hover:bg-navy/90 transition-colors"
|
|
79
|
+
>
|
|
80
|
+
Go to Dashboard
|
|
81
|
+
</button>
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return <>{children}</>
|
|
88
|
+
}
|