spine-framework 0.3.145 → 0.4.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/.env.example +76 -0
- package/.framework/.spine-manifest.json +19 -0
- package/.framework/cli/commands/agents.ts +61 -33
- package/.framework/cli/commands/auth.ts +60 -28
- package/.framework/cli/commands/create-app.ts +212 -80
- package/.framework/cli/commands/dev.ts +184 -68
- package/.framework/cli/commands/doctor.ts +324 -152
- package/.framework/cli/commands/generate.ts +119 -68
- package/.framework/cli/commands/init.ts +141 -242
- package/.framework/cli/commands/install-app.ts +1336 -314
- package/.framework/cli/commands/items.ts +31 -29
- package/.framework/cli/commands/migrate.ts +299 -156
- package/.framework/cli/commands/migrations.ts +62 -30
- package/.framework/cli/commands/pipelines.ts +31 -29
- package/.framework/cli/commands/status.ts +105 -45
- package/.framework/cli/commands/system.ts +47 -42
- package/.framework/cli/commands/test.ts +161 -102
- package/.framework/cli/commands/upgrade.ts +260 -0
- package/.framework/cli/commands/validate-app.ts +517 -161
- package/.framework/cli/context.ts +117 -85
- package/.framework/cli/env-loader.ts +74 -43
- package/.framework/cli/index.ts +70 -46
- package/.framework/cli/lib/project-files.ts +404 -0
- package/.framework/docs/guides/testing-guide.md +1 -1
- package/.framework/docs/runtime-types.md +72 -72
- package/.framework/functions/_shared/access.ts +84 -0
- package/.framework/functions/_shared/agent-runner.ts +5051 -1026
- package/.framework/functions/_shared/app-manifest.ts +214 -94
- package/.framework/functions/_shared/ast.ts +214 -0
- package/.framework/functions/_shared/audit.ts +91 -55
- package/.framework/functions/_shared/cil.ts +368 -127
- package/.framework/functions/_shared/db.ts +337 -68
- package/.framework/functions/_shared/funnel.ts +228 -0
- package/.framework/functions/_shared/geo.ts +105 -0
- package/.framework/functions/_shared/hash-api-key.ts +94 -17
- package/.framework/functions/_shared/index.ts +22 -224
- package/.framework/functions/_shared/kb.ts +832 -58
- package/.framework/functions/_shared/llm.ts +118 -18
- package/.framework/functions/_shared/logging.ts +317 -19
- package/.framework/functions/_shared/middleware.ts +701 -131
- package/.framework/functions/_shared/notify.ts +70 -0
- package/.framework/functions/_shared/outcomes.ts +34 -19
- package/.framework/functions/_shared/permissions.ts +501 -315
- package/.framework/functions/_shared/pipeline-runner.ts +704 -155
- package/.framework/functions/_shared/principal.ts +436 -263
- package/.framework/functions/_shared/rate-limit.ts +233 -0
- package/.framework/functions/_shared/resolve-credentials.ts +86 -19
- package/.framework/functions/_shared/resolve-ids.ts +203 -139
- package/.framework/functions/_shared/retry-deliveries.ts +51 -16
- package/.framework/functions/_shared/schema-utils.ts +602 -521
- package/.framework/functions/_shared/security.ts +345 -0
- package/.framework/functions/_shared/testing.ts +197 -172
- package/.framework/functions/_shared/tracing.ts +351 -21
- package/.framework/functions/_shared/trigger-engine.ts +425 -136
- package/.framework/functions/_shared/webhook-registration.ts +71 -70
- package/.framework/functions/_shared/webhook-registry.ts +126 -83
- package/.framework/functions/account-nodes.ts +30 -30
- package/.framework/functions/adapters/generic-webhook-inbound.ts +49 -16
- package/.framework/functions/adapters/generic-webhook-outbound.ts +17 -17
- package/.framework/functions/adapters/openai-outbound.ts +15 -16
- package/.framework/functions/admin-data.ts +596 -173
- package/.framework/functions/admin-funnel.ts +64 -60
- package/.framework/functions/admin-install-funnel.ts +84 -66
- package/.framework/functions/admin-signals.ts +69 -51
- package/.framework/functions/ai-agents.ts +431 -106
- package/.framework/functions/ai-interactions.ts +186 -112
- package/.framework/functions/api-keys.ts +107 -107
- package/.framework/functions/apps.ts +154 -136
- package/.framework/functions/auth.ts +83 -65
- package/.framework/functions/cil-agent-ingest.ts +189 -232
- package/.framework/functions/cil-agent.ts +433 -177
- package/.framework/functions/cil-callmap.ts +642 -430
- package/.framework/functions/cil-config.ts +139 -135
- package/.framework/functions/cil-context.ts +214 -127
- package/.framework/functions/cil-doc.ts +587 -458
- package/.framework/functions/cil-embeddings.ts +453 -364
- package/.framework/functions/cil-graph.ts +427 -142
- package/.framework/functions/cil-ingest.ts +1418 -1154
- package/.framework/functions/cil-pipeline.ts +276 -21
- package/.framework/functions/cil-project.ts +659 -132
- package/.framework/functions/cil-validate.ts +198 -164
- package/.framework/functions/debug-auth.ts +57 -55
- package/.framework/functions/deliveries.ts +80 -21
- package/.framework/functions/embeddings.ts +1023 -318
- package/.framework/functions/eval-harness.ts +146 -108
- package/.framework/functions/integration-outbound.ts +205 -75
- package/.framework/functions/integration-routes.ts +128 -23
- package/.framework/functions/integrations.ts +125 -100
- package/.framework/functions/invites.ts +1095 -460
- package/.framework/functions/item-progress.ts +158 -102
- package/.framework/functions/kb.ts +34 -10
- package/.framework/functions/logs.ts +133 -133
- package/.framework/functions/observability.ts +152 -122
- package/.framework/functions/pipeline-executions.ts +147 -132
- package/.framework/functions/pipelines.ts +134 -119
- package/.framework/functions/prompt-configs.ts +96 -80
- package/.framework/functions/roles.ts +112 -82
- package/.framework/functions/security.ts +450 -0
- package/.framework/functions/system-cron.ts +117 -80
- package/.framework/functions/system.ts +158 -98
- package/.framework/functions/tests.ts +29 -29
- package/.framework/functions/timers.ts +94 -95
- package/.framework/functions/trigger-scheduler.ts +10 -0
- package/.framework/functions/triggers.ts +179 -149
- package/.framework/functions/types.ts +137 -125
- package/.framework/mcp/index.ts +133 -0
- package/.framework/mcp/load-env.ts +60 -0
- package/.framework/mcp/shared/app-manifest.ts +275 -0
- package/.framework/mcp/shared/db.ts +477 -0
- package/.framework/mcp/shared/kb.ts +118 -0
- package/.framework/mcp/tools/architect.ts +431 -0
- package/.framework/mcp/tools/cil/context.ts +345 -0
- package/.framework/mcp/tools/cil/graph.ts +242 -0
- package/.framework/mcp/tools/cil/ingest.ts +1217 -0
- package/.framework/mcp/tools/cil/pipeline-orchestrator.ts +693 -0
- package/.framework/mcp/tools/cil/pipeline.ts +767 -0
- package/.framework/mcp/tools/cil/project.ts +791 -0
- package/.framework/mcp/tools/cil/retrieval.ts +336 -0
- package/.framework/mcp/tools/cil/search-core.ts +454 -0
- package/.framework/mcp/tools/cil/search.ts +97 -0
- package/.framework/mcp/tools/cil/suggest.ts +186 -0
- package/.framework/mcp/tools/cil/validate.ts +1369 -0
- package/.framework/mcp/tools/kb/delete.ts +139 -0
- package/.framework/mcp/tools/kb/index.ts +52 -0
- package/.framework/mcp/tools/kb/ingest.ts +84 -0
- package/.framework/mcp/tools/kb/list-types.ts +102 -0
- package/.framework/mcp/tools/kb/publish.ts +100 -0
- package/.framework/mcp/tools/kb/reindex.ts +86 -0
- package/.framework/mcp/tools/kb/revoke.ts +85 -0
- package/.framework/mcp/tools/kb/search.ts +101 -0
- package/.framework/mcp/tools/kb/upsert.ts +125 -0
- package/.framework/mcp/tools/observability.ts +510 -0
- package/.framework/migrations/001_core_schema.sql +15 -0
- package/.framework/migrations/002_core_rls_and_functions.sql +15 -0
- package/.framework/migrations/003_core_system_data.sql +16 -1
- package/.framework/migrations/004_core_rpc_and_broker.sql +17 -1
- package/.framework/migrations/005_core_observability.sql +17 -1
- package/.framework/migrations/006_security_hardening_rls.sql +15 -0
- package/.framework/migrations/007_kb_article_list.sql +17 -1
- package/.framework/migrations/008_items_target.sql +15 -0
- package/.framework/migrations/009_roles_slug_unique.sql +15 -0
- package/.framework/migrations/010_auth_user_trigger.sql +15 -0
- package/.framework/migrations/011_spine_system_account.sql +16 -0
- package/.framework/migrations/012_service_role_grants.sql +16 -0
- package/.framework/migrations/013_get_account_apps_role_filter.sql +15 -0
- package/.framework/migrations/014_apps_required_roles.sql +16 -0
- package/.framework/migrations/015_types_kind_slug_unique.sql +15 -0
- package/.framework/migrations/016_cil_types.sql +281 -0
- package/.framework/migrations/017_cil_stable_ids.sql +37 -0
- package/.framework/migrations/018_runtime_tables.sql +129 -0
- package/.framework/migrations/019_agent_prompt_columns.sql +56 -0
- package/.framework/migrations/020_schema_reconciliation.sql +67 -0
- package/.framework/migrations/021_kb_embedding_lifecycle.sql +31 -0
- package/.framework/migrations/032_cil_status_migration.sql +73 -0
- package/.framework/migrations/033_cil_versioning.sql +73 -0
- package/.framework/migrations/034_match_embeddings_knn.sql +115 -0
- package/.framework/migrations/035_rate_limits.sql +55 -0
- package/.framework/migrations/036_demo_record_flags.sql +72 -0
- package/.framework/migrations/037_kb_types_canonical.sql +244 -0
- package/.framework/migrations/038_drop_demo_record_flags.sql +38 -0
- package/.framework/migrations/042_registration_hierarchy.sql +309 -0
- package/.framework/migrations/043_policy_actor_cleanup.sql +39 -0
- package/.framework/migrations/044_match_embeddings_filtered_knn.sql +151 -0
- package/.framework/migrations/045_security_critical_rls.sql +139 -0
- package/.framework/migrations/046_security_missing_rls.sql +79 -0
- package/.framework/migrations/047_people_updated_by.sql +27 -0
- package/.framework/migrations/048_watcher_last_seen_at.sql +24 -0
- package/.framework/migrations/049_security_blocklist.sql +148 -0
- package/.framework/migrations/050_notifications.sql +49 -0
- package/.framework/migrations/051_message_agent_fields.sql +74 -0
- package/.framework/migrations/052_registration_security.sql +421 -0
- package/.framework/migrations/053_builtin_action_seeds.sql +66 -0
- package/.framework/migrations/054_kb_ingest_lease.sql +157 -0
- package/.framework/migrations/055_type_id_drift_reconciliation.sql +33 -0
- package/.framework/migrations/056_slug_column_reconciliation.sql +38 -0
- package/.framework/migrations/057_pipelines_slug_identity.sql +14 -0
- package/.framework/migrations/058_account_data_field_declarations.sql +53 -0
- package/.framework/migrations/059_registration_placement_fixes.sql +269 -0
- package/.framework/migrations/060_account_person_record_permissions.sql +38 -0
- package/.framework/migrations/061_fk_dedup.sql +32 -0
- package/.framework/public/spine-logo.svg +10 -3
- package/.framework/scripts/app-install-cli.ts +190 -93
- package/.framework/scripts/assemble-frontend.sh +127 -44
- package/.framework/scripts/assemble-functions.sh +128 -30
- package/.framework/scripts/boundary-check.sh +6 -2
- package/.framework/scripts/build-manifest.sh +24 -68
- package/.framework/scripts/check-core-integrity.sh +15 -76
- package/.framework/scripts/checksum-manifest.mts +343 -0
- package/.framework/scripts/cil-migrate-markers.ts +403 -0
- package/.framework/scripts/fix-cil-markers.mjs +176 -0
- package/.framework/scripts/verify-integrity.sh +21 -57
- package/.framework/scripts/verify-manifest.mts +305 -0
- package/.framework/seeds/types/funnel_signal_use.json +74 -21
- package/.framework/seeds/types/spine_instance.json +73 -21
- package/.framework/src/App.tsx +118 -72
- package/.framework/src/apps/admin/index.tsx +855 -58
- package/.framework/src/components/AppWrapper.tsx +43 -45
- package/.framework/src/components/CustomAppLoader.tsx +160 -116
- package/.framework/src/components/admin/AdminListPage.tsx +46 -44
- package/.framework/src/components/admin/AdminSidebar.tsx +57 -47
- package/.framework/src/components/admin/AdminStatsCard.tsx +46 -44
- package/.framework/src/components/admin/PageInstructions.tsx +98 -2
- package/.framework/src/components/admin/SortableTableHeader.tsx +44 -45
- package/.framework/src/components/app-shell/GenericAppShell.tsx +64 -65
- package/.framework/src/components/app-shell/GenericDetailPage.tsx +44 -47
- package/.framework/src/components/app-shell/GenericListPage.tsx +45 -49
- package/.framework/src/components/app-sidebar.tsx +42 -45
- package/.framework/src/components/auth/ProtectedRoute.tsx +48 -41
- package/.framework/src/components/auth/TurnstileWidget.tsx +27 -0
- package/.framework/src/components/kb/KBArticleEditor.tsx +231 -22
- package/.framework/src/components/kb/KBArticleList.tsx +251 -10
- package/.framework/src/components/layout/AppShell.tsx +51 -45
- package/.framework/src/components/layout/Header.tsx +42 -43
- package/.framework/src/components/layout/Layout.tsx +46 -46
- package/.framework/src/components/layout/Sidebar.tsx +196 -96
- package/.framework/src/components/runtime/DataDetailHeader.tsx +55 -30
- package/.framework/src/components/runtime/DataDetailPage.tsx +31 -269
- package/.framework/src/components/runtime/DataFilters.tsx +49 -74
- package/.framework/src/components/runtime/DataHeader.tsx +53 -32
- package/.framework/src/components/runtime/DataListPage.tsx +51 -155
- package/.framework/src/components/runtime/DataStats.tsx +66 -44
- package/.framework/src/components/runtime/DataTable.tsx +49 -149
- package/.framework/src/components/runtime/SchemaDetailForm.tsx +45 -75
- package/.framework/src/components/runtime/index.ts +119 -16
- package/.framework/src/components/search-form.tsx +46 -29
- package/.framework/src/components/shared/AgentView.tsx +65 -48
- package/.framework/src/components/shared/FieldRenderer.tsx +144 -50
- package/.framework/src/components/shared/InviteManager.tsx +207 -97
- package/.framework/src/components/shared/MemberList.tsx +97 -0
- package/.framework/src/components/shared/SchemaFields.tsx +107 -86
- package/.framework/src/components/ui/DataTable.tsx +80 -68
- package/.framework/src/components/ui/Form.tsx +157 -146
- package/.framework/src/components/ui/ItemCard.tsx +74 -67
- package/.framework/src/components/ui/ItemListView.tsx +73 -68
- package/.framework/src/components/ui/LoadingSpinner.tsx +43 -48
- package/.framework/src/components/ui/Modal.tsx +78 -68
- package/.framework/src/components/ui/RichTextEditor.tsx +89 -69
- package/.framework/src/components/ui/accordion.tsx +85 -86
- package/.framework/src/components/ui/alert-dialog.tsx +197 -184
- package/.framework/src/components/ui/alert.tsx +105 -94
- package/.framework/src/components/ui/aspect-ratio.tsx +57 -43
- package/.framework/src/components/ui/avatar.tsx +122 -107
- package/.framework/src/components/ui/badge.tsx +60 -55
- package/.framework/src/components/ui/breadcrumb.tsx +127 -128
- package/.framework/src/components/ui/button-group.tsx +86 -72
- package/.framework/src/components/ui/button.tsx +71 -50
- package/.framework/src/components/ui/calendar.tsx +72 -57
- package/.framework/src/components/ui/card.tsx +136 -129
- package/.framework/src/components/ui/carousel.tsx +226 -107
- package/.framework/src/components/ui/chart.tsx +252 -147
- package/.framework/src/components/ui/checkbox.tsx +43 -44
- package/.framework/src/components/ui/collapsible.tsx +86 -71
- package/.framework/src/components/ui/combobox.tsx +282 -249
- package/.framework/src/components/ui/command.tsx +158 -146
- package/.framework/src/components/ui/context-menu.tsx +239 -240
- package/.framework/src/components/ui/dialog.tsx +174 -157
- package/.framework/src/components/ui/direction.tsx +72 -56
- package/.framework/src/components/ui/drawer.tsx +168 -169
- package/.framework/src/components/ui/dropdown-menu.tsx +254 -223
- package/.framework/src/components/ui/empty.tsx +131 -120
- package/.framework/src/components/ui/field.tsx +205 -173
- package/.framework/src/components/ui/hover-card.tsx +71 -72
- package/.framework/src/components/ui/input-group.tsx +148 -133
- package/.framework/src/components/ui/input-otp.tsx +99 -86
- package/.framework/src/components/ui/input.tsx +43 -41
- package/.framework/src/components/ui/item.tsx +207 -185
- package/.framework/src/components/ui/kbd.tsx +57 -56
- package/.framework/src/components/ui/label.tsx +45 -41
- package/.framework/src/components/ui/menubar.tsx +268 -236
- package/.framework/src/components/ui/native-select.tsx +85 -86
- package/.framework/src/components/ui/navigation-menu.tsx +166 -156
- package/.framework/src/components/ui/pagination.tsx +131 -141
- package/.framework/src/components/ui/popover.tsx +125 -128
- package/.framework/src/components/ui/progress.tsx +47 -44
- package/.framework/src/components/ui/radio-group.tsx +60 -55
- package/.framework/src/components/ui/resizable.tsx +85 -72
- package/.framework/src/components/ui/scroll-area.tsx +57 -58
- package/.framework/src/components/ui/select.tsx +182 -169
- package/.framework/src/components/ui/separator.tsx +42 -43
- package/.framework/src/components/ui/sheet.tsx +170 -159
- package/.framework/src/components/ui/sidebar.tsx +395 -398
- package/.framework/src/components/ui/skeleton.tsx +42 -43
- package/.framework/src/components/ui/slider.tsx +61 -44
- package/.framework/src/components/ui/sonner.tsx +44 -44
- package/.framework/src/components/ui/spinner.tsx +47 -42
- package/.framework/src/components/ui/switch.tsx +56 -42
- package/.framework/src/components/ui/table-primitives.tsx +272 -132
- package/.framework/src/components/ui/table.tsx +140 -142
- package/.framework/src/components/ui/tabs.tsx +110 -93
- package/.framework/src/components/ui/textarea.tsx +43 -44
- package/.framework/src/components/ui/toggle-group.tsx +87 -71
- package/.framework/src/components/ui/toggle.tsx +56 -56
- package/.framework/src/components/ui/tooltip.tsx +99 -85
- package/.framework/src/contexts/AppContext.tsx +166 -114
- package/.framework/src/contexts/AuthContext.tsx +232 -137
- package/.framework/src/hooks/use-mobile.ts +43 -44
- package/.framework/src/hooks/useApi.ts +185 -172
- package/.framework/src/hooks/useAppPath.ts +31 -29
- package/.framework/src/hooks/useApps.ts +77 -42
- package/.framework/src/hooks/useEntityList.ts +66 -29
- package/.framework/src/hooks/useEntityRecord.ts +76 -32
- package/.framework/src/hooks/useForm.ts +62 -30
- package/.framework/src/hooks/useListSchema.ts +60 -43
- package/.framework/src/hooks/useSchemaRecord.ts +115 -95
- package/.framework/src/lib/api.ts +258 -134
- package/.framework/src/lib/registration.ts +181 -0
- package/.framework/src/lib/supabase.ts +118 -81
- package/.framework/src/lib/utils.ts +266 -266
- package/.framework/src/main.tsx +43 -44
- package/.framework/src/pages/DashboardPage.tsx +44 -43
- package/.framework/src/pages/NoAppPage.tsx +50 -0
- package/.framework/src/pages/NotFoundPage.tsx +32 -29
- package/.framework/src/pages/SetupPage.tsx +34 -33
- package/.framework/src/pages/admin/AIAgentDetailPage.tsx +69 -58
- package/.framework/src/pages/admin/AIAgentsPage.tsx +43 -40
- package/.framework/src/pages/admin/APIKeyDetailPage.tsx +63 -55
- package/.framework/src/pages/admin/APIKeysPage.tsx +44 -42
- package/.framework/src/pages/admin/AlertsConfigPage.tsx +117 -94
- package/.framework/src/pages/admin/AppDetailPage.tsx +48 -42
- package/.framework/src/pages/admin/AppsPage.tsx +45 -42
- package/.framework/src/pages/admin/DeliveriesPage.tsx +49 -17
- package/.framework/src/pages/admin/DesignedPage.tsx +31 -30
- package/.framework/src/pages/admin/EmbeddingDetailPage.tsx +58 -0
- package/.framework/src/pages/admin/EmbeddingsPage.tsx +49 -0
- package/.framework/src/pages/admin/ExtendedShadcnTestPage.tsx +31 -29
- package/.framework/src/pages/admin/IncrementalShadcnTestPage.tsx +46 -29
- package/.framework/src/pages/admin/IntegratedDashboard.tsx +32 -29
- package/.framework/src/pages/admin/IntegrationDetailPage.tsx +68 -55
- package/.framework/src/pages/admin/IntegrationsPage.tsx +45 -42
- package/.framework/src/pages/admin/InvitesPage.tsx +60 -44
- package/.framework/src/pages/admin/LogsPage.tsx +87 -137
- package/.framework/src/pages/admin/MinimalShadcnTestPage.tsx +31 -29
- package/.framework/src/pages/admin/ObservabilityDashboard.tsx +150 -89
- package/.framework/src/pages/admin/PipelineDetailPage.tsx +77 -104
- package/.framework/src/pages/admin/PipelineExecutionsPage.tsx +44 -43
- package/.framework/src/pages/admin/PipelinesPage.tsx +59 -145
- package/.framework/src/pages/admin/PromptConfigDetailPage.tsx +53 -42
- package/.framework/src/pages/admin/PromptConfigsPage.tsx +47 -117
- package/.framework/src/pages/admin/ProperlyDesignedPage.tsx +31 -44
- package/.framework/src/pages/admin/RoleDetailPage.tsx +49 -92
- package/.framework/src/pages/admin/RolesPage.tsx +47 -164
- package/.framework/src/pages/admin/SecurityPage.tsx +310 -0
- package/.framework/src/pages/admin/SelectTestPage.tsx +30 -32
- package/.framework/src/pages/admin/ShadcnTestPage.tsx +37 -44
- package/.framework/src/pages/admin/SimpleDashboard.tsx +32 -44
- package/.framework/src/pages/admin/TestRunDetailPage.tsx +97 -44
- package/.framework/src/pages/admin/TestingDashboard.tsx +126 -71
- package/.framework/src/pages/admin/TimerDetailPage.tsx +67 -55
- package/.framework/src/pages/admin/TimersPage.tsx +44 -42
- package/.framework/src/pages/admin/TriggerDetailPage.tsx +47 -42
- package/.framework/src/pages/admin/TriggersPage.tsx +58 -57
- package/.framework/src/pages/admin/TypeDetailPage.tsx +91 -55
- package/.framework/src/pages/admin/TypesPage.tsx +45 -42
- package/.framework/src/pages/admin/cil/CILAgentPage.tsx +258 -128
- package/.framework/src/pages/admin/cil/CILChunkDetailPage.tsx +127 -123
- package/.framework/src/pages/admin/cil/CILDashboardPage.tsx +308 -235
- package/.framework/src/pages/admin/cil/CILFileListPage.tsx +159 -110
- package/.framework/src/pages/admin/cil/CILFileSelectPage.tsx +432 -0
- package/.framework/src/pages/admin/cil/CILGraphPage.tsx +200 -178
- package/.framework/src/pages/admin/cil/CILIngestionPage.tsx +286 -239
- package/.framework/src/pages/admin/cil/CILProjectsPage.tsx +211 -90
- package/.framework/src/pages/admin/cil/CILSearchPage.tsx +156 -143
- package/.framework/src/pages/admin/cil/CILSuggestionsPage.tsx +379 -0
- package/.framework/src/pages/admin/cil/CILVersionsPage.tsx +337 -0
- package/.framework/src/pages/admin/cil/FlexiblePipelinePage.tsx +219 -214
- package/.framework/src/pages/admin/kb/KBAdminPage.tsx +64 -0
- package/.framework/src/pages/auth/AuthConfirmPage.tsx +135 -65
- package/.framework/src/pages/auth/ForgotPasswordPage.tsx +39 -31
- package/.framework/src/pages/auth/LoginPage.tsx +38 -32
- package/.framework/src/pages/auth/PendingApprovalPage.tsx +31 -28
- package/.framework/src/pages/auth/RegisterPage.tsx +429 -155
- package/.framework/src/pages/spine-framework/APIPage.tsx +33 -30
- package/.framework/src/pages/spine-framework/CLIPage.tsx +32 -30
- package/.framework/src/types/auth.ts +101 -93
- package/.framework/src/types/types.ts +283 -262
- package/.framework/templates/project.json +87 -0
- package/.framework/templates/spine.config.neutral.json +7 -0
- package/.framework/tests/api/api-surface.test.ts +381 -0
- package/.framework/tests/fixtures/seed.ts +427 -0
- package/.framework/tests/fixtures/teardown.ts +228 -0
- package/.framework/tests/reporter.ts +351 -0
- package/.framework/tests/setup.ts +135 -0
- package/.framework/tests/ui/ui-sweep.ts +278 -0
- package/.framework/tests/unit/admin-data-logger.test.ts +310 -0
- package/.framework/tests/unit/agent-runner.test.ts +2389 -0
- package/.framework/tests/unit/ai-interactions.test.ts +81 -0
- package/.framework/tests/unit/app-manifest.test.ts +359 -0
- package/.framework/tests/unit/assembly-scripts.test.ts +172 -0
- package/.framework/tests/unit/cil-determinism.test.ts +85 -0
- package/.framework/tests/unit/core-isolation.test.ts +153 -0
- package/.framework/tests/unit/funnel-signals.test.ts +135 -0
- package/.framework/tests/unit/install-app.test.ts +1759 -0
- package/.framework/tests/unit/invites-security.test.ts +572 -0
- package/.framework/tests/unit/kb-ingest-lease.test.ts +287 -0
- package/.framework/tests/unit/kb-search.test.ts +119 -0
- package/.framework/tests/unit/migrate.test.ts +509 -0
- package/.framework/tests/unit/notify.test.ts +136 -0
- package/.framework/tests/unit/permissions.test.ts +269 -0
- package/.framework/tests/unit/pipeline-runner.test.ts +755 -0
- package/.framework/tests/unit/principal-cache.test.ts +138 -0
- package/.framework/tests/unit/retrieval-golden.test.ts +520 -0
- package/.framework/tests/unit/runtime-isolation.test.ts +642 -0
- package/.framework/tests/unit/schema-utils.test.ts +225 -0
- package/.framework/tests/unit/trigger-engine.test.ts +513 -0
- package/.framework/tests/unit/validate-app.test.ts +527 -0
- package/README.md +34 -3
- package/bin/spine-framework.cjs +1 -0
- package/config/tailwind.config.cjs +7 -0
- package/config/tsconfig.functions.json +42 -0
- package/config/tsconfig.json +37 -9
- package/config/vite.config.ts +31 -2
- package/netlify.toml +31 -3
- package/package.json +46 -29
- package/scripts/assemble-frontend.sh +127 -44
- package/scripts/assemble-functions.sh +127 -29
- package/scripts/boundary-check.sh +6 -2
- package/scripts/build-manifest.sh +24 -68
- package/scripts/checksum-manifest.mts +345 -0
- package/scripts/dev-clean.sh +86 -0
- package/scripts/dev-netlify.sh +49 -0
- package/scripts/netlify-dev-wrapper.sh +2 -0
- package/scripts/verify-install.ts +358 -0
- package/scripts/verify-integrity.sh +21 -57
- package/scripts/verify-manifest.mts +305 -0
- package/templates/project/gitignore +45 -0
- package/{config → templates/project}/package-lock.json +22335 -9366
- package/vitest.config.ts +46 -0
- package/.framework/public/spine.config.json +0 -91
- package/config/deno.lock +0 -108
- package/config/tsconfig.node.tsbuildinfo +0 -1
- package/config/tsconfig.tsbuildinfo +0 -1
- package/config/vite.config.d.ts +0 -2
- package/custom/.devin/AGENT.md +0 -357
- package/custom/.devin/skills/install-app/SKILL.md +0 -39
- package/custom/.devin/skills/spine-workbench-discovery/SKILL.md +0 -39
- package/custom/.devin/skills/spine-workbench-idea/SKILL.md +0 -36
- package/custom/.devin/skills/spine-workbench-implement/SKILL.md +0 -46
- package/custom/.devin/skills/spine-workbench-initiative/SKILL.md +0 -28
- package/custom/.devin/skills/spine-workbench-plan/SKILL.md +0 -38
- package/custom/.devin/workflows/app-install.yaml +0 -83
- package/custom/README.md +0 -79
- package/docs/README.md +0 -15
- package/scripts/app-install-cli.ts +0 -286
- package/scripts/check-core-integrity.sh +0 -82
- package/scripts/ingest-chunks.cjs +0 -202
- package/scripts/kb-chunk-parser.cjs +0 -312
- package/scripts/kb-chunk-parser.ts +0 -330
- package/scripts/kb-ingest-docs.ts +0 -203
- package/scripts/load-test-app-install.ts +0 -484
- package/scripts/test-login.js +0 -33
- package/spine.config.json +0 -91
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module middleware
|
|
3
|
+
* @audience internal
|
|
4
|
+
* @layer shared-core
|
|
5
|
+
* @stability stable
|
|
6
|
+
*
|
|
7
|
+
* This module provides middleware functions that handle authentication and authorization for API requests, ensuring that only authorized users can access certain resources. It integrates with tracing and auditing systems to monitor and log activities. INVARIANT: All requests must be validated against user roles before proceeding to the next step.
|
|
8
|
+
*
|
|
9
|
+
* @seeAlso principal (provides user identity management).
|
|
10
|
+
* @seeAlso db (handles database interactions for user roles).
|
|
11
|
+
* @seeAlso auditing (logs actions for compliance and monitoring).
|
|
12
|
+
* @seeAlso tracing (manages request tracing for performance analysis).
|
|
13
|
+
*
|
|
14
|
+
* @cil-generated
|
|
15
|
+
*/
|
|
16
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:module_header:module_header" type="module_header" identity="module_header" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
17
|
+
// CIL[DOC-MACRO purpose="This module provides middleware functions that handle authentication and authorization for API requests, ensuring that only authorized users can access certain resources."]
|
|
18
|
+
// CIL[DOC-RESPONSIBILITY responsibility="This module provides middleware functions that handle authentication and authorization for API requests, ensuring that only authorized users can access certain resources. It integrates with tracing and auditing systems to monitor and log activities. INVARIANT: All requests must be validated against user roles before proceeding to the next step."]
|
|
19
|
+
// CIL[DOC-CONTEXT module="middleware" layer="shared-core" related_files="principal (provides user identity management).,db (handles database interactions for user roles).,auditing (logs actions for compliance and monitoring).,tracing (manages request tracing for performance analysis)."]
|
|
20
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
21
|
+
// CIL[DOC-MICRO logic_summary="This module provides middleware functions that handle authentication and authorization for API requests, ensuring that only authorized users can access certain resources. It integrates with tracing and auditing systems to monitor and log activities. INVARIANT: All requests must be validated against user roles before proceeding to the next step." notable_decisions="none"]
|
|
22
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
23
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
24
|
+
// CIL[DOC-AUDIENCE audience="internal"]
|
|
1
25
|
import {
|
|
2
26
|
Principal,
|
|
3
27
|
resolvePrincipal,
|
|
@@ -6,6 +30,8 @@ import {
|
|
|
6
30
|
} from './principal'
|
|
7
31
|
import { adminDb } from './db'
|
|
8
32
|
import { emitAudit, emitSpan } from './audit'
|
|
33
|
+
import { isBlockedRequest, isBlockedIp, touchPersonGeo } from './security'
|
|
34
|
+
import { getClientGeo } from './geo'
|
|
9
35
|
import {
|
|
10
36
|
TraceContext,
|
|
11
37
|
Span,
|
|
@@ -19,23 +45,37 @@ import {
|
|
|
19
45
|
isSampled,
|
|
20
46
|
traceDb
|
|
21
47
|
} from './tracing'
|
|
22
|
-
|
|
23
|
-
// CIL[
|
|
24
|
-
// CIL[DOC-
|
|
25
|
-
// CIL[DOC-
|
|
26
|
-
// CIL[DOC-
|
|
27
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="types and handlers" errors="none" side_effects="request processing"]
|
|
28
|
-
// CIL[DOC-MICRO logic_summary="Defines CoreContext, RequestContext, HandlerFunction and HandlerResult types" notable_decisions="[]"]
|
|
29
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
30
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
31
|
-
// CIL[DOC-AUDIENCE audience="developer"]
|
|
32
|
-
// CIL[DOC-VECTOR type="context" content="Layer: infrastructure. Direct callers: 0. Direct calls: 0. Related files: custom/apps/portal/pages/ContentPage.tsx, custom/apps/cortex/pages/operations/OperationsDashboard.tsx, .framework/src/pages/admin/RolesPage.tsx, .framework/src/pages/admin/TypeDetailPage.tsx, \."]
|
|
33
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
34
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
35
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
48
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:module_header:module_header"]
|
|
49
|
+
// CIL[DOC-VECTOR type="context" content="purpose='This module provides middleware functions that handle authentication and authorization for API requests, ensuring that only authorized users can access certain resources.'; No verified external callers" status="ready"]
|
|
50
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
51
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
52
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
36
53
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
37
54
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
38
55
|
|
|
56
|
+
|
|
57
|
+
// CIL[DOC-MACRO purpose="CoreContext provides a structured context for handling requests within the application, encapsulating essential information such as the principal, account ID, and request details."]
|
|
58
|
+
// CIL[DOC-RESPONSIBILITY responsibility="CoreContext provides a structured context for handling requests within the application, encapsulating essential information such as the principal, account ID, and request details. It exists to facilitate consistent access to contextual data throughout the middleware layer."]
|
|
59
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
60
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
61
|
+
// CIL[DOC-MICRO logic_summary="CoreContext provides a structured context for handling requests within the application, encapsulating essential information such as the principal, account ID, and request details. It exists to facilitate consistent access to contextual data throughout the middleware layer." notable_decisions="none"]
|
|
62
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
63
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
64
|
+
/**
|
|
65
|
+
* CoreContext provides a structured context for handling requests within the application, encapsulating essential information such as the principal, account ID, and request details. It exists to facilitate consistent access to contextual data throughout the middleware layer.
|
|
66
|
+
*
|
|
67
|
+
* @sideEffects none
|
|
68
|
+
* @stability stable
|
|
69
|
+
* @cil-generated
|
|
70
|
+
*/
|
|
71
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:corecontext:interface" type="interface" identity="CoreContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
72
|
+
// CIL[DOC-MACRO purpose="CoreContext interface"]
|
|
73
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the CoreContext interface."]
|
|
74
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
75
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
76
|
+
// CIL[DOC-MICRO logic_summary="Implements the CoreContext interface." notable_decisions="[]"]
|
|
77
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
78
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
39
79
|
export interface CoreContext {
|
|
40
80
|
principal: Principal
|
|
41
81
|
accountId: string | null
|
|
@@ -45,27 +85,191 @@ export interface CoreContext {
|
|
|
45
85
|
logLevel?: string
|
|
46
86
|
trace?: TraceContext
|
|
47
87
|
}
|
|
88
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:corecontext:interface"]
|
|
89
|
+
// CIL[DOC-VECTOR type="context" content="purpose='CoreContext provides a structured context for handling requests within the application, encapsulating essential information such as the principal, account ID, and request details.'; No verified external callers" status="ready"]
|
|
90
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
91
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
92
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
93
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
94
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
48
95
|
|
|
96
|
+
// CIL[DOC-MACRO purpose="The RequestContext interface defines the structure for context information related to an incoming request, including application ID, query parameters, request path, and headers."]
|
|
97
|
+
// CIL[DOC-RESPONSIBILITY responsibility="The RequestContext interface defines the structure for context information related to an incoming request, including application ID, query parameters, request path, and headers. It is used to facilitate middleware operations by providing essential request-related data."]
|
|
98
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
99
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
100
|
+
// CIL[DOC-MICRO logic_summary="The RequestContext interface defines the structure for context information related to an incoming request, including application ID, query parameters, request path, and headers. It is used to facilitate middleware operations by providing essential request-related data." notable_decisions="none"]
|
|
101
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
102
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
103
|
+
/**
|
|
104
|
+
* The RequestContext interface defines the structure for context information related to an incoming request, including application ID, query parameters, request path, and headers. It is used to facilitate middleware operations by providing essential request-related data.
|
|
105
|
+
*
|
|
106
|
+
* @sideEffects none
|
|
107
|
+
* @stability stable
|
|
108
|
+
* @cil-generated
|
|
109
|
+
*/
|
|
110
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requestcontext:interface" type="interface" identity="RequestContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
111
|
+
// CIL[DOC-MACRO purpose="RequestContext interface"]
|
|
112
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the RequestContext interface."]
|
|
113
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
114
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
115
|
+
// CIL[DOC-MICRO logic_summary="Implements the RequestContext interface." notable_decisions="[]"]
|
|
116
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
117
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
49
118
|
export interface RequestContext extends CoreContext {
|
|
50
119
|
appId: string | null
|
|
51
120
|
query: Record<string, string>
|
|
52
121
|
requestPath: string
|
|
122
|
+
/** Lowercased request headers — used by geo/rate-limit helpers. */
|
|
123
|
+
headers?: Record<string, string>
|
|
53
124
|
}
|
|
125
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requestcontext:interface"]
|
|
126
|
+
// CIL[DOC-VECTOR type="context" content="purpose='The RequestContext interface defines the structure for context information related to an incoming request, including application ID, query parameters, request path, and headers.'; No verified external callers" status="ready"]
|
|
127
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
128
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
129
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
130
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
131
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
54
132
|
|
|
133
|
+
// CIL[DOC-MACRO purpose="HandlerFunction is a type that defines a function signature for handling requests in a middleware context."]
|
|
134
|
+
// CIL[DOC-RESPONSIBILITY responsibility="HandlerFunction is a type that defines a function signature for handling requests in a middleware context. It facilitates the processing of a request context and an optional body, returning a promise for asynchronous operations."]
|
|
135
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
136
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
137
|
+
// CIL[DOC-MICRO logic_summary="HandlerFunction is a type that defines a function signature for handling requests in a middleware context. It facilitates the processing of a request context and an optional body, returning a promise for asynchronous operations." notable_decisions="none"]
|
|
138
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
139
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
140
|
+
/**
|
|
141
|
+
* HandlerFunction is a type that defines a function signature for handling requests in a middleware context. It facilitates the processing of a request context and an optional body, returning a promise for asynchronous operations.
|
|
142
|
+
*
|
|
143
|
+
* @sideEffects none
|
|
144
|
+
* @stability stable
|
|
145
|
+
* @cil-generated
|
|
146
|
+
*/
|
|
147
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:handlerfunction:type" type="type" identity="HandlerFunction" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
148
|
+
// CIL[DOC-MACRO purpose="HandlerFunction type"]
|
|
149
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the HandlerFunction type."]
|
|
150
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
151
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
152
|
+
// CIL[DOC-MICRO logic_summary="Implements the HandlerFunction type." notable_decisions="[]"]
|
|
153
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
154
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
55
155
|
export type HandlerFunction = (ctx: RequestContext, body?: any) => Promise<any>
|
|
156
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:handlerfunction:type"]
|
|
157
|
+
// CIL[DOC-MACRO purpose="HandlerFunction type"]
|
|
158
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the HandlerFunction type."]
|
|
159
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
160
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
161
|
+
// CIL[DOC-MICRO logic_summary="Implements the HandlerFunction type." notable_decisions="[]"]
|
|
162
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
163
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
164
|
+
// CIL[DOC-VECTOR type="context" content="purpose='HandlerFunction is a type that defines a function signature for handling requests in a middleware context.'; No verified external callers" status="ready"]
|
|
165
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
166
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
167
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
168
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
169
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
56
170
|
|
|
171
|
+
// CIL[DOC-MACRO purpose="HandlerResult is an interface that encapsulates the result of a handler operation, allowing for the inclusion of data, error messages, and metadata."]
|
|
172
|
+
// CIL[DOC-RESPONSIBILITY responsibility="HandlerResult is an interface that encapsulates the result of a handler operation, allowing for the inclusion of data, error messages, and metadata. It exists to standardize the response structure across various handler implementations."]
|
|
173
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
174
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
175
|
+
// CIL[DOC-MICRO logic_summary="HandlerResult is an interface that encapsulates the result of a handler operation, allowing for the inclusion of data, error messages, and metadata. It exists to standardize the response structure across various handler implementations." notable_decisions="none"]
|
|
176
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
177
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
178
|
+
/**
|
|
179
|
+
* HandlerResult is an interface that encapsulates the result of a handler operation, allowing for the inclusion of data, error messages, and metadata. It exists to standardize the response structure across various handler implementations.
|
|
180
|
+
*
|
|
181
|
+
* @sideEffects none
|
|
182
|
+
* @stability stable
|
|
183
|
+
* @cil-generated
|
|
184
|
+
*/
|
|
185
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:handlerresult:interface" type="interface" identity="HandlerResult" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
186
|
+
// CIL[DOC-MACRO purpose="HandlerResult interface"]
|
|
187
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the HandlerResult interface."]
|
|
188
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
189
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
190
|
+
// CIL[DOC-MICRO logic_summary="Implements the HandlerResult interface." notable_decisions="[]"]
|
|
191
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
192
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
57
193
|
export interface HandlerResult {
|
|
58
194
|
data?: any
|
|
59
195
|
error?: string
|
|
60
196
|
meta?: any
|
|
61
197
|
}
|
|
198
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:handlerresult:interface"]
|
|
199
|
+
// CIL[DOC-VECTOR type="context" content="purpose='HandlerResult is an interface that encapsulates the result of a handler operation, allowing for the inclusion of data, error messages, and metadata.'; No verified external callers" status="ready"]
|
|
200
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
201
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
202
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
203
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
204
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
62
205
|
|
|
206
|
+
// CIL[DOC-MACRO purpose="Validates whether a given value is a properly formatted UUID string."]
|
|
207
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Validates whether a given value is a properly formatted UUID string. This function exists to ensure that UUIDs conform to the expected format before further processing."]
|
|
208
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
209
|
+
// CIL[DOC-CONTRACT inputs="- value: any (required) — the value to be validated as a UUID." outputs="value is string — returns true if the value is a valid UUID string, otherwise false." errors="none" side_effects="none"]
|
|
210
|
+
// CIL[DOC-MICRO logic_summary="Validates whether a given value is a properly formatted UUID string. This function exists to ensure that UUIDs conform to the expected format before further processing." notable_decisions="none"]
|
|
211
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
212
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
213
|
+
/**
|
|
214
|
+
* Validates whether a given value is a properly formatted UUID string. This function exists to ensure that UUIDs conform to the expected format before further processing.
|
|
215
|
+
*
|
|
216
|
+
* @inputSpec
|
|
217
|
+
* - value: any (required) — the value to be validated as a UUID.
|
|
218
|
+
* @outputSpec value is string — returns true if the value is a valid UUID string, otherwise false.
|
|
219
|
+
* @sideEffects none
|
|
220
|
+
* @stability stable
|
|
221
|
+
* @cil-generated
|
|
222
|
+
*/
|
|
223
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:isvaliduuid:function" type="function" identity="isValidUuid" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
224
|
+
// CIL[DOC-MACRO purpose="isValidUuid function"]
|
|
225
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the isValidUuid function."]
|
|
226
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
227
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
228
|
+
// CIL[DOC-MICRO logic_summary="Implements the isValidUuid function." notable_decisions="[]"]
|
|
229
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
230
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
63
231
|
function isValidUuid(value: any): value is string {
|
|
64
232
|
if (typeof value !== 'string') return false
|
|
65
233
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-9a-f][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
|
|
66
234
|
return uuidRegex.test(value)
|
|
67
235
|
}
|
|
236
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:isvaliduuid:function"]
|
|
237
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Validates whether a given value is a properly formatted UUID string.'; No verified external callers" status="ready"]
|
|
238
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
239
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
240
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
241
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
242
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
68
243
|
|
|
244
|
+
// CIL[DOC-MACRO purpose="Trace context builder for distributed tracing."]
|
|
245
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Builds a TraceContext object based on incoming event headers or a provided request ID. This function is essential for tracing requests in distributed systems."]
|
|
246
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
247
|
+
// CIL[DOC-CONTRACT inputs="- event: any (required) — the incoming event containing headers for tracing.\\n- requestId: string (required) — a unique identifier for the request." outputs="TraceContext — an object containing traceId, spanId, parentSpanId, traceFlags, traceState, and sampled status." errors="none" side_effects="none dependencies="parseTraceParent, parseTraceState, generateSpanId, formatTraceState, isSampled"]
|
|
248
|
+
// CIL[DOC-MICRO logic_summary="Parses trace headers in a specific order and generates a TraceContext based on the parsed values or defaults to the request ID." notable_decisions="none"]
|
|
249
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
250
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
251
|
+
/**
|
|
252
|
+
* Builds a TraceContext object based on incoming event headers or a provided request ID. This function is essential for tracing requests in distributed systems.
|
|
253
|
+
*
|
|
254
|
+
* @macro Trace context builder for distributed tracing.
|
|
255
|
+
* @micro Parses trace headers in a specific order and generates a TraceContext based on the parsed values or defaults to the request ID.
|
|
256
|
+
* @inputSpec
|
|
257
|
+
* - event: any (required) — the incoming event containing headers for tracing.
|
|
258
|
+
* - requestId: string (required) — a unique identifier for the request.
|
|
259
|
+
* @outputSpec TraceContext — an object containing traceId, spanId, parentSpanId, traceFlags, traceState, and sampled status.
|
|
260
|
+
* @sideEffects none
|
|
261
|
+
* @stability stable
|
|
262
|
+
* @calls parseTraceParent, parseTraceState, generateSpanId, formatTraceState, isSampled
|
|
263
|
+
* @cil-generated
|
|
264
|
+
*/
|
|
265
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:buildtracecontext:function" type="function" identity="buildTraceContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
266
|
+
// CIL[DOC-MACRO purpose="buildTraceContext function"]
|
|
267
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the buildTraceContext function."]
|
|
268
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
269
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
270
|
+
// CIL[DOC-MICRO logic_summary="Implements the buildTraceContext function." notable_decisions="[]"]
|
|
271
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
272
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
69
273
|
function buildTraceContext(event: any, requestId: string): TraceContext {
|
|
70
274
|
const traceparentHeader =
|
|
71
275
|
event.headers?.['traceparent'] ||
|
|
@@ -96,7 +300,41 @@ function buildTraceContext(event: any, requestId: string): TraceContext {
|
|
|
96
300
|
sampled: true
|
|
97
301
|
}
|
|
98
302
|
}
|
|
303
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:buildtracecontext:function"]
|
|
304
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Builds a TraceContext object based on incoming event headers or a provided request ID.'; No verified external callers" status="ready"]
|
|
305
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
306
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
307
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
308
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
309
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
99
310
|
|
|
311
|
+
// CIL[DOC-MACRO purpose="Generates a set of response headers for tracing purposes, including a request ID and trace information if provided."]
|
|
312
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Generates a set of response headers for tracing purposes, including a request ID and trace information if provided. This function is useful for tracking requests in distributed systems."]
|
|
313
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
314
|
+
// CIL[DOC-CONTRACT inputs="trace: TraceContext (optional) — context for tracing, including traceId, spanId, and traceFlags.\\nrequestId: string (optional) — unique identifier for the request." outputs="Record<string, string> — an object containing the generated headers." errors="none" side_effects="none dependencies="formatTraceParent"]
|
|
315
|
+
// CIL[DOC-MICRO logic_summary="Generates a set of response headers for tracing purposes, including a request ID and trace information if provided. This function is useful for tracking requests in distributed systems." notable_decisions="none"]
|
|
316
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
317
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
318
|
+
/**
|
|
319
|
+
* Generates a set of response headers for tracing purposes, including a request ID and trace information if provided. This function is useful for tracking requests in distributed systems.
|
|
320
|
+
*
|
|
321
|
+
* @inputSpec
|
|
322
|
+
* trace: TraceContext (optional) — context for tracing, including traceId, spanId, and traceFlags.
|
|
323
|
+
* requestId: string (optional) — unique identifier for the request.
|
|
324
|
+
* @outputSpec Record<string, string> — an object containing the generated headers.
|
|
325
|
+
* @sideEffects none
|
|
326
|
+
* @stability stable
|
|
327
|
+
* @calls formatTraceParent
|
|
328
|
+
* @cil-generated
|
|
329
|
+
*/
|
|
330
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:traceresponseheaders:function" type="function" identity="traceResponseHeaders" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
331
|
+
// CIL[DOC-MACRO purpose="traceResponseHeaders function"]
|
|
332
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the traceResponseHeaders function."]
|
|
333
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
334
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
335
|
+
// CIL[DOC-MICRO logic_summary="Implements the traceResponseHeaders function." notable_decisions="[]"]
|
|
336
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
337
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
100
338
|
function traceResponseHeaders(trace?: TraceContext, requestId?: string): Record<string, string> {
|
|
101
339
|
const headers: Record<string, string> = {}
|
|
102
340
|
if (requestId) headers['X-Request-ID'] = requestId
|
|
@@ -104,25 +342,79 @@ function traceResponseHeaders(trace?: TraceContext, requestId?: string): Record<
|
|
|
104
342
|
if (trace?.traceState) headers['tracestate'] = trace.traceState
|
|
105
343
|
return headers
|
|
106
344
|
}
|
|
345
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:traceresponseheaders:function"]
|
|
346
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Generates a set of response headers for tracing purposes, including a request ID and trace information if provided.'; No verified external callers" status="ready"]
|
|
347
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
348
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
349
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
350
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
351
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
107
352
|
|
|
353
|
+
// CIL[DOC-MACRO purpose="Merges two sets of headers, combining the base headers with any additional headers provided."]
|
|
354
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Merges two sets of headers, combining the base headers with any additional headers provided. This function exists to facilitate the construction of a complete set of headers for HTTP requests or responses."]
|
|
355
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
356
|
+
// CIL[DOC-CONTRACT inputs="base: Record<string, string> (required) — the base headers to merge.\\nextra: Record<string, string> (optional) — additional headers to merge with the base headers." outputs="Record<string, string> — a new object containing the merged headers." errors="none" side_effects="none"]
|
|
357
|
+
// CIL[DOC-MICRO logic_summary="Merges two sets of headers, combining the base headers with any additional headers provided. This function exists to facilitate the construction of a complete set of headers for HTTP requests or responses." notable_decisions="none"]
|
|
358
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
359
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
360
|
+
/**
|
|
361
|
+
* Merges two sets of headers, combining the base headers with any additional headers provided. This function exists to facilitate the construction of a complete set of headers for HTTP requests or responses.
|
|
362
|
+
*
|
|
363
|
+
* @inputSpec
|
|
364
|
+
* base: Record<string, string> (required) — the base headers to merge.
|
|
365
|
+
* extra: Record<string, string> (optional) — additional headers to merge with the base headers.
|
|
366
|
+
* @outputSpec Record<string, string> — a new object containing the merged headers.
|
|
367
|
+
* @sideEffects none
|
|
368
|
+
* @stability stable
|
|
369
|
+
* @cil-generated
|
|
370
|
+
*/
|
|
371
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:mergeheaders:function" type="function" identity="mergeHeaders" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
372
|
+
// CIL[DOC-MACRO purpose="mergeHeaders function"]
|
|
373
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the mergeHeaders function."]
|
|
374
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
375
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
376
|
+
// CIL[DOC-MICRO logic_summary="Implements the mergeHeaders function." notable_decisions="[]"]
|
|
377
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
378
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
108
379
|
function mergeHeaders(base: Record<string, string>, extra?: Record<string, string>): Record<string, string> {
|
|
109
380
|
return { ...base, ...extra }
|
|
110
381
|
}
|
|
111
|
-
// CIL[END
|
|
112
|
-
// CIL[
|
|
113
|
-
// CIL[DOC-
|
|
114
|
-
// CIL[DOC-
|
|
115
|
-
// CIL[DOC-
|
|
116
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="wrapped handler" errors="auth errors" side_effects="audit logging"]
|
|
117
|
-
// CIL[DOC-MICRO logic_summary="Wraps handler with authentication, context building, and audit logging" notable_decisions="[]"]
|
|
118
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
119
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
120
|
-
// CIL[DOC-VECTOR type="context" content="Layer: infrastructure. Direct callers: 0. Direct calls: 0. Related files: .framework/functions/_shared/principal.ts, .framework/src/pages/admin/TypeDetailPage.tsx, .framework/src/components/ui/dialog.tsx, \."]
|
|
121
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
122
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
123
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
382
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:mergeheaders:function"]
|
|
383
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Merges two sets of headers, combining the base headers with any additional headers provided.'; No verified external callers" status="ready"]
|
|
384
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
385
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
386
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
124
387
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
125
388
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
389
|
+
// CIL[DOC-MACRO purpose="Middleware function for handling requests with authentication and context management."]
|
|
390
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Creates a middleware handler that processes incoming events and manages authentication and context for the request. It ensures that valid principals are resolved and handles errors related to authentication and request parsing."]
|
|
391
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
392
|
+
// CIL[DOC-CONTRACT inputs="- handler: HandlerFunction (required) — the function to handle the event once validated." outputs="Promise<any> — returns the result of the handler or an error response." errors="none" side_effects="DB writes for logging and tracing, external calls for principal resolution. dependencies="isValidUuid, crypto.randomUUID, buildTraceContext, startSpan, resolvePrincipal, getPrincipalDb, traceDb, emitSpan, error"]
|
|
393
|
+
// CIL[DOC-MICRO logic_summary="Validates headers and query parameters to construct a request context, while managing spans for tracing." notable_decisions="returns an error response with a status code for authentication failures and JSON parsing errors."]
|
|
394
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
395
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
396
|
+
/**
|
|
397
|
+
* Creates a middleware handler that processes incoming events and manages authentication and context for the request. It ensures that valid principals are resolved and handles errors related to authentication and request parsing.
|
|
398
|
+
*
|
|
399
|
+
* @macro Middleware function for handling requests with authentication and context management.
|
|
400
|
+
* @micro Validates headers and query parameters to construct a request context, while managing spans for tracing.
|
|
401
|
+
* @inputSpec
|
|
402
|
+
* - handler: HandlerFunction (required) — the function to handle the event once validated.
|
|
403
|
+
* @outputSpec Promise<any> — returns the result of the handler or an error response.
|
|
404
|
+
* @sideEffects DB writes for logging and tracing, external calls for principal resolution.
|
|
405
|
+
* @stability stable
|
|
406
|
+
* @calls isValidUuid, crypto.randomUUID, buildTraceContext, startSpan, resolvePrincipal, getPrincipalDb, traceDb, emitSpan, error
|
|
407
|
+
* @errorHandling returns an error response with a status code for authentication failures and JSON parsing errors.
|
|
408
|
+
* @cil-generated
|
|
409
|
+
*/
|
|
410
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:createhandler:function" type="function" identity="createHandler" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
411
|
+
// CIL[DOC-MACRO purpose="createHandler function"]
|
|
412
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the createHandler function."]
|
|
413
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
414
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
415
|
+
// CIL[DOC-MICRO logic_summary="Implements the createHandler function." notable_decisions="[]"]
|
|
416
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
417
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
126
418
|
export function createHandler(handler: HandlerFunction) {
|
|
127
419
|
return async (event: any, context: any) => {
|
|
128
420
|
if (event && event.requestId && event.principal) {
|
|
@@ -140,6 +432,13 @@ export function createHandler(handler: HandlerFunction) {
|
|
|
140
432
|
const source = event.headers?.['x-source'] || event.headers?.['X-Source']
|
|
141
433
|
const logLevel = event.headers?.['x-log-level'] || event.headers?.['X-Log-Level']
|
|
142
434
|
|
|
435
|
+
const headers: Record<string, string> = {}
|
|
436
|
+
if (event.headers) {
|
|
437
|
+
for (const [k, v] of Object.entries(event.headers)) {
|
|
438
|
+
if (typeof v === 'string') headers[k.toLowerCase()] = v
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
143
442
|
const queryParams: Record<string, string> = {}
|
|
144
443
|
if (event.queryStringParameters) {
|
|
145
444
|
Object.assign(queryParams, event.queryStringParameters)
|
|
@@ -169,6 +468,7 @@ export function createHandler(handler: HandlerFunction) {
|
|
|
169
468
|
appId: appId || null,
|
|
170
469
|
query: queryParams,
|
|
171
470
|
requestPath: event.path || '/',
|
|
471
|
+
headers,
|
|
172
472
|
source,
|
|
173
473
|
logLevel,
|
|
174
474
|
trace: traceContext
|
|
@@ -176,6 +476,23 @@ export function createHandler(handler: HandlerFunction) {
|
|
|
176
476
|
|
|
177
477
|
ctx.db = traceDb(ctx, ctxDb, emitSpan)
|
|
178
478
|
|
|
479
|
+
// Hard-blocklist enforcement (person/account/email/ip). Fails open
|
|
480
|
+
// when the security_blocklist table is absent (pre-049 install).
|
|
481
|
+
const blocked = await isBlockedRequest(ctx)
|
|
482
|
+
if (blocked) {
|
|
483
|
+
endSpan(span, { status: 'error', attributes: { error: 'blocked' } })
|
|
484
|
+
void emitSpan(ctx, span, {
|
|
485
|
+
action: 'request.blocked',
|
|
486
|
+
target: { type: 'request', id: requestId, account_id: ctx.accountId },
|
|
487
|
+
metadata: { blocked_type: blocked.type }
|
|
488
|
+
}).catch(() => {})
|
|
489
|
+
return error('Access denied', 403, requestId, traceContext)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// Best-effort last-seen geo stamp — fire-and-forget, never on the
|
|
493
|
+
// request critical path.
|
|
494
|
+
void touchPersonGeo(principal.id, ctx)
|
|
495
|
+
|
|
179
496
|
let body = null
|
|
180
497
|
if (event.body) {
|
|
181
498
|
try {
|
|
@@ -201,7 +518,9 @@ export function createHandler(handler: HandlerFunction) {
|
|
|
201
518
|
const result = await handler(ctx, body)
|
|
202
519
|
endSpan(span, { status: 'ok' })
|
|
203
520
|
|
|
204
|
-
|
|
521
|
+
// Fire-and-forget like every other span — telemetry is best-effort and
|
|
522
|
+
// must not add a logs INSERT to the request's critical path.
|
|
523
|
+
void emitSpan(ctx, span, {
|
|
205
524
|
action: `request.${httpMethod.toLowerCase()}`,
|
|
206
525
|
target: { type: 'request', id: requestId, account_id: ctx.accountId },
|
|
207
526
|
metadata: {
|
|
@@ -211,7 +530,7 @@ export function createHandler(handler: HandlerFunction) {
|
|
|
211
530
|
principal_id: principal.id,
|
|
212
531
|
app_id: ctx.appId
|
|
213
532
|
}
|
|
214
|
-
})
|
|
533
|
+
}).catch((e: any) => console.warn(`[${requestId}] request span emit failed:`, e?.message || e))
|
|
215
534
|
|
|
216
535
|
return json({
|
|
217
536
|
data: result,
|
|
@@ -233,30 +552,51 @@ export function createHandler(handler: HandlerFunction) {
|
|
|
233
552
|
requestId,
|
|
234
553
|
trace: traceContext
|
|
235
554
|
}
|
|
236
|
-
|
|
555
|
+
void emitSpan(fallbackCtx, span, {
|
|
237
556
|
action: 'request.error',
|
|
238
557
|
target: { type: 'request', id: requestId, account_id: fallbackCtx.accountId },
|
|
239
558
|
metadata: { status, error: err.message || 'Internal server error' }
|
|
240
|
-
})
|
|
241
|
-
return
|
|
559
|
+
}).catch(() => {})
|
|
560
|
+
return structuredError(err, status, requestId, traceContext)
|
|
242
561
|
}
|
|
243
562
|
}
|
|
244
563
|
}
|
|
245
|
-
// CIL[END
|
|
246
|
-
// CIL[
|
|
247
|
-
// CIL[DOC-
|
|
248
|
-
// CIL[DOC-
|
|
249
|
-
// CIL[DOC-
|
|
250
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="wrapped handler" errors="request errors" side_effects="context building"]
|
|
251
|
-
// CIL[DOC-MICRO logic_summary="Wraps handler with context building but no authentication" notable_decisions="[]"]
|
|
252
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
253
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
254
|
-
// CIL[DOC-VECTOR type="context" content="Layer: infrastructure. Direct callers: 0. Direct calls: 0. Related files: .framework/src/pages/admin/TypeDetailPage.tsx, .framework/src/components/ui/dialog.tsx, .framework/migrations/025_retype_threads_messages.sql, \."]
|
|
255
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
256
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
257
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
564
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:createhandler:function"]
|
|
565
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Creates a middleware handler that processes incoming events and manages authentication and context for the request.'; No verified external callers" status="ready"]
|
|
566
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
567
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
568
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
258
569
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
259
570
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
571
|
+
// CIL[DOC-MACRO purpose="Middleware function that wraps a handler for public access."]
|
|
572
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Creates a public handler that processes incoming events and delegates to a specified handler function. It ensures that requests are properly traced and validated before invoking the handler."]
|
|
573
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
574
|
+
// CIL[DOC-CONTRACT inputs="handler: HandlerFunction (required) — the function to handle the event." outputs="Promise<any> — resolves with a JSON response containing data and metadata." errors="none" side_effects="none dependencies="isValidUuid, crypto.randomUUID, buildTraceContext, startSpan, resolvePrincipal, getPrincipalDb, traceDb, emitSpan, json"]
|
|
575
|
+
// CIL[DOC-MICRO logic_summary="Validates request headers and constructs a context object before calling the handler." notable_decisions="returns an error response for invalid JSON in the request body."]
|
|
576
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
577
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
578
|
+
/**
|
|
579
|
+
* Creates a public handler that processes incoming events and delegates to a specified handler function. It ensures that requests are properly traced and validated before invoking the handler.
|
|
580
|
+
*
|
|
581
|
+
* @macro Middleware function that wraps a handler for public access.
|
|
582
|
+
* @micro Validates request headers and constructs a context object before calling the handler.
|
|
583
|
+
* @inputSpec
|
|
584
|
+
* handler: HandlerFunction (required) — the function to handle the event.
|
|
585
|
+
* @outputSpec Promise<any> — resolves with a JSON response containing data and metadata.
|
|
586
|
+
* @sideEffects none
|
|
587
|
+
* @stability stable
|
|
588
|
+
* @calls isValidUuid, crypto.randomUUID, buildTraceContext, startSpan, resolvePrincipal, getPrincipalDb, traceDb, emitSpan, json
|
|
589
|
+
* @errorHandling returns an error response for invalid JSON in the request body.
|
|
590
|
+
* @cil-generated
|
|
591
|
+
*/
|
|
592
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:createpublichandler:function" type="function" identity="createPublicHandler" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
593
|
+
// CIL[DOC-MACRO purpose="createPublicHandler function"]
|
|
594
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the createPublicHandler function."]
|
|
595
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
596
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
597
|
+
// CIL[DOC-MICRO logic_summary="Implements the createPublicHandler function." notable_decisions="[]"]
|
|
598
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
599
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
260
600
|
export function createPublicHandler(handler: HandlerFunction) {
|
|
261
601
|
return async (event: any, context: any) => {
|
|
262
602
|
if (event && event.requestId && event.principal) {
|
|
@@ -274,6 +614,13 @@ export function createPublicHandler(handler: HandlerFunction) {
|
|
|
274
614
|
const source = event.headers?.['x-source'] || event.headers?.['X-Source']
|
|
275
615
|
const logLevel = event.headers?.['x-log-level'] || event.headers?.['X-Log-Level']
|
|
276
616
|
|
|
617
|
+
const headers: Record<string, string> = {}
|
|
618
|
+
if (event.headers) {
|
|
619
|
+
for (const [k, v] of Object.entries(event.headers)) {
|
|
620
|
+
if (typeof v === 'string') headers[k.toLowerCase()] = v
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
277
624
|
const queryParams: Record<string, string> = {}
|
|
278
625
|
if (event.queryStringParameters) {
|
|
279
626
|
Object.assign(queryParams, event.queryStringParameters)
|
|
@@ -294,6 +641,7 @@ export function createPublicHandler(handler: HandlerFunction) {
|
|
|
294
641
|
appId: appId || null,
|
|
295
642
|
query: queryParams,
|
|
296
643
|
requestPath: event.path || '/',
|
|
644
|
+
headers,
|
|
297
645
|
source,
|
|
298
646
|
logLevel,
|
|
299
647
|
trace: traceContext
|
|
@@ -301,6 +649,14 @@ export function createPublicHandler(handler: HandlerFunction) {
|
|
|
301
649
|
|
|
302
650
|
ctx.db = traceDb(ctx, ctxDb, emitSpan)
|
|
303
651
|
|
|
652
|
+
// IP hard-block on public endpoints (registration, invite preview).
|
|
653
|
+
// Fails open when the blocklist table is absent.
|
|
654
|
+
const blockedIp = await isBlockedIp(getClientGeo(ctx).ip)
|
|
655
|
+
if (blockedIp) {
|
|
656
|
+
endSpan(span, { status: 'error', attributes: { error: 'blocked' } })
|
|
657
|
+
return error('Access denied', 403, requestId, traceContext)
|
|
658
|
+
}
|
|
659
|
+
|
|
304
660
|
let body = null
|
|
305
661
|
if (event.body) {
|
|
306
662
|
try {
|
|
@@ -355,34 +711,61 @@ export function createPublicHandler(handler: HandlerFunction) {
|
|
|
355
711
|
requestId,
|
|
356
712
|
trace: traceContext
|
|
357
713
|
}
|
|
358
|
-
|
|
714
|
+
void emitSpan(fallbackCtx, span, {
|
|
359
715
|
action: 'request.error',
|
|
360
716
|
target: { type: 'request', id: requestId, account_id: fallbackCtx.accountId },
|
|
361
717
|
metadata: { status, error: err.message || 'Internal server error' }
|
|
362
|
-
})
|
|
363
|
-
return
|
|
718
|
+
}).catch(() => {})
|
|
719
|
+
return structuredError(err, status, requestId, traceContext)
|
|
364
720
|
}
|
|
365
721
|
}
|
|
366
722
|
}
|
|
367
|
-
// CIL[END
|
|
368
|
-
// CIL[
|
|
369
|
-
// CIL[DOC-
|
|
370
|
-
// CIL[DOC-
|
|
371
|
-
// CIL[DOC-
|
|
372
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="HTTP response" errors="none" side_effects="none"]
|
|
373
|
-
// CIL[DOC-MICRO logic_summary="Creates HTTP response with JSON body and CORS headers" notable_decisions="[]"]
|
|
374
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
375
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
376
|
-
// CIL[DOC-VECTOR type="context" content="Layer: infrastructure. Direct callers: 0. Direct calls: 0. Related files: .framework/src/pages/admin/TypeDetailPage.tsx, .framework/src/components/ui/dialog.tsx, \."]
|
|
377
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
378
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
379
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
723
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:createpublichandler:function"]
|
|
724
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Creates a public handler that processes incoming events and delegates to a specified handler function.'; No verified external callers" status="ready"]
|
|
725
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
726
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
727
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
380
728
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
381
729
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
730
|
+
// CIL[DOC-MACRO purpose="Response formatter for JSON API responses."]
|
|
731
|
+
// CIL[DOC-RESPONSIBILITY responsibility="The json function formats a given data object into a JSON response with specified HTTP status and optional tracing information. It is designed to standardize the response structure for API endpoints."]
|
|
732
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
733
|
+
// CIL[DOC-CONTRACT inputs="- data: any (required) — the data to be serialized into JSON.\\n- status: number (optional) — the HTTP status code to return, defaults to 200.\\n- requestId: string (optional|nullable) — an optional request identifier for tracing.\\n- trace: TraceContext (optional|nullable) — optional tracing context containing trace information." outputs="{ statusCode: number, headers: Record<string, string>, body: string }" errors="none" side_effects="none dependencies="formatTraceParent"]
|
|
734
|
+
// CIL[DOC-MICRO logic_summary="Constructs a response object with headers for CORS and tracing based on input parameters." notable_decisions="none"]
|
|
735
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
736
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
737
|
+
/**
|
|
738
|
+
* The json function formats a given data object into a JSON response with specified HTTP status and optional tracing information. It is designed to standardize the response structure for API endpoints.
|
|
739
|
+
*
|
|
740
|
+
* @macro Response formatter for JSON API responses.
|
|
741
|
+
* @micro Constructs a response object with headers for CORS and tracing based on input parameters.
|
|
742
|
+
* @inputSpec
|
|
743
|
+
* - data: any (required) — the data to be serialized into JSON.
|
|
744
|
+
* - status: number (optional) — the HTTP status code to return, defaults to 200.
|
|
745
|
+
* - requestId: string (optional|nullable) — an optional request identifier for tracing.
|
|
746
|
+
* - trace: TraceContext (optional|nullable) — optional tracing context containing trace information.
|
|
747
|
+
* @outputSpec { statusCode: number, headers: Record<string, string>, body: string }
|
|
748
|
+
* @sideEffects none
|
|
749
|
+
* @stability stable
|
|
750
|
+
* @calls formatTraceParent
|
|
751
|
+
* @cil-generated
|
|
752
|
+
*/
|
|
753
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:json:function" type="function" identity="json" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
754
|
+
// CIL[DOC-MACRO purpose="json function"]
|
|
755
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the json function."]
|
|
756
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
757
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
758
|
+
// CIL[DOC-MICRO logic_summary="Implements the json function." notable_decisions="[]"]
|
|
759
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
760
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
382
761
|
export function json(data: any, status: number = 200, requestId?: string, trace?: TraceContext) {
|
|
383
762
|
const headers: Record<string, string> = {
|
|
384
763
|
'Content-Type': 'application/json',
|
|
385
|
-
|
|
764
|
+
// Same-origin SPA calls never read this header; it only governs
|
|
765
|
+
// cross-origin API access. SITE_URL (custom domain) → URL (Netlify
|
|
766
|
+
// auto-set site URL) → '*' fallback keeps local dev working when
|
|
767
|
+
// neither is configured.
|
|
768
|
+
'Access-Control-Allow-Origin': process.env.SITE_URL || process.env.URL || '*',
|
|
386
769
|
'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Account-Id, X-App-Id, X-Request-ID, X-Source, X-Log-Level, traceparent, tracestate',
|
|
387
770
|
'Access-Control-Allow-Methods': 'GET, POST, PATCH, DELETE, OPTIONS'
|
|
388
771
|
}
|
|
@@ -399,42 +782,129 @@ export function json(data: any, status: number = 200, requestId?: string, trace?
|
|
|
399
782
|
body: JSON.stringify(data)
|
|
400
783
|
}
|
|
401
784
|
}
|
|
402
|
-
// CIL[END
|
|
403
|
-
// CIL[
|
|
404
|
-
// CIL[DOC-
|
|
405
|
-
// CIL[DOC-
|
|
406
|
-
// CIL[DOC-
|
|
407
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="HTTP error response" errors="none" side_effects="none"]
|
|
408
|
-
// CIL[DOC-MICRO logic_summary="Creates JSON error response with status code" notable_decisions="[]"]
|
|
409
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
410
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
411
|
-
// CIL[DOC-VECTOR type="context" content="Layer: infrastructure. Direct callers: 0. Direct calls: 0. Related files: .framework/src/pages/admin/TypeDetailPage.tsx, .framework/src/components/ui/dialog.tsx."]
|
|
412
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
413
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
414
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
785
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:json:function"]
|
|
786
|
+
// CIL[DOC-VECTOR type="context" content="purpose='The json function formats a given data object into a JSON response with specified HTTP status and optional tracing information.'; No verified external callers" status="ready"]
|
|
787
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
788
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
789
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
415
790
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
416
791
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
792
|
+
// CIL[DOC-MACRO purpose="The error function generates a standardized JSON response for error handling in the application."]
|
|
793
|
+
// CIL[DOC-RESPONSIBILITY responsibility="The error function generates a standardized JSON response for error handling in the application. It provides a consistent structure for error messages along with an optional HTTP status code and request tracing information."]
|
|
794
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
795
|
+
// CIL[DOC-CONTRACT inputs="message: string (required) — the error message to be returned.\\nstatus: number (optional) — the HTTP status code, defaulting to 400.\\nrequestId: string (optional|nullable) — an optional identifier for the request.\\ntrace: TraceContext (optional|nullable) — optional tracing context for debugging." outputs="Promise<any> — returns a JSON response containing the error message." errors="none" side_effects="none dependencies="json"]
|
|
796
|
+
// CIL[DOC-MICRO logic_summary="The error function generates a standardized JSON response for error handling in the application. It provides a consistent structure for error messages along with an optional HTTP status code and request tracing information." notable_decisions="none"]
|
|
797
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
798
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
799
|
+
/**
|
|
800
|
+
* The error function generates a standardized JSON response for error handling in the application. It provides a consistent structure for error messages along with an optional HTTP status code and request tracing information.
|
|
801
|
+
*
|
|
802
|
+
* @inputSpec
|
|
803
|
+
* message: string (required) — the error message to be returned.
|
|
804
|
+
* status: number (optional) — the HTTP status code, defaulting to 400.
|
|
805
|
+
* requestId: string (optional|nullable) — an optional identifier for the request.
|
|
806
|
+
* trace: TraceContext (optional|nullable) — optional tracing context for debugging.
|
|
807
|
+
* @outputSpec Promise<any> — returns a JSON response containing the error message.
|
|
808
|
+
* @sideEffects none
|
|
809
|
+
* @stability stable
|
|
810
|
+
* @calls json
|
|
811
|
+
* @cil-generated
|
|
812
|
+
*/
|
|
813
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:error:function" type="function" identity="error" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
814
|
+
// CIL[DOC-MACRO purpose="error function"]
|
|
815
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the error function."]
|
|
816
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
817
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
818
|
+
// CIL[DOC-MICRO logic_summary="Implements the error function." notable_decisions="[]"]
|
|
819
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
820
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
417
821
|
export function error(message: string, status: number = 400, requestId?: string, trace?: TraceContext) {
|
|
418
822
|
return json({
|
|
419
823
|
data: null,
|
|
420
824
|
error: message
|
|
421
825
|
}, status, requestId, trace)
|
|
422
826
|
}
|
|
423
|
-
// CIL[END
|
|
424
|
-
// CIL[
|
|
425
|
-
// CIL[DOC-
|
|
426
|
-
// CIL[DOC-
|
|
427
|
-
// CIL[DOC-
|
|
428
|
-
// CIL[DOC-
|
|
429
|
-
// CIL[DOC-
|
|
430
|
-
|
|
431
|
-
//
|
|
432
|
-
//
|
|
433
|
-
// CIL[DOC-
|
|
434
|
-
// CIL[DOC-
|
|
435
|
-
// CIL[DOC-
|
|
827
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:error:function"]
|
|
828
|
+
// CIL[DOC-VECTOR type="context" content="purpose='The error function generates a standardized JSON response for error handling in the application.'; No verified external callers" status="ready"]
|
|
829
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
830
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
831
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
832
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
833
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
834
|
+
|
|
835
|
+
// Error responses carry whitelisted structured fields (e.g. rate-limit
|
|
836
|
+
// action/limit/retry_after) so clients can render recovery UX.
|
|
837
|
+
// CIL[DOC-MACRO purpose="The structuredError function formats error responses for API calls, ensuring consistent structure and information."]
|
|
838
|
+
// CIL[DOC-RESPONSIBILITY responsibility="The structuredError function formats error responses for API calls, ensuring consistent structure and information. It provides a way to include additional error details when available."]
|
|
839
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
840
|
+
// CIL[DOC-CONTRACT inputs="err: any (required) — the error object containing details about the error.\\nstatus: number (required) — the HTTP status code to return.\\nrequestId: string (optional) — an optional identifier for the request.\\ntrace: TraceContext (optional) — optional tracing context for debugging." outputs="Promise<any> — a JSON response containing the error details and status code." errors="none" side_effects="none dependencies="json"]
|
|
841
|
+
// CIL[DOC-MICRO logic_summary="The structuredError function formats error responses for API calls, ensuring consistent structure and information. It provides a way to include additional error details when available." notable_decisions="none"]
|
|
842
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
843
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
844
|
+
/**
|
|
845
|
+
* The structuredError function formats error responses for API calls, ensuring consistent structure and information. It provides a way to include additional error details when available.
|
|
846
|
+
*
|
|
847
|
+
* @inputSpec
|
|
848
|
+
* err: any (required) — the error object containing details about the error.
|
|
849
|
+
* status: number (required) — the HTTP status code to return.
|
|
850
|
+
* requestId: string (optional) — an optional identifier for the request.
|
|
851
|
+
* trace: TraceContext (optional) — optional tracing context for debugging.
|
|
852
|
+
* @outputSpec Promise<any> — a JSON response containing the error details and status code.
|
|
853
|
+
* @sideEffects none
|
|
854
|
+
* @stability stable
|
|
855
|
+
* @calls json
|
|
856
|
+
* @cil-generated
|
|
857
|
+
*/
|
|
858
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:structurederror:function" type="function" identity="structuredError" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
859
|
+
// CIL[DOC-MACRO purpose="structuredError function"]
|
|
860
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the structuredError function."]
|
|
861
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
862
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
863
|
+
// CIL[DOC-MICRO logic_summary="Implements the structuredError function." notable_decisions="[]"]
|
|
864
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
865
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
866
|
+
function structuredError(err: any, status: number, requestId?: string, trace?: TraceContext) {
|
|
867
|
+
const body: Record<string, any> = { data: null, error: err?.message || 'Internal server error' }
|
|
868
|
+
for (const key of ['action', 'limit', 'retry_after']) {
|
|
869
|
+
if (err?.[key] !== undefined) body[key] = err[key]
|
|
870
|
+
}
|
|
871
|
+
if (err?.retryAfter !== undefined) body.retry_after = err.retryAfter
|
|
872
|
+
return json(body, status, requestId, trace)
|
|
873
|
+
}
|
|
874
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:structurederror:function"]
|
|
875
|
+
// CIL[DOC-VECTOR type="context" content="purpose='The structuredError function formats error responses for API calls, ensuring consistent structure and information.'; No verified external callers" status="ready"]
|
|
876
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
877
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
878
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
436
879
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
437
880
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
881
|
+
// CIL[DOC-MACRO purpose="Parses the body of an event to extract JSON data."]
|
|
882
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Parses the body of an event to extract JSON data. This function exists to handle incoming event data that may be in JSON format."]
|
|
883
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
884
|
+
// CIL[DOC-CONTRACT inputs="event: any (required) — the event object containing the body to be parsed." outputs="any — the parsed JSON object or null if no body is present." errors="Error — Invalid JSON in request body" side_effects="none dependencies="JSON.parse"]
|
|
885
|
+
// CIL[DOC-MICRO logic_summary="Parses the body of an event to extract JSON data. This function exists to handle incoming event data that may be in JSON format." notable_decisions="none"]
|
|
886
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
887
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
888
|
+
/**
|
|
889
|
+
* Parses the body of an event to extract JSON data. This function exists to handle incoming event data that may be in JSON format.
|
|
890
|
+
*
|
|
891
|
+
* @inputSpec
|
|
892
|
+
* event: any (required) — the event object containing the body to be parsed.
|
|
893
|
+
* @outputSpec any — the parsed JSON object or null if no body is present.
|
|
894
|
+
* @throws Error — Invalid JSON in request body
|
|
895
|
+
* @sideEffects none
|
|
896
|
+
* @stability stable
|
|
897
|
+
* @calls JSON.parse
|
|
898
|
+
* @cil-generated
|
|
899
|
+
*/
|
|
900
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:parsebody:function" type="function" identity="parseBody" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
901
|
+
// CIL[DOC-MACRO purpose="parseBody function"]
|
|
902
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the parseBody function."]
|
|
903
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
904
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
905
|
+
// CIL[DOC-MICRO logic_summary="Implements the parseBody function." notable_decisions="[]"]
|
|
906
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
907
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
438
908
|
export function parseBody(event: any): any {
|
|
439
909
|
if (!event.body) return null
|
|
440
910
|
|
|
@@ -444,23 +914,66 @@ export function parseBody(event: any): any {
|
|
|
444
914
|
throw new Error('Invalid JSON in request body')
|
|
445
915
|
}
|
|
446
916
|
}
|
|
447
|
-
// CIL[END
|
|
448
|
-
// CIL[
|
|
449
|
-
// CIL[DOC-
|
|
450
|
-
// CIL[DOC-
|
|
451
|
-
// CIL[DOC-
|
|
452
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="wrapped handler or error" errors="auth errors" side_effects="none"]
|
|
453
|
-
// CIL[DOC-MICRO logic_summary="Ensures principal is authenticated and has account context" notable_decisions="[]"]
|
|
454
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
455
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
456
|
-
// CIL[DOC-VECTOR type="context" content="Layer: infrastructure. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
457
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
458
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
459
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
917
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:parsebody:function"]
|
|
918
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Parses the body of an event to extract JSON data.'; No verified external callers" status="ready"]
|
|
919
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
920
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
921
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
460
922
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
461
923
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
924
|
+
// CIL[DOC-MACRO purpose="The requireUserContext function ensures that a valid user context is present before executing a handler function or returning an error."]
|
|
925
|
+
// CIL[DOC-RESPONSIBILITY responsibility="The requireUserContext function ensures that a valid user context is present before executing a handler function or returning an error. It is used to enforce user authentication and account association in middleware."]
|
|
926
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
927
|
+
// CIL[DOC-CONTRACT inputs="- arg: HandlerFunction | RequestContext (required) — a function to handle requests or a context object containing user information." outputs="HandlerFunction | HandlerResult | null — returns a handler function, an error result, or null based on user context validation." errors="Error — User context (person and account) required" side_effects="none dependencies="error"]
|
|
928
|
+
// CIL[DOC-MICRO logic_summary="The requireUserContext function ensures that a valid user context is present before executing a handler function or returning an error. It is used to enforce user authentication and account association in middleware." notable_decisions="none"]
|
|
929
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
930
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
931
|
+
/**
|
|
932
|
+
* The requireUserContext function ensures that a valid user context is present before executing a handler function or returning an error. It is used to enforce user authentication and account association in middleware.
|
|
933
|
+
*
|
|
934
|
+
* @inputSpec
|
|
935
|
+
* - arg: HandlerFunction | RequestContext (required) — a function to handle requests or a context object containing user information.
|
|
936
|
+
* @outputSpec HandlerFunction | HandlerResult | null — returns a handler function, an error result, or null based on user context validation.
|
|
937
|
+
* @throws Error — User context (person and account) required
|
|
938
|
+
* @sideEffects none
|
|
939
|
+
* @stability stable
|
|
940
|
+
* @calls error
|
|
941
|
+
* @cil-generated
|
|
942
|
+
*/
|
|
943
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requireusercontext_signature_1:function" type="function" identity="requireUserContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
944
|
+
// CIL[DOC-MACRO purpose="requireUserContext function"]
|
|
945
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireUserContext function."]
|
|
946
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
947
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
948
|
+
// CIL[DOC-MICRO logic_summary="Implements the requireUserContext function." notable_decisions="[]"]
|
|
949
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
950
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
462
951
|
export function requireUserContext(handler: HandlerFunction): HandlerFunction
|
|
952
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requireusercontext_signature_1:function"]
|
|
953
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requireusercontext_signature_2:function" type="function" identity="requireUserContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
954
|
+
// CIL[DOC-MACRO purpose="requireUserContext function"]
|
|
955
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireUserContext function."]
|
|
956
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
957
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
958
|
+
// CIL[DOC-MICRO logic_summary="Implements the requireUserContext function." notable_decisions="[]"]
|
|
959
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
960
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
961
|
+
// CIL[DOC-VECTOR type="context" content="purpose='The requireUserContext function ensures that a valid user context is present before executing a handler function or returning an error.'; No verified external callers" status="ready"]
|
|
962
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
963
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
964
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
965
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
966
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
463
967
|
export function requireUserContext(ctx: RequestContext): HandlerResult | null
|
|
968
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requireusercontext_signature_2:function"]
|
|
969
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requireusercontext:function" type="function" identity="requireUserContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
970
|
+
// CIL[DOC-MACRO purpose="requireUserContext function"]
|
|
971
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireUserContext function."]
|
|
972
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
973
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
974
|
+
// CIL[DOC-MICRO logic_summary="Implements the requireUserContext function." notable_decisions="[]"]
|
|
975
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
976
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
464
977
|
export function requireUserContext(arg: HandlerFunction | RequestContext): HandlerFunction | HandlerResult | null {
|
|
465
978
|
if (typeof arg === 'function') {
|
|
466
979
|
const handler = arg
|
|
@@ -478,23 +991,64 @@ export function requireUserContext(arg: HandlerFunction | RequestContext): Handl
|
|
|
478
991
|
}
|
|
479
992
|
return null
|
|
480
993
|
}
|
|
481
|
-
// CIL[END
|
|
482
|
-
// CIL[
|
|
483
|
-
// CIL[DOC-
|
|
484
|
-
// CIL[DOC-
|
|
485
|
-
// CIL[DOC-
|
|
486
|
-
// CIL[DOC-
|
|
487
|
-
// CIL[DOC-
|
|
488
|
-
// CIL[DOC-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
994
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requireusercontext:function"]
|
|
995
|
+
// CIL[DOC-MACRO purpose="Middleware function that enforces authentication and authorization for system-level operations."]
|
|
996
|
+
// CIL[DOC-RESPONSIBILITY responsibility="This function ensures that the context provided is authenticated and has system administrator privileges, adding an audit trail by tracking who triggered the action. It is used to enforce security requirements in middleware operations. Error — System context required, if the principal is not a system administrator."]
|
|
997
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
998
|
+
// CIL[DOC-CONTRACT inputs="- arg: HandlerFunction | RequestContext (required) — the handler function or request context to be processed.\\n- triggeredBy: string (optional) — the identifier of the user or process that triggered the action." outputs="HandlerFunction | HandlerResult | null — returns a handler function for further processing, an error result, or null if validation passes." errors="Error — Authentication required, if the principal is not authenticated." side_effects="none dependencies="isSystemAdmin, error"]
|
|
999
|
+
// CIL[DOC-MICRO logic_summary="Validates the principal's identity and role before executing the provided handler function or returning an error." notable_decisions="none"]
|
|
1000
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1001
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1002
|
+
/**
|
|
1003
|
+
* This function ensures that the context provided is authenticated and has system administrator privileges, adding an audit trail by tracking who triggered the action. It is used to enforce security requirements in middleware operations.
|
|
1004
|
+
*
|
|
1005
|
+
* @macro Middleware function that enforces authentication and authorization for system-level operations.
|
|
1006
|
+
* @micro Validates the principal's identity and role before executing the provided handler function or returning an error.
|
|
1007
|
+
* @inputSpec
|
|
1008
|
+
* - arg: HandlerFunction | RequestContext (required) — the handler function or request context to be processed.
|
|
1009
|
+
* - triggeredBy: string (optional) — the identifier of the user or process that triggered the action.
|
|
1010
|
+
* @outputSpec HandlerFunction | HandlerResult | null — returns a handler function for further processing, an error result, or null if validation passes.
|
|
1011
|
+
* @throws Error — Authentication required, if the principal is not authenticated.
|
|
1012
|
+
Error — System context required, if the principal is not a system administrator.
|
|
1013
|
+
* @sideEffects none
|
|
1014
|
+
* @stability stable
|
|
1015
|
+
* @calls isSystemAdmin, error
|
|
1016
|
+
* @cil-generated
|
|
1017
|
+
*/
|
|
1018
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requiresystemcontextwithaudit_signature_1:function" type="function" identity="requireSystemContextWithAudit" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
1019
|
+
// CIL[DOC-MACRO purpose="requireSystemContextWithAudit function"]
|
|
1020
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireSystemContextWithAudit function."]
|
|
1021
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
1022
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
1023
|
+
// CIL[DOC-MICRO logic_summary="Implements the requireSystemContextWithAudit function." notable_decisions="[]"]
|
|
1024
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
1025
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1026
|
+
export function requireSystemContextWithAudit(handler: HandlerFunction): HandlerFunction
|
|
1027
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requiresystemcontextwithaudit_signature_1:function"]
|
|
1028
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requiresystemcontextwithaudit_signature_2:function" type="function" identity="requireSystemContextWithAudit" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
1029
|
+
// CIL[DOC-MACRO purpose="requireSystemContextWithAudit function"]
|
|
1030
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireSystemContextWithAudit function."]
|
|
1031
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
1032
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
1033
|
+
// CIL[DOC-MICRO logic_summary="Implements the requireSystemContextWithAudit function." notable_decisions="[]"]
|
|
1034
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
1035
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1036
|
+
// CIL[DOC-VECTOR type="context" content="purpose='This function ensures that the context provided is authenticated and has system administrator privileges, adding an audit trail by tracking who triggered the action.'; No verified external callers" status="ready"]
|
|
1037
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
1038
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
1039
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
494
1040
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
495
1041
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
496
|
-
export function requireSystemContextWithAudit(handler: HandlerFunction): HandlerFunction
|
|
497
1042
|
export function requireSystemContextWithAudit(ctx: RequestContext, triggeredBy?: string): HandlerResult | null
|
|
1043
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requiresystemcontextwithaudit_signature_2:function"]
|
|
1044
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requiresystemcontextwithaudit:function" type="function" identity="requireSystemContextWithAudit" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
1045
|
+
// CIL[DOC-MACRO purpose="requireSystemContextWithAudit function"]
|
|
1046
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireSystemContextWithAudit function."]
|
|
1047
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
1048
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
1049
|
+
// CIL[DOC-MICRO logic_summary="Implements the requireSystemContextWithAudit function." notable_decisions="[]"]
|
|
1050
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
1051
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
498
1052
|
export function requireSystemContextWithAudit(
|
|
499
1053
|
arg: HandlerFunction | RequestContext,
|
|
500
1054
|
triggeredBy?: string,
|
|
@@ -523,22 +1077,38 @@ export function requireSystemContextWithAudit(
|
|
|
523
1077
|
;(ctx as any).triggeredBy = triggeredBy || ctx.principal.id
|
|
524
1078
|
return null
|
|
525
1079
|
}
|
|
526
|
-
// CIL[END
|
|
527
|
-
// CIL[
|
|
528
|
-
// CIL[DOC-
|
|
529
|
-
// CIL[DOC-
|
|
530
|
-
// CIL[DOC-
|
|
531
|
-
// CIL[DOC-
|
|
532
|
-
// CIL[DOC-
|
|
533
|
-
// CIL[DOC-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
1080
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requiresystemcontextwithaudit:function"]
|
|
1081
|
+
// CIL[DOC-MACRO purpose="The cors function enables Cross-Origin Resource Sharing (CORS) for HTTP responses."]
|
|
1082
|
+
// CIL[DOC-RESPONSIBILITY responsibility="The cors function enables Cross-Origin Resource Sharing (CORS) for HTTP responses. It is used to allow web applications running at one origin to access resources from a different origin."]
|
|
1083
|
+
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
1084
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="Promise<{ message: string }> — returns a JSON object with a message indicating CORS is enabled." errors="none" side_effects="none dependencies="json"]
|
|
1085
|
+
// CIL[DOC-MICRO logic_summary="The cors function enables Cross-Origin Resource Sharing (CORS) for HTTP responses. It is used to allow web applications running at one origin to access resources from a different origin." notable_decisions="none"]
|
|
1086
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1087
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1088
|
+
/**
|
|
1089
|
+
* The cors function enables Cross-Origin Resource Sharing (CORS) for HTTP responses. It is used to allow web applications running at one origin to access resources from a different origin.
|
|
1090
|
+
*
|
|
1091
|
+
* @outputSpec Promise<{ message: string }> — returns a JSON object with a message indicating CORS is enabled.
|
|
1092
|
+
* @sideEffects none
|
|
1093
|
+
* @stability stable
|
|
1094
|
+
* @calls json
|
|
1095
|
+
* @cil-generated
|
|
1096
|
+
*/
|
|
1097
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:cors:function" type="function" identity="cors" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
1098
|
+
// CIL[DOC-MACRO purpose="cors function"]
|
|
1099
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the cors function."]
|
|
1100
|
+
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
1101
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
1102
|
+
// CIL[DOC-MICRO logic_summary="Implements the cors function." notable_decisions="[]"]
|
|
1103
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
1104
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
541
1105
|
export function cors() {
|
|
542
1106
|
return json({ message: 'CORS enabled' }, 200)
|
|
543
1107
|
}
|
|
544
|
-
// CIL[END
|
|
1108
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:cors:function"]
|
|
1109
|
+
// CIL[DOC-VECTOR type="context" content="purpose='The cors function enables Cross-Origin Resource Sharing (CORS) for HTTP responses.'; No verified external callers" status="ready"]
|
|
1110
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
1111
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
1112
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
1113
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
1114
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|