spine-framework 0.4.4 → 0.5.0-rc.4
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 +13 -3
- package/.framework/cli/commands/bootstrap.ts +392 -0
- package/.framework/cli/commands/dev.ts +91 -218
- package/.framework/cli/commands/doctor.ts +132 -26
- package/.framework/cli/commands/generate.ts +38 -298
- package/.framework/cli/commands/init.ts +20 -1
- package/.framework/cli/commands/migrate.ts +36 -30
- package/.framework/cli/commands/migrations.ts +16 -56
- package/.framework/cli/commands/upgrade.ts +35 -0
- package/.framework/cli/commands/validate-schema.ts +147 -0
- package/.framework/cli/context.ts +223 -110
- package/.framework/cli/index.ts +6 -0
- package/.framework/cli/lib/project-files.ts +241 -1
- package/.framework/functions/_shared/hash-api-key.ts +183 -79
- package/.framework/functions/_shared/logging.ts +562 -224
- package/.framework/functions/_shared/middleware.ts +47 -44
- package/.framework/functions/admin-data.ts +39 -28
- package/.framework/functions/ai-agents.ts +10 -6
- package/.framework/functions/api-keys.ts +301 -122
- package/.framework/functions/apps.ts +43 -26
- package/.framework/functions/cil-ingest.ts +48 -15
- package/.framework/functions/debug-auth.ts +14 -8
- package/.framework/functions/deliveries.ts +39 -12
- package/.framework/functions/embeddings.ts +145 -76
- package/.framework/functions/integration-outbound.ts +67 -27
- package/.framework/functions/integrations.ts +254 -127
- package/.framework/functions/logs.ts +273 -133
- package/.framework/functions/observability.ts +277 -147
- package/.framework/functions/pipeline-executions.ts +1 -1
- package/.framework/functions/pipelines.ts +14 -9
- package/.framework/functions/prompt-configs.ts +7 -4
- package/.framework/functions/roles.ts +8 -5
- package/.framework/functions/security.ts +30 -17
- package/.framework/functions/system-cron.ts +240 -127
- package/.framework/functions/tests.ts +7 -6
- package/.framework/functions/timers.ts +310 -107
- package/.framework/functions/triggers.ts +28 -13
- package/.framework/functions/types.ts +13 -10
- package/.framework/migrations/069_log_stats_window.sql +54 -0
- package/.framework/migrations/070_app_type_schema_rpcs.sql +166 -0
- package/.framework/migrations/071_timer_interval_keys.sql +96 -0
- package/.framework/migrations/072_slug_autofill.sql +77 -0
- package/.framework/migrations/073_seed_member_roles.sql +26 -0
- package/.framework/src/apps/admin/index.tsx +1141 -775
- package/.framework/src/components/ErrorBoundary.tsx +136 -0
- package/.framework/src/components/admin/AdminListPage.tsx +81 -73
- package/.framework/src/components/admin/AdminSidebar.tsx +88 -79
- package/.framework/src/components/admin/EntitySelect.tsx +181 -0
- package/.framework/src/components/admin/PageInstructions.tsx +86 -127
- package/.framework/src/components/app-shell/GenericDetailPage.tsx +37 -13
- package/.framework/src/components/app-shell/GenericListPage.tsx +28 -32
- package/.framework/src/components/layout/Sidebar.tsx +300 -177
- package/.framework/src/components/runtime/DataDetailPage.tsx +67 -35
- package/.framework/src/components/runtime/DataHeader.tsx +96 -48
- package/.framework/src/components/runtime/DataListPage.tsx +3 -26
- package/.framework/src/components/runtime/DataStats.tsx +10 -10
- package/.framework/src/components/runtime/DataTable.tsx +12 -10
- package/.framework/src/components/ui/sheet.tsx +24 -26
- package/.framework/src/components/ui/textarea.tsx +74 -48
- package/.framework/src/hooks/useEntityList.ts +12 -9
- package/.framework/src/hooks/useListSchema.ts +108 -58
- package/.framework/src/instructions/README.md +57 -0
- package/.framework/src/instructions/ai-agents.md +69 -0
- package/.framework/src/instructions/alerts.md +80 -0
- package/.framework/src/instructions/api-keys.md +87 -0
- package/.framework/src/instructions/apps.md +77 -0
- package/.framework/src/instructions/concepts/ai-and-prompts.md +150 -0
- package/.framework/src/instructions/concepts/apps-and-renderers.md +162 -0
- package/.framework/src/instructions/concepts/auth-and-api-keys.md +133 -0
- package/.framework/src/instructions/concepts/automation.md +186 -0
- package/.framework/src/instructions/concepts/concurrency-and-idempotency.md +125 -0
- package/.framework/src/instructions/concepts/core-vs-custom.md +124 -0
- package/.framework/src/instructions/concepts/design-schema.md +152 -0
- package/.framework/src/instructions/concepts/integrations-and-webhooks.md +127 -0
- package/.framework/src/instructions/concepts/observability.md +116 -0
- package/.framework/src/instructions/concepts/permissions.md +150 -0
- package/.framework/src/instructions/concepts/runtime-records.md +111 -0
- package/.framework/src/instructions/concepts/scope-and-accounts.md +112 -0
- package/.framework/src/instructions/concepts/spine-way.md +172 -0
- package/.framework/src/instructions/deliveries.md +59 -0
- package/.framework/src/instructions/guide/00-orientation.md +106 -0
- package/.framework/src/instructions/guide/01-install-and-first-run.md +253 -0
- package/.framework/src/instructions/guide/02-project-map.md +147 -0
- package/.framework/src/instructions/guide/03-domain-model.md +223 -0
- package/.framework/src/instructions/guide/04-first-app.md +227 -0
- package/.framework/src/instructions/guide/05-glossary.md +183 -0
- package/.framework/src/instructions/integrations.md +96 -0
- package/.framework/src/instructions/internal/cil-markers.md +83 -0
- package/.framework/src/instructions/invites.md +60 -0
- package/.framework/src/instructions/kb.md +80 -0
- package/.framework/src/instructions/logs.md +77 -0
- package/.framework/src/instructions/observability.md +61 -0
- package/.framework/src/instructions/operations/deployment.md +115 -0
- package/.framework/src/instructions/operations/migrations.md +125 -0
- package/.framework/src/instructions/operations/security-checklist.md +148 -0
- package/.framework/src/instructions/operations/troubleshooting.md +170 -0
- package/.framework/src/instructions/operations/upgrade.md +116 -0
- package/.framework/src/instructions/pipeline-executions.md +62 -0
- package/.framework/src/instructions/pipelines.md +78 -0
- package/.framework/src/instructions/prompts.md +95 -0
- package/.framework/src/instructions/reference/api/admin-data.md +162 -0
- package/.framework/src/instructions/reference/api/auth.md +113 -0
- package/.framework/src/instructions/reference/api/errors-and-envelopes.md +113 -0
- package/.framework/src/instructions/reference/app-manifest.md +150 -0
- package/.framework/src/instructions/reference/cli.md +124 -0
- package/.framework/src/instructions/reference/database.md +132 -0
- package/.framework/src/instructions/reference/design-schema.md +280 -0
- package/.framework/src/instructions/reference/env-vars.md +133 -0
- package/.framework/src/instructions/reference/functions/account-nodes.md +75 -0
- package/.framework/src/instructions/reference/functions/admin-data.md +195 -0
- package/.framework/src/instructions/reference/functions/admin-funnel.md +90 -0
- package/.framework/src/instructions/reference/functions/admin-install-funnel.md +107 -0
- package/.framework/src/instructions/reference/functions/admin-signals.md +102 -0
- package/.framework/src/instructions/reference/functions/ai-agents.md +148 -0
- package/.framework/src/instructions/reference/functions/ai-interactions.md +156 -0
- package/.framework/src/instructions/reference/functions/api-keys.md +130 -0
- package/.framework/src/instructions/reference/functions/apps.md +140 -0
- package/.framework/src/instructions/reference/functions/auth.md +99 -0
- package/.framework/src/instructions/reference/functions/debug-auth.md +91 -0
- package/.framework/src/instructions/reference/functions/deliveries.md +110 -0
- package/.framework/src/instructions/reference/functions/embeddings.md +166 -0
- package/.framework/src/instructions/reference/functions/eval-harness.md +149 -0
- package/.framework/src/instructions/reference/functions/index.md +103 -0
- package/.framework/src/instructions/reference/functions/integration-outbound.md +200 -0
- package/.framework/src/instructions/reference/functions/integration-routes.md +151 -0
- package/.framework/src/instructions/reference/functions/integrations.md +130 -0
- package/.framework/src/instructions/reference/functions/invites.md +182 -0
- package/.framework/src/instructions/reference/functions/item-progress.md +107 -0
- package/.framework/src/instructions/reference/functions/kb.md +166 -0
- package/.framework/src/instructions/reference/functions/logs.md +141 -0
- package/.framework/src/instructions/reference/functions/observability.md +105 -0
- package/.framework/src/instructions/reference/functions/pipeline-executions.md +132 -0
- package/.framework/src/instructions/reference/functions/pipeline-runner-background.md +121 -0
- package/.framework/src/instructions/reference/functions/pipelines.md +136 -0
- package/.framework/src/instructions/reference/functions/prompt-configs.md +121 -0
- package/.framework/src/instructions/reference/functions/roles.md +121 -0
- package/.framework/src/instructions/reference/functions/security.md +140 -0
- package/.framework/src/instructions/reference/functions/system-cron.md +136 -0
- package/.framework/src/instructions/reference/functions/system.md +106 -0
- package/.framework/src/instructions/reference/functions/tests.md +97 -0
- package/.framework/src/instructions/reference/functions/timers.md +117 -0
- package/.framework/src/instructions/reference/functions/trigger-scheduler.md +102 -0
- package/.framework/src/instructions/reference/functions/triggers.md +140 -0
- package/.framework/src/instructions/reference/functions/types.md +146 -0
- package/.framework/src/instructions/reference/seeds.md +126 -0
- package/.framework/src/instructions/reference/shared-modules.md +127 -0
- package/.framework/src/instructions/reference/spine-config.md +114 -0
- package/.framework/src/instructions/roles.md +80 -0
- package/.framework/src/instructions/runtime-detail.md +70 -0
- package/.framework/src/instructions/runtime-list.md +77 -0
- package/.framework/src/instructions/security.md +67 -0
- package/.framework/src/instructions/tasks/add-a-pipeline.md +110 -0
- package/.framework/src/instructions/tasks/add-a-role.md +96 -0
- package/.framework/src/instructions/tasks/add-a-timer.md +114 -0
- package/.framework/src/instructions/tasks/add-a-trigger.md +106 -0
- package/.framework/src/instructions/tasks/add-a-type.md +151 -0
- package/.framework/src/instructions/tasks/add-a-webhook.md +108 -0
- package/.framework/src/instructions/tasks/add-an-ai-agent.md +108 -0
- package/.framework/src/instructions/tasks/add-an-integration.md +124 -0
- package/.framework/src/instructions/tasks/build-a-custom-page.md +118 -0
- package/.framework/src/instructions/tasks/package-and-install-an-app.md +127 -0
- package/.framework/src/instructions/tasks/test-your-code.md +108 -0
- package/.framework/src/instructions/tasks/write-a-function.md +132 -0
- package/.framework/src/instructions/tasks/write-a-migration.md +110 -0
- package/.framework/src/instructions/testing.md +59 -0
- package/.framework/src/instructions/timers.md +82 -0
- package/.framework/src/instructions/triggers.md +69 -0
- package/.framework/src/instructions/types.md +93 -0
- package/.framework/src/pages/NotFoundPage.tsx +62 -31
- package/.framework/src/pages/admin/AIAgentDetailPage.tsx +117 -106
- package/.framework/src/pages/admin/AIAgentsPage.tsx +86 -48
- package/.framework/src/pages/admin/APIKeyDetailPage.tsx +153 -152
- package/.framework/src/pages/admin/APIKeysPage.tsx +91 -90
- package/.framework/src/pages/admin/AlertsConfigPage.tsx +29 -18
- package/.framework/src/pages/admin/AppDetailPage.tsx +6 -60
- package/.framework/src/pages/admin/AppsPage.tsx +104 -66
- package/.framework/src/pages/admin/DeliveriesPage.tsx +5 -5
- package/.framework/src/pages/admin/EmbeddingDetailPage.tsx +5 -23
- package/.framework/src/pages/admin/EmbeddingsPage.tsx +5 -26
- package/.framework/src/pages/admin/IntegrationDetailPage.tsx +7 -7
- package/.framework/src/pages/admin/IntegrationsPage.tsx +85 -43
- package/.framework/src/pages/admin/LogsPage.tsx +144 -76
- package/.framework/src/pages/admin/ObservabilityDashboard.tsx +223 -140
- package/.framework/src/pages/admin/PipelineDetailPage.tsx +134 -113
- package/.framework/src/pages/admin/PipelineExecutionsPage.tsx +108 -45
- package/.framework/src/pages/admin/PipelinesPage.tsx +160 -115
- package/.framework/src/pages/admin/PromptConfigDetailPage.tsx +96 -98
- package/.framework/src/pages/admin/PromptConfigsPage.tsx +101 -59
- package/.framework/src/pages/admin/RoleDetailPage.tsx +90 -79
- package/.framework/src/pages/admin/RolesPage.tsx +86 -43
- package/.framework/src/pages/admin/SecurityPage.tsx +1 -1
- package/.framework/src/pages/admin/TestingDashboard.tsx +16 -28
- package/.framework/src/pages/admin/TimerDetailPage.tsx +117 -100
- package/.framework/src/pages/admin/TimersPage.tsx +90 -62
- package/.framework/src/pages/admin/TriggerDetailPage.tsx +90 -83
- package/.framework/src/pages/admin/TriggersPage.tsx +124 -99
- package/.framework/src/pages/admin/TypeDetailPage.tsx +152 -138
- package/.framework/src/pages/admin/TypesPage.tsx +90 -48
- package/.framework/src/pages/admin/cil/CILAgentPage.tsx +17 -25
- package/.framework/src/pages/admin/cil/CILChunkDetailPage.tsx +17 -27
- package/.framework/src/pages/admin/cil/CILDashboardPage.tsx +72 -40
- package/.framework/src/pages/admin/cil/CILFileListPage.tsx +321 -129
- package/.framework/src/pages/admin/cil/CILFileSelectPage.tsx +18 -29
- package/.framework/src/pages/admin/cil/CILGraphPage.tsx +26 -38
- package/.framework/src/pages/admin/cil/CILIngestionPage.tsx +34 -46
- package/.framework/src/pages/admin/cil/CILProjectsPage.tsx +189 -103
- package/.framework/src/pages/admin/cil/CILSearchPage.tsx +246 -136
- package/.framework/src/pages/admin/cil/CILSuggestionsPage.tsx +11 -22
- package/.framework/src/pages/admin/cil/CILVersionsPage.tsx +9 -20
- package/.framework/src/pages/admin/cil/FlexiblePipelinePage.tsx +26 -38
- package/.framework/src/pages/admin/kb/KBAdminPage.tsx +7 -26
- package/.framework/templates/agent/AGENTS.md +150 -0
- package/.framework/templates/agent/skills/spine-add-ai-agent/SKILL.md +58 -0
- package/.framework/templates/agent/skills/spine-add-automation/SKILL.md +62 -0
- package/.framework/templates/agent/skills/spine-add-integration/SKILL.md +63 -0
- package/.framework/templates/agent/skills/spine-architect/SKILL.md +86 -0
- package/.framework/templates/agent/skills/spine-install-app/SKILL.md +72 -0
- package/.framework/templates/agent/skills/spine-migration/SKILL.md +75 -0
- package/.framework/templates/agent/skills/spine-new-app/SKILL.md +67 -0
- package/.framework/templates/agent/skills/spine-new-function/SKILL.md +65 -0
- package/.framework/templates/agent/skills/spine-new-type/SKILL.md +65 -0
- package/.framework/templates/agent/skills/spine-schema/SKILL.md +77 -0
- package/.framework/templates/agent/skills/spine-test/SKILL.md +67 -0
- package/.framework/templates/agent/skills/spine-troubleshoot/SKILL.md +74 -0
- package/.framework/templates/agent/skills/spine-upgrade/SKILL.md +69 -0
- package/.framework/templates/project.json +4 -1
- package/.framework/tests/unit/account-scoping-gates.test.ts +392 -0
- package/.framework/tests/unit/agent-files.test.ts +355 -0
- package/.framework/tests/unit/agent-runner.test.ts +479 -44
- package/.framework/tests/unit/api-keys-create-scope-gate.test.ts +160 -0
- package/.framework/tests/unit/api-keys-omit-secret-fields.test.ts +38 -0
- package/.framework/tests/unit/bootstrap.test.ts +242 -0
- package/.framework/tests/unit/cli-context-api-key.test.ts +114 -0
- package/.framework/tests/unit/debug-auth.test.ts +38 -0
- package/.framework/tests/unit/deliveries-account-scoping.test.ts +185 -0
- package/.framework/tests/unit/integration-outbound-credentials.test.ts +167 -0
- package/.framework/tests/unit/integrations-audit-redaction.test.ts +130 -0
- package/.framework/tests/unit/logging-app-id.test.ts +75 -0
- package/.framework/tests/unit/system-context-denial.test.ts +145 -0
- package/.framework/tests/unit/system-cron.test.ts +240 -0
- package/.framework/tests/unit/timers.test.ts +159 -0
- package/README.md +125 -166
- package/config/tsconfig.cli.json +2 -2
- package/package.json +15 -4
- package/templates/project/package-lock.json +2 -2
- package/.framework/docs/admin-routes.md +0 -76
- package/.framework/docs/api-docs-progress.md +0 -38
- package/.framework/docs/api-governance.md +0 -146
- package/.framework/docs/api-testing-results.md +0 -212
- package/.framework/docs/assembly-launch-guide.md +0 -138
- package/.framework/docs/audit-results.md +0 -590
- package/.framework/docs/db-api-inventory.md +0 -95
- package/.framework/docs/gap-remediation-backlog.md +0 -103
- package/.framework/docs/ui-adoption-verification.md +0 -111
- package/.framework/docs/ui-api-coverage.md +0 -84
- package/.framework/docs/v2-compatibility-audit.md +0 -228
- package/.framework/mcp/index.ts +0 -133
- package/.framework/mcp/load-env.ts +0 -60
- package/.framework/mcp/shared/app-manifest.ts +0 -275
- package/.framework/mcp/shared/db.ts +0 -477
- package/.framework/mcp/shared/kb.ts +0 -118
- package/.framework/mcp/tools/architect.ts +0 -431
- package/.framework/mcp/tools/cil/context.ts +0 -345
- package/.framework/mcp/tools/cil/graph.ts +0 -242
- package/.framework/mcp/tools/cil/ingest.ts +0 -1217
- package/.framework/mcp/tools/cil/pipeline-orchestrator.ts +0 -693
- package/.framework/mcp/tools/cil/pipeline.ts +0 -767
- package/.framework/mcp/tools/cil/project.ts +0 -791
- package/.framework/mcp/tools/cil/retrieval.ts +0 -336
- package/.framework/mcp/tools/cil/search-core.ts +0 -454
- package/.framework/mcp/tools/cil/search.ts +0 -97
- package/.framework/mcp/tools/cil/suggest.ts +0 -186
- package/.framework/mcp/tools/cil/validate.ts +0 -1369
- package/.framework/mcp/tools/kb/delete.ts +0 -139
- package/.framework/mcp/tools/kb/index.ts +0 -52
- package/.framework/mcp/tools/kb/ingest.ts +0 -84
- package/.framework/mcp/tools/kb/list-types.ts +0 -102
- package/.framework/mcp/tools/kb/publish.ts +0 -100
- package/.framework/mcp/tools/kb/reindex.ts +0 -86
- package/.framework/mcp/tools/kb/revoke.ts +0 -85
- package/.framework/mcp/tools/kb/search.ts +0 -101
- package/.framework/mcp/tools/kb/upsert.ts +0 -125
- package/.framework/mcp/tools/observability.ts +0 -510
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 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"]
|
|
1
2
|
/**
|
|
2
3
|
* @module middleware
|
|
3
4
|
* @audience internal
|
|
@@ -13,7 +14,6 @@
|
|
|
13
14
|
*
|
|
14
15
|
* @cil-generated
|
|
15
16
|
*/
|
|
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
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
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
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)."]
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
// CIL[DOC-STABILITY stability="stable"]
|
|
24
24
|
// CIL[DOC-AUDIENCE audience="internal"]
|
|
25
25
|
import {
|
|
26
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:module_header:module_header"]
|
|
26
27
|
Principal,
|
|
27
28
|
resolvePrincipal,
|
|
28
29
|
isSystemAdmin,
|
|
@@ -45,7 +46,6 @@ import {
|
|
|
45
46
|
isSampled,
|
|
46
47
|
traceDb
|
|
47
48
|
} from './tracing'
|
|
48
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:module_header:module_header"]
|
|
49
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
50
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
51
51
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -68,7 +68,6 @@ import {
|
|
|
68
68
|
* @stability stable
|
|
69
69
|
* @cil-generated
|
|
70
70
|
*/
|
|
71
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:corecontext:interface" type="interface" identity="CoreContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
72
71
|
// CIL[DOC-MACRO purpose="CoreContext interface"]
|
|
73
72
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the CoreContext interface."]
|
|
74
73
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -76,6 +75,7 @@ import {
|
|
|
76
75
|
// CIL[DOC-MICRO logic_summary="Implements the CoreContext interface." notable_decisions="[]"]
|
|
77
76
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
78
77
|
// CIL[DOC-STABILITY stability="stable"]
|
|
78
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:CoreContext:interface" type="interface" identity="CoreContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
79
79
|
export interface CoreContext {
|
|
80
80
|
principal: Principal
|
|
81
81
|
accountId: string | null
|
|
@@ -85,7 +85,7 @@ export interface CoreContext {
|
|
|
85
85
|
logLevel?: string
|
|
86
86
|
trace?: TraceContext
|
|
87
87
|
}
|
|
88
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
88
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:CoreContext:interface"]
|
|
89
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
90
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
91
91
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -107,7 +107,6 @@ export interface CoreContext {
|
|
|
107
107
|
* @stability stable
|
|
108
108
|
* @cil-generated
|
|
109
109
|
*/
|
|
110
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requestcontext:interface" type="interface" identity="RequestContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
111
110
|
// CIL[DOC-MACRO purpose="RequestContext interface"]
|
|
112
111
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the RequestContext interface."]
|
|
113
112
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -115,6 +114,7 @@ export interface CoreContext {
|
|
|
115
114
|
// CIL[DOC-MICRO logic_summary="Implements the RequestContext interface." notable_decisions="[]"]
|
|
116
115
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
117
116
|
// CIL[DOC-STABILITY stability="stable"]
|
|
117
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:RequestContext:interface" type="interface" identity="RequestContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
118
118
|
export interface RequestContext extends CoreContext {
|
|
119
119
|
appId: string | null
|
|
120
120
|
query: Record<string, string>
|
|
@@ -122,7 +122,7 @@ export interface RequestContext extends CoreContext {
|
|
|
122
122
|
/** Lowercased request headers — used by geo/rate-limit helpers. */
|
|
123
123
|
headers?: Record<string, string>
|
|
124
124
|
}
|
|
125
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
125
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:RequestContext:interface"]
|
|
126
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
127
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
128
128
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -144,7 +144,6 @@ export interface RequestContext extends CoreContext {
|
|
|
144
144
|
* @stability stable
|
|
145
145
|
* @cil-generated
|
|
146
146
|
*/
|
|
147
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:handlerfunction:type" type="type" identity="HandlerFunction" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
148
147
|
// CIL[DOC-MACRO purpose="HandlerFunction type"]
|
|
149
148
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the HandlerFunction type."]
|
|
150
149
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -152,8 +151,9 @@ export interface RequestContext extends CoreContext {
|
|
|
152
151
|
// CIL[DOC-MICRO logic_summary="Implements the HandlerFunction type." notable_decisions="[]"]
|
|
153
152
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
154
153
|
// CIL[DOC-STABILITY stability="stable"]
|
|
154
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:HandlerFunction:type" type="type" identity="HandlerFunction" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
155
155
|
export type HandlerFunction = (ctx: RequestContext, body?: any) => Promise<any>
|
|
156
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
156
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:HandlerFunction:type"]
|
|
157
157
|
// CIL[DOC-MACRO purpose="HandlerFunction type"]
|
|
158
158
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the HandlerFunction type."]
|
|
159
159
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -182,7 +182,6 @@ export type HandlerFunction = (ctx: RequestContext, body?: any) => Promise<any>
|
|
|
182
182
|
* @stability stable
|
|
183
183
|
* @cil-generated
|
|
184
184
|
*/
|
|
185
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:handlerresult:interface" type="interface" identity="HandlerResult" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
186
185
|
// CIL[DOC-MACRO purpose="HandlerResult interface"]
|
|
187
186
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the HandlerResult interface."]
|
|
188
187
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -190,12 +189,13 @@ export type HandlerFunction = (ctx: RequestContext, body?: any) => Promise<any>
|
|
|
190
189
|
// CIL[DOC-MICRO logic_summary="Implements the HandlerResult interface." notable_decisions="[]"]
|
|
191
190
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
192
191
|
// CIL[DOC-STABILITY stability="stable"]
|
|
192
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:HandlerResult:interface" type="interface" identity="HandlerResult" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
193
193
|
export interface HandlerResult {
|
|
194
194
|
data?: any
|
|
195
195
|
error?: string
|
|
196
196
|
meta?: any
|
|
197
197
|
}
|
|
198
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
198
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:HandlerResult:interface"]
|
|
199
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
200
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
201
201
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -220,7 +220,6 @@ export interface HandlerResult {
|
|
|
220
220
|
* @stability stable
|
|
221
221
|
* @cil-generated
|
|
222
222
|
*/
|
|
223
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:isvaliduuid:function" type="function" identity="isValidUuid" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
224
223
|
// CIL[DOC-MACRO purpose="isValidUuid function"]
|
|
225
224
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the isValidUuid function."]
|
|
226
225
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -228,12 +227,13 @@ export interface HandlerResult {
|
|
|
228
227
|
// CIL[DOC-MICRO logic_summary="Implements the isValidUuid function." notable_decisions="[]"]
|
|
229
228
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
230
229
|
// CIL[DOC-STABILITY stability="stable"]
|
|
230
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:isValidUuid:function" type="function" identity="isValidUuid" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
231
231
|
function isValidUuid(value: any): value is string {
|
|
232
232
|
if (typeof value !== 'string') return false
|
|
233
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
|
|
234
234
|
return uuidRegex.test(value)
|
|
235
235
|
}
|
|
236
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
236
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:isValidUuid:function"]
|
|
237
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
238
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
239
239
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -262,7 +262,6 @@ function isValidUuid(value: any): value is string {
|
|
|
262
262
|
* @calls parseTraceParent, parseTraceState, generateSpanId, formatTraceState, isSampled
|
|
263
263
|
* @cil-generated
|
|
264
264
|
*/
|
|
265
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:buildtracecontext:function" type="function" identity="buildTraceContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
266
265
|
// CIL[DOC-MACRO purpose="buildTraceContext function"]
|
|
267
266
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the buildTraceContext function."]
|
|
268
267
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -270,6 +269,7 @@ function isValidUuid(value: any): value is string {
|
|
|
270
269
|
// CIL[DOC-MICRO logic_summary="Implements the buildTraceContext function." notable_decisions="[]"]
|
|
271
270
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
272
271
|
// CIL[DOC-STABILITY stability="stable"]
|
|
272
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:buildTraceContext:function" type="function" identity="buildTraceContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
273
273
|
function buildTraceContext(event: any, requestId: string): TraceContext {
|
|
274
274
|
const traceparentHeader =
|
|
275
275
|
event.headers?.['traceparent'] ||
|
|
@@ -300,7 +300,7 @@ function buildTraceContext(event: any, requestId: string): TraceContext {
|
|
|
300
300
|
sampled: true
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
303
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:buildTraceContext:function"]
|
|
304
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
305
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
306
306
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -327,7 +327,6 @@ function buildTraceContext(event: any, requestId: string): TraceContext {
|
|
|
327
327
|
* @calls formatTraceParent
|
|
328
328
|
* @cil-generated
|
|
329
329
|
*/
|
|
330
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:traceresponseheaders:function" type="function" identity="traceResponseHeaders" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
331
330
|
// CIL[DOC-MACRO purpose="traceResponseHeaders function"]
|
|
332
331
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the traceResponseHeaders function."]
|
|
333
332
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -335,6 +334,7 @@ function buildTraceContext(event: any, requestId: string): TraceContext {
|
|
|
335
334
|
// CIL[DOC-MICRO logic_summary="Implements the traceResponseHeaders function." notable_decisions="[]"]
|
|
336
335
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
337
336
|
// CIL[DOC-STABILITY stability="stable"]
|
|
337
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:traceResponseHeaders:function" type="function" identity="traceResponseHeaders" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
338
338
|
function traceResponseHeaders(trace?: TraceContext, requestId?: string): Record<string, string> {
|
|
339
339
|
const headers: Record<string, string> = {}
|
|
340
340
|
if (requestId) headers['X-Request-ID'] = requestId
|
|
@@ -342,7 +342,7 @@ function traceResponseHeaders(trace?: TraceContext, requestId?: string): Record<
|
|
|
342
342
|
if (trace?.traceState) headers['tracestate'] = trace.traceState
|
|
343
343
|
return headers
|
|
344
344
|
}
|
|
345
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
345
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:traceResponseHeaders:function"]
|
|
346
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
347
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
348
348
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -368,7 +368,6 @@ function traceResponseHeaders(trace?: TraceContext, requestId?: string): Record<
|
|
|
368
368
|
* @stability stable
|
|
369
369
|
* @cil-generated
|
|
370
370
|
*/
|
|
371
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:mergeheaders:function" type="function" identity="mergeHeaders" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
372
371
|
// CIL[DOC-MACRO purpose="mergeHeaders function"]
|
|
373
372
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the mergeHeaders function."]
|
|
374
373
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -376,10 +375,11 @@ function traceResponseHeaders(trace?: TraceContext, requestId?: string): Record<
|
|
|
376
375
|
// CIL[DOC-MICRO logic_summary="Implements the mergeHeaders function." notable_decisions="[]"]
|
|
377
376
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
378
377
|
// CIL[DOC-STABILITY stability="stable"]
|
|
378
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:mergeHeaders:function" type="function" identity="mergeHeaders" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
379
379
|
function mergeHeaders(base: Record<string, string>, extra?: Record<string, string>): Record<string, string> {
|
|
380
380
|
return { ...base, ...extra }
|
|
381
381
|
}
|
|
382
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
382
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:mergeHeaders:function"]
|
|
383
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
384
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
385
385
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -407,7 +407,6 @@ function mergeHeaders(base: Record<string, string>, extra?: Record<string, strin
|
|
|
407
407
|
* @errorHandling returns an error response with a status code for authentication failures and JSON parsing errors.
|
|
408
408
|
* @cil-generated
|
|
409
409
|
*/
|
|
410
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:createhandler:function" type="function" identity="createHandler" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
411
410
|
// CIL[DOC-MACRO purpose="createHandler function"]
|
|
412
411
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the createHandler function."]
|
|
413
412
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -415,6 +414,7 @@ function mergeHeaders(base: Record<string, string>, extra?: Record<string, strin
|
|
|
415
414
|
// CIL[DOC-MICRO logic_summary="Implements the createHandler function." notable_decisions="[]"]
|
|
416
415
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
417
416
|
// CIL[DOC-STABILITY stability="stable"]
|
|
417
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:createHandler:function" type="function" identity="createHandler" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
418
418
|
export function createHandler(handler: HandlerFunction) {
|
|
419
419
|
return async (event: any, context: any) => {
|
|
420
420
|
if (event && event.requestId && event.principal) {
|
|
@@ -561,7 +561,7 @@ export function createHandler(handler: HandlerFunction) {
|
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
564
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:createHandler:function"]
|
|
565
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
566
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
567
567
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -589,7 +589,6 @@ export function createHandler(handler: HandlerFunction) {
|
|
|
589
589
|
* @errorHandling returns an error response for invalid JSON in the request body.
|
|
590
590
|
* @cil-generated
|
|
591
591
|
*/
|
|
592
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:createpublichandler:function" type="function" identity="createPublicHandler" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
593
592
|
// CIL[DOC-MACRO purpose="createPublicHandler function"]
|
|
594
593
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the createPublicHandler function."]
|
|
595
594
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -597,6 +596,7 @@ export function createHandler(handler: HandlerFunction) {
|
|
|
597
596
|
// CIL[DOC-MICRO logic_summary="Implements the createPublicHandler function." notable_decisions="[]"]
|
|
598
597
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
599
598
|
// CIL[DOC-STABILITY stability="stable"]
|
|
599
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:createPublicHandler:function" type="function" identity="createPublicHandler" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
600
600
|
export function createPublicHandler(handler: HandlerFunction) {
|
|
601
601
|
return async (event: any, context: any) => {
|
|
602
602
|
if (event && event.requestId && event.principal) {
|
|
@@ -720,7 +720,7 @@ export function createPublicHandler(handler: HandlerFunction) {
|
|
|
720
720
|
}
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
723
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:createPublicHandler:function"]
|
|
724
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
725
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
726
726
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -750,7 +750,6 @@ export function createPublicHandler(handler: HandlerFunction) {
|
|
|
750
750
|
* @calls formatTraceParent
|
|
751
751
|
* @cil-generated
|
|
752
752
|
*/
|
|
753
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:json:function" type="function" identity="json" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
754
753
|
// CIL[DOC-MACRO purpose="json function"]
|
|
755
754
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the json function."]
|
|
756
755
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -758,6 +757,7 @@ export function createPublicHandler(handler: HandlerFunction) {
|
|
|
758
757
|
// CIL[DOC-MICRO logic_summary="Implements the json function." notable_decisions="[]"]
|
|
759
758
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
760
759
|
// CIL[DOC-STABILITY stability="stable"]
|
|
760
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:json:function" type="function" identity="json" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
761
761
|
export function json(data: any, status: number = 200, requestId?: string, trace?: TraceContext) {
|
|
762
762
|
const headers: Record<string, string> = {
|
|
763
763
|
'Content-Type': 'application/json',
|
|
@@ -810,7 +810,6 @@ export function json(data: any, status: number = 200, requestId?: string, trace?
|
|
|
810
810
|
* @calls json
|
|
811
811
|
* @cil-generated
|
|
812
812
|
*/
|
|
813
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:error:function" type="function" identity="error" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
814
813
|
// CIL[DOC-MACRO purpose="error function"]
|
|
815
814
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the error function."]
|
|
816
815
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -818,6 +817,7 @@ export function json(data: any, status: number = 200, requestId?: string, trace?
|
|
|
818
817
|
// CIL[DOC-MICRO logic_summary="Implements the error function." notable_decisions="[]"]
|
|
819
818
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
820
819
|
// CIL[DOC-STABILITY stability="stable"]
|
|
820
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:error:function" type="function" identity="error" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
821
821
|
export function error(message: string, status: number = 400, requestId?: string, trace?: TraceContext) {
|
|
822
822
|
return json({
|
|
823
823
|
data: null,
|
|
@@ -855,7 +855,6 @@ export function error(message: string, status: number = 400, requestId?: string,
|
|
|
855
855
|
* @calls json
|
|
856
856
|
* @cil-generated
|
|
857
857
|
*/
|
|
858
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:structurederror:function" type="function" identity="structuredError" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
859
858
|
// CIL[DOC-MACRO purpose="structuredError function"]
|
|
860
859
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the structuredError function."]
|
|
861
860
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -863,6 +862,7 @@ export function error(message: string, status: number = 400, requestId?: string,
|
|
|
863
862
|
// CIL[DOC-MICRO logic_summary="Implements the structuredError function." notable_decisions="[]"]
|
|
864
863
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
865
864
|
// CIL[DOC-STABILITY stability="stable"]
|
|
865
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:structuredError:function" type="function" identity="structuredError" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
866
866
|
function structuredError(err: any, status: number, requestId?: string, trace?: TraceContext) {
|
|
867
867
|
const body: Record<string, any> = { data: null, error: err?.message || 'Internal server error' }
|
|
868
868
|
for (const key of ['action', 'limit', 'retry_after']) {
|
|
@@ -871,7 +871,7 @@ function structuredError(err: any, status: number, requestId?: string, trace?: T
|
|
|
871
871
|
if (err?.retryAfter !== undefined) body.retry_after = err.retryAfter
|
|
872
872
|
return json(body, status, requestId, trace)
|
|
873
873
|
}
|
|
874
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
874
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:structuredError:function"]
|
|
875
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
876
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
877
877
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -897,7 +897,6 @@ function structuredError(err: any, status: number, requestId?: string, trace?: T
|
|
|
897
897
|
* @calls JSON.parse
|
|
898
898
|
* @cil-generated
|
|
899
899
|
*/
|
|
900
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:parsebody:function" type="function" identity="parseBody" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
901
900
|
// CIL[DOC-MACRO purpose="parseBody function"]
|
|
902
901
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the parseBody function."]
|
|
903
902
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -905,6 +904,7 @@ function structuredError(err: any, status: number, requestId?: string, trace?: T
|
|
|
905
904
|
// CIL[DOC-MICRO logic_summary="Implements the parseBody function." notable_decisions="[]"]
|
|
906
905
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
907
906
|
// CIL[DOC-STABILITY stability="stable"]
|
|
907
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:parseBody:function" type="function" identity="parseBody" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
908
908
|
export function parseBody(event: any): any {
|
|
909
909
|
if (!event.body) return null
|
|
910
910
|
|
|
@@ -914,7 +914,7 @@ export function parseBody(event: any): any {
|
|
|
914
914
|
throw new Error('Invalid JSON in request body')
|
|
915
915
|
}
|
|
916
916
|
}
|
|
917
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
917
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:parseBody:function"]
|
|
918
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
919
|
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
920
920
|
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
@@ -940,7 +940,6 @@ export function parseBody(event: any): any {
|
|
|
940
940
|
* @calls error
|
|
941
941
|
* @cil-generated
|
|
942
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
943
|
// CIL[DOC-MACRO purpose="requireUserContext function"]
|
|
945
944
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireUserContext function."]
|
|
946
945
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -948,9 +947,9 @@ export function parseBody(event: any): any {
|
|
|
948
947
|
// CIL[DOC-MICRO logic_summary="Implements the requireUserContext function." notable_decisions="[]"]
|
|
949
948
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
950
949
|
// CIL[DOC-STABILITY stability="stable"]
|
|
950
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requireUserContext:function" type="function" identity="requireUserContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
951
951
|
export function requireUserContext(handler: HandlerFunction): HandlerFunction
|
|
952
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
953
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requireusercontext_signature_2:function" type="function" identity="requireUserContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
952
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requireUserContext:function"]
|
|
954
953
|
// CIL[DOC-MACRO purpose="requireUserContext function"]
|
|
955
954
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireUserContext function."]
|
|
956
955
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -964,9 +963,9 @@ export function requireUserContext(handler: HandlerFunction): HandlerFunction
|
|
|
964
963
|
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
965
964
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
966
965
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
966
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requireUserContext:function" type="function" identity="requireUserContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
967
967
|
export function requireUserContext(ctx: RequestContext): HandlerResult | null
|
|
968
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
969
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requireusercontext:function" type="function" identity="requireUserContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
968
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requireUserContext:function"]
|
|
970
969
|
// CIL[DOC-MACRO purpose="requireUserContext function"]
|
|
971
970
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireUserContext function."]
|
|
972
971
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -974,6 +973,7 @@ export function requireUserContext(ctx: RequestContext): HandlerResult | null
|
|
|
974
973
|
// CIL[DOC-MICRO logic_summary="Implements the requireUserContext function." notable_decisions="[]"]
|
|
975
974
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
976
975
|
// CIL[DOC-STABILITY stability="stable"]
|
|
976
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requireUserContext:function" type="function" identity="requireUserContext" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
977
977
|
export function requireUserContext(arg: HandlerFunction | RequestContext): HandlerFunction | HandlerResult | null {
|
|
978
978
|
if (typeof arg === 'function') {
|
|
979
979
|
const handler = arg
|
|
@@ -987,11 +987,11 @@ export function requireUserContext(arg: HandlerFunction | RequestContext): Handl
|
|
|
987
987
|
|
|
988
988
|
const ctx = arg
|
|
989
989
|
if (!ctx.principal || ctx.principal.id === 'anonymous' || !ctx.accountId) {
|
|
990
|
-
|
|
990
|
+
throw Object.assign(new Error('User context (person and account) required'), { statusCode: 403 })
|
|
991
991
|
}
|
|
992
992
|
return null
|
|
993
993
|
}
|
|
994
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
994
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requireUserContext:function"]
|
|
995
995
|
// CIL[DOC-MACRO purpose="Middleware function that enforces authentication and authorization for system-level operations."]
|
|
996
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
997
|
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
@@ -1015,7 +1015,6 @@ Error — System context required, if the principal is not a system administrato
|
|
|
1015
1015
|
* @calls isSystemAdmin, error
|
|
1016
1016
|
* @cil-generated
|
|
1017
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
1018
|
// CIL[DOC-MACRO purpose="requireSystemContextWithAudit function"]
|
|
1020
1019
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireSystemContextWithAudit function."]
|
|
1021
1020
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -1023,9 +1022,9 @@ Error — System context required, if the principal is not a system administrato
|
|
|
1023
1022
|
// CIL[DOC-MICRO logic_summary="Implements the requireSystemContextWithAudit function." notable_decisions="[]"]
|
|
1024
1023
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
1025
1024
|
// CIL[DOC-STABILITY stability="stable"]
|
|
1025
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requireSystemContextWithAudit:function" type="function" identity="requireSystemContextWithAudit" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
1026
1026
|
export function requireSystemContextWithAudit(handler: HandlerFunction): HandlerFunction
|
|
1027
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
1028
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requiresystemcontextwithaudit_signature_2:function" type="function" identity="requireSystemContextWithAudit" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
1027
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requireSystemContextWithAudit:function"]
|
|
1029
1028
|
// CIL[DOC-MACRO purpose="requireSystemContextWithAudit function"]
|
|
1030
1029
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireSystemContextWithAudit function."]
|
|
1031
1030
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -1039,9 +1038,9 @@ export function requireSystemContextWithAudit(handler: HandlerFunction): Handler
|
|
|
1039
1038
|
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
1040
1039
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
1041
1040
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1041
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requireSystemContextWithAudit:function" type="function" identity="requireSystemContextWithAudit" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
1042
1042
|
export function requireSystemContextWithAudit(ctx: RequestContext, triggeredBy?: string): HandlerResult | null
|
|
1043
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
1044
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requiresystemcontextwithaudit:function" type="function" identity="requireSystemContextWithAudit" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
1043
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requireSystemContextWithAudit:function"]
|
|
1045
1044
|
// CIL[DOC-MACRO purpose="requireSystemContextWithAudit function"]
|
|
1046
1045
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the requireSystemContextWithAudit function."]
|
|
1047
1046
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -1049,6 +1048,7 @@ export function requireSystemContextWithAudit(ctx: RequestContext, triggeredBy?:
|
|
|
1049
1048
|
// CIL[DOC-MICRO logic_summary="Implements the requireSystemContextWithAudit function." notable_decisions="[]"]
|
|
1050
1049
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
1051
1050
|
// CIL[DOC-STABILITY stability="stable"]
|
|
1051
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:requireSystemContextWithAudit:function" type="function" identity="requireSystemContextWithAudit" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
1052
1052
|
export function requireSystemContextWithAudit(
|
|
1053
1053
|
arg: HandlerFunction | RequestContext,
|
|
1054
1054
|
triggeredBy?: string,
|
|
@@ -1069,15 +1069,18 @@ export function requireSystemContextWithAudit(
|
|
|
1069
1069
|
|
|
1070
1070
|
const ctx = arg
|
|
1071
1071
|
if (!ctx.principal || ctx.principal.id === 'anonymous') {
|
|
1072
|
-
|
|
1072
|
+
// Thrown (not returned) so createHandler's catch maps statusCode to a real
|
|
1073
|
+
// HTTP status — returning the response object here let it be wrapped as
|
|
1074
|
+
// {data: {statusCode: 401}} under HTTP 200 (F-051).
|
|
1075
|
+
throw Object.assign(new Error('Authentication required'), { statusCode: 401 })
|
|
1073
1076
|
}
|
|
1074
1077
|
if (!isSystemAdmin(ctx.principal)) {
|
|
1075
|
-
|
|
1078
|
+
throw Object.assign(new Error('System context required'), { statusCode: 403 })
|
|
1076
1079
|
}
|
|
1077
1080
|
;(ctx as any).triggeredBy = triggeredBy || ctx.principal.id
|
|
1078
1081
|
return null
|
|
1079
1082
|
}
|
|
1080
|
-
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:
|
|
1083
|
+
// CIL[END stable_id="~/.framework/functions/_shared/middleware.ts:requireSystemContextWithAudit:function"]
|
|
1081
1084
|
// CIL[DOC-MACRO purpose="The cors function enables Cross-Origin Resource Sharing (CORS) for HTTP responses."]
|
|
1082
1085
|
// 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
1086
|
// CIL[DOC-CONTEXT module="middleware" layer="app-specific" related_files=".framework/functions/_shared/db,.framework/functions/_shared/audit"]
|
|
@@ -1094,7 +1097,6 @@ export function requireSystemContextWithAudit(
|
|
|
1094
1097
|
* @calls json
|
|
1095
1098
|
* @cil-generated
|
|
1096
1099
|
*/
|
|
1097
|
-
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:cors:function" type="function" identity="cors" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
1098
1100
|
// CIL[DOC-MACRO purpose="cors function"]
|
|
1099
1101
|
// CIL[DOC-RESPONSIBILITY responsibility="Implements the cors function."]
|
|
1100
1102
|
// CIL[DOC-CONTEXT module=".framework/functions/_shared/middleware.ts" layer="app-specific" related_files=""]
|
|
@@ -1102,6 +1104,7 @@ export function requireSystemContextWithAudit(
|
|
|
1102
1104
|
// CIL[DOC-MICRO logic_summary="Implements the cors function." notable_decisions="[]"]
|
|
1103
1105
|
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
1104
1106
|
// CIL[DOC-STABILITY stability="stable"]
|
|
1107
|
+
// CIL[BEGIN stable_id="~/.framework/functions/_shared/middleware.ts:cors:function" type="function" identity="cors" parent="~/.framework/functions/_shared/middleware.ts"]
|
|
1105
1108
|
export function cors() {
|
|
1106
1109
|
return json({ message: 'CORS enabled' }, 200)
|
|
1107
1110
|
}
|