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.
Files changed (283) hide show
  1. package/.env.example +13 -3
  2. package/.framework/cli/commands/bootstrap.ts +392 -0
  3. package/.framework/cli/commands/dev.ts +91 -218
  4. package/.framework/cli/commands/doctor.ts +132 -26
  5. package/.framework/cli/commands/generate.ts +38 -298
  6. package/.framework/cli/commands/init.ts +20 -1
  7. package/.framework/cli/commands/migrate.ts +36 -30
  8. package/.framework/cli/commands/migrations.ts +16 -56
  9. package/.framework/cli/commands/upgrade.ts +35 -0
  10. package/.framework/cli/commands/validate-schema.ts +147 -0
  11. package/.framework/cli/context.ts +223 -110
  12. package/.framework/cli/index.ts +6 -0
  13. package/.framework/cli/lib/project-files.ts +241 -1
  14. package/.framework/functions/_shared/hash-api-key.ts +183 -79
  15. package/.framework/functions/_shared/logging.ts +562 -224
  16. package/.framework/functions/_shared/middleware.ts +47 -44
  17. package/.framework/functions/admin-data.ts +39 -28
  18. package/.framework/functions/ai-agents.ts +10 -6
  19. package/.framework/functions/api-keys.ts +301 -122
  20. package/.framework/functions/apps.ts +43 -26
  21. package/.framework/functions/cil-ingest.ts +48 -15
  22. package/.framework/functions/debug-auth.ts +14 -8
  23. package/.framework/functions/deliveries.ts +39 -12
  24. package/.framework/functions/embeddings.ts +145 -76
  25. package/.framework/functions/integration-outbound.ts +67 -27
  26. package/.framework/functions/integrations.ts +254 -127
  27. package/.framework/functions/logs.ts +273 -133
  28. package/.framework/functions/observability.ts +277 -147
  29. package/.framework/functions/pipeline-executions.ts +1 -1
  30. package/.framework/functions/pipelines.ts +14 -9
  31. package/.framework/functions/prompt-configs.ts +7 -4
  32. package/.framework/functions/roles.ts +8 -5
  33. package/.framework/functions/security.ts +30 -17
  34. package/.framework/functions/system-cron.ts +240 -127
  35. package/.framework/functions/tests.ts +7 -6
  36. package/.framework/functions/timers.ts +310 -107
  37. package/.framework/functions/triggers.ts +28 -13
  38. package/.framework/functions/types.ts +13 -10
  39. package/.framework/migrations/069_log_stats_window.sql +54 -0
  40. package/.framework/migrations/070_app_type_schema_rpcs.sql +166 -0
  41. package/.framework/migrations/071_timer_interval_keys.sql +96 -0
  42. package/.framework/migrations/072_slug_autofill.sql +77 -0
  43. package/.framework/migrations/073_seed_member_roles.sql +26 -0
  44. package/.framework/src/apps/admin/index.tsx +1141 -775
  45. package/.framework/src/components/ErrorBoundary.tsx +136 -0
  46. package/.framework/src/components/admin/AdminListPage.tsx +81 -73
  47. package/.framework/src/components/admin/AdminSidebar.tsx +88 -79
  48. package/.framework/src/components/admin/EntitySelect.tsx +181 -0
  49. package/.framework/src/components/admin/PageInstructions.tsx +86 -127
  50. package/.framework/src/components/app-shell/GenericDetailPage.tsx +37 -13
  51. package/.framework/src/components/app-shell/GenericListPage.tsx +28 -32
  52. package/.framework/src/components/layout/Sidebar.tsx +300 -177
  53. package/.framework/src/components/runtime/DataDetailPage.tsx +67 -35
  54. package/.framework/src/components/runtime/DataHeader.tsx +96 -48
  55. package/.framework/src/components/runtime/DataListPage.tsx +3 -26
  56. package/.framework/src/components/runtime/DataStats.tsx +10 -10
  57. package/.framework/src/components/runtime/DataTable.tsx +12 -10
  58. package/.framework/src/components/ui/sheet.tsx +24 -26
  59. package/.framework/src/components/ui/textarea.tsx +74 -48
  60. package/.framework/src/hooks/useEntityList.ts +12 -9
  61. package/.framework/src/hooks/useListSchema.ts +108 -58
  62. package/.framework/src/instructions/README.md +57 -0
  63. package/.framework/src/instructions/ai-agents.md +69 -0
  64. package/.framework/src/instructions/alerts.md +80 -0
  65. package/.framework/src/instructions/api-keys.md +87 -0
  66. package/.framework/src/instructions/apps.md +77 -0
  67. package/.framework/src/instructions/concepts/ai-and-prompts.md +150 -0
  68. package/.framework/src/instructions/concepts/apps-and-renderers.md +162 -0
  69. package/.framework/src/instructions/concepts/auth-and-api-keys.md +133 -0
  70. package/.framework/src/instructions/concepts/automation.md +186 -0
  71. package/.framework/src/instructions/concepts/concurrency-and-idempotency.md +125 -0
  72. package/.framework/src/instructions/concepts/core-vs-custom.md +124 -0
  73. package/.framework/src/instructions/concepts/design-schema.md +152 -0
  74. package/.framework/src/instructions/concepts/integrations-and-webhooks.md +127 -0
  75. package/.framework/src/instructions/concepts/observability.md +116 -0
  76. package/.framework/src/instructions/concepts/permissions.md +150 -0
  77. package/.framework/src/instructions/concepts/runtime-records.md +111 -0
  78. package/.framework/src/instructions/concepts/scope-and-accounts.md +112 -0
  79. package/.framework/src/instructions/concepts/spine-way.md +172 -0
  80. package/.framework/src/instructions/deliveries.md +59 -0
  81. package/.framework/src/instructions/guide/00-orientation.md +106 -0
  82. package/.framework/src/instructions/guide/01-install-and-first-run.md +253 -0
  83. package/.framework/src/instructions/guide/02-project-map.md +147 -0
  84. package/.framework/src/instructions/guide/03-domain-model.md +223 -0
  85. package/.framework/src/instructions/guide/04-first-app.md +227 -0
  86. package/.framework/src/instructions/guide/05-glossary.md +183 -0
  87. package/.framework/src/instructions/integrations.md +96 -0
  88. package/.framework/src/instructions/internal/cil-markers.md +83 -0
  89. package/.framework/src/instructions/invites.md +60 -0
  90. package/.framework/src/instructions/kb.md +80 -0
  91. package/.framework/src/instructions/logs.md +77 -0
  92. package/.framework/src/instructions/observability.md +61 -0
  93. package/.framework/src/instructions/operations/deployment.md +115 -0
  94. package/.framework/src/instructions/operations/migrations.md +125 -0
  95. package/.framework/src/instructions/operations/security-checklist.md +148 -0
  96. package/.framework/src/instructions/operations/troubleshooting.md +170 -0
  97. package/.framework/src/instructions/operations/upgrade.md +116 -0
  98. package/.framework/src/instructions/pipeline-executions.md +62 -0
  99. package/.framework/src/instructions/pipelines.md +78 -0
  100. package/.framework/src/instructions/prompts.md +95 -0
  101. package/.framework/src/instructions/reference/api/admin-data.md +162 -0
  102. package/.framework/src/instructions/reference/api/auth.md +113 -0
  103. package/.framework/src/instructions/reference/api/errors-and-envelopes.md +113 -0
  104. package/.framework/src/instructions/reference/app-manifest.md +150 -0
  105. package/.framework/src/instructions/reference/cli.md +124 -0
  106. package/.framework/src/instructions/reference/database.md +132 -0
  107. package/.framework/src/instructions/reference/design-schema.md +280 -0
  108. package/.framework/src/instructions/reference/env-vars.md +133 -0
  109. package/.framework/src/instructions/reference/functions/account-nodes.md +75 -0
  110. package/.framework/src/instructions/reference/functions/admin-data.md +195 -0
  111. package/.framework/src/instructions/reference/functions/admin-funnel.md +90 -0
  112. package/.framework/src/instructions/reference/functions/admin-install-funnel.md +107 -0
  113. package/.framework/src/instructions/reference/functions/admin-signals.md +102 -0
  114. package/.framework/src/instructions/reference/functions/ai-agents.md +148 -0
  115. package/.framework/src/instructions/reference/functions/ai-interactions.md +156 -0
  116. package/.framework/src/instructions/reference/functions/api-keys.md +130 -0
  117. package/.framework/src/instructions/reference/functions/apps.md +140 -0
  118. package/.framework/src/instructions/reference/functions/auth.md +99 -0
  119. package/.framework/src/instructions/reference/functions/debug-auth.md +91 -0
  120. package/.framework/src/instructions/reference/functions/deliveries.md +110 -0
  121. package/.framework/src/instructions/reference/functions/embeddings.md +166 -0
  122. package/.framework/src/instructions/reference/functions/eval-harness.md +149 -0
  123. package/.framework/src/instructions/reference/functions/index.md +103 -0
  124. package/.framework/src/instructions/reference/functions/integration-outbound.md +200 -0
  125. package/.framework/src/instructions/reference/functions/integration-routes.md +151 -0
  126. package/.framework/src/instructions/reference/functions/integrations.md +130 -0
  127. package/.framework/src/instructions/reference/functions/invites.md +182 -0
  128. package/.framework/src/instructions/reference/functions/item-progress.md +107 -0
  129. package/.framework/src/instructions/reference/functions/kb.md +166 -0
  130. package/.framework/src/instructions/reference/functions/logs.md +141 -0
  131. package/.framework/src/instructions/reference/functions/observability.md +105 -0
  132. package/.framework/src/instructions/reference/functions/pipeline-executions.md +132 -0
  133. package/.framework/src/instructions/reference/functions/pipeline-runner-background.md +121 -0
  134. package/.framework/src/instructions/reference/functions/pipelines.md +136 -0
  135. package/.framework/src/instructions/reference/functions/prompt-configs.md +121 -0
  136. package/.framework/src/instructions/reference/functions/roles.md +121 -0
  137. package/.framework/src/instructions/reference/functions/security.md +140 -0
  138. package/.framework/src/instructions/reference/functions/system-cron.md +136 -0
  139. package/.framework/src/instructions/reference/functions/system.md +106 -0
  140. package/.framework/src/instructions/reference/functions/tests.md +97 -0
  141. package/.framework/src/instructions/reference/functions/timers.md +117 -0
  142. package/.framework/src/instructions/reference/functions/trigger-scheduler.md +102 -0
  143. package/.framework/src/instructions/reference/functions/triggers.md +140 -0
  144. package/.framework/src/instructions/reference/functions/types.md +146 -0
  145. package/.framework/src/instructions/reference/seeds.md +126 -0
  146. package/.framework/src/instructions/reference/shared-modules.md +127 -0
  147. package/.framework/src/instructions/reference/spine-config.md +114 -0
  148. package/.framework/src/instructions/roles.md +80 -0
  149. package/.framework/src/instructions/runtime-detail.md +70 -0
  150. package/.framework/src/instructions/runtime-list.md +77 -0
  151. package/.framework/src/instructions/security.md +67 -0
  152. package/.framework/src/instructions/tasks/add-a-pipeline.md +110 -0
  153. package/.framework/src/instructions/tasks/add-a-role.md +96 -0
  154. package/.framework/src/instructions/tasks/add-a-timer.md +114 -0
  155. package/.framework/src/instructions/tasks/add-a-trigger.md +106 -0
  156. package/.framework/src/instructions/tasks/add-a-type.md +151 -0
  157. package/.framework/src/instructions/tasks/add-a-webhook.md +108 -0
  158. package/.framework/src/instructions/tasks/add-an-ai-agent.md +108 -0
  159. package/.framework/src/instructions/tasks/add-an-integration.md +124 -0
  160. package/.framework/src/instructions/tasks/build-a-custom-page.md +118 -0
  161. package/.framework/src/instructions/tasks/package-and-install-an-app.md +127 -0
  162. package/.framework/src/instructions/tasks/test-your-code.md +108 -0
  163. package/.framework/src/instructions/tasks/write-a-function.md +132 -0
  164. package/.framework/src/instructions/tasks/write-a-migration.md +110 -0
  165. package/.framework/src/instructions/testing.md +59 -0
  166. package/.framework/src/instructions/timers.md +82 -0
  167. package/.framework/src/instructions/triggers.md +69 -0
  168. package/.framework/src/instructions/types.md +93 -0
  169. package/.framework/src/pages/NotFoundPage.tsx +62 -31
  170. package/.framework/src/pages/admin/AIAgentDetailPage.tsx +117 -106
  171. package/.framework/src/pages/admin/AIAgentsPage.tsx +86 -48
  172. package/.framework/src/pages/admin/APIKeyDetailPage.tsx +153 -152
  173. package/.framework/src/pages/admin/APIKeysPage.tsx +91 -90
  174. package/.framework/src/pages/admin/AlertsConfigPage.tsx +29 -18
  175. package/.framework/src/pages/admin/AppDetailPage.tsx +6 -60
  176. package/.framework/src/pages/admin/AppsPage.tsx +104 -66
  177. package/.framework/src/pages/admin/DeliveriesPage.tsx +5 -5
  178. package/.framework/src/pages/admin/EmbeddingDetailPage.tsx +5 -23
  179. package/.framework/src/pages/admin/EmbeddingsPage.tsx +5 -26
  180. package/.framework/src/pages/admin/IntegrationDetailPage.tsx +7 -7
  181. package/.framework/src/pages/admin/IntegrationsPage.tsx +85 -43
  182. package/.framework/src/pages/admin/LogsPage.tsx +144 -76
  183. package/.framework/src/pages/admin/ObservabilityDashboard.tsx +223 -140
  184. package/.framework/src/pages/admin/PipelineDetailPage.tsx +134 -113
  185. package/.framework/src/pages/admin/PipelineExecutionsPage.tsx +108 -45
  186. package/.framework/src/pages/admin/PipelinesPage.tsx +160 -115
  187. package/.framework/src/pages/admin/PromptConfigDetailPage.tsx +96 -98
  188. package/.framework/src/pages/admin/PromptConfigsPage.tsx +101 -59
  189. package/.framework/src/pages/admin/RoleDetailPage.tsx +90 -79
  190. package/.framework/src/pages/admin/RolesPage.tsx +86 -43
  191. package/.framework/src/pages/admin/SecurityPage.tsx +1 -1
  192. package/.framework/src/pages/admin/TestingDashboard.tsx +16 -28
  193. package/.framework/src/pages/admin/TimerDetailPage.tsx +117 -100
  194. package/.framework/src/pages/admin/TimersPage.tsx +90 -62
  195. package/.framework/src/pages/admin/TriggerDetailPage.tsx +90 -83
  196. package/.framework/src/pages/admin/TriggersPage.tsx +124 -99
  197. package/.framework/src/pages/admin/TypeDetailPage.tsx +152 -138
  198. package/.framework/src/pages/admin/TypesPage.tsx +90 -48
  199. package/.framework/src/pages/admin/cil/CILAgentPage.tsx +17 -25
  200. package/.framework/src/pages/admin/cil/CILChunkDetailPage.tsx +17 -27
  201. package/.framework/src/pages/admin/cil/CILDashboardPage.tsx +72 -40
  202. package/.framework/src/pages/admin/cil/CILFileListPage.tsx +321 -129
  203. package/.framework/src/pages/admin/cil/CILFileSelectPage.tsx +18 -29
  204. package/.framework/src/pages/admin/cil/CILGraphPage.tsx +26 -38
  205. package/.framework/src/pages/admin/cil/CILIngestionPage.tsx +34 -46
  206. package/.framework/src/pages/admin/cil/CILProjectsPage.tsx +189 -103
  207. package/.framework/src/pages/admin/cil/CILSearchPage.tsx +246 -136
  208. package/.framework/src/pages/admin/cil/CILSuggestionsPage.tsx +11 -22
  209. package/.framework/src/pages/admin/cil/CILVersionsPage.tsx +9 -20
  210. package/.framework/src/pages/admin/cil/FlexiblePipelinePage.tsx +26 -38
  211. package/.framework/src/pages/admin/kb/KBAdminPage.tsx +7 -26
  212. package/.framework/templates/agent/AGENTS.md +150 -0
  213. package/.framework/templates/agent/skills/spine-add-ai-agent/SKILL.md +58 -0
  214. package/.framework/templates/agent/skills/spine-add-automation/SKILL.md +62 -0
  215. package/.framework/templates/agent/skills/spine-add-integration/SKILL.md +63 -0
  216. package/.framework/templates/agent/skills/spine-architect/SKILL.md +86 -0
  217. package/.framework/templates/agent/skills/spine-install-app/SKILL.md +72 -0
  218. package/.framework/templates/agent/skills/spine-migration/SKILL.md +75 -0
  219. package/.framework/templates/agent/skills/spine-new-app/SKILL.md +67 -0
  220. package/.framework/templates/agent/skills/spine-new-function/SKILL.md +65 -0
  221. package/.framework/templates/agent/skills/spine-new-type/SKILL.md +65 -0
  222. package/.framework/templates/agent/skills/spine-schema/SKILL.md +77 -0
  223. package/.framework/templates/agent/skills/spine-test/SKILL.md +67 -0
  224. package/.framework/templates/agent/skills/spine-troubleshoot/SKILL.md +74 -0
  225. package/.framework/templates/agent/skills/spine-upgrade/SKILL.md +69 -0
  226. package/.framework/templates/project.json +4 -1
  227. package/.framework/tests/unit/account-scoping-gates.test.ts +392 -0
  228. package/.framework/tests/unit/agent-files.test.ts +355 -0
  229. package/.framework/tests/unit/agent-runner.test.ts +479 -44
  230. package/.framework/tests/unit/api-keys-create-scope-gate.test.ts +160 -0
  231. package/.framework/tests/unit/api-keys-omit-secret-fields.test.ts +38 -0
  232. package/.framework/tests/unit/bootstrap.test.ts +242 -0
  233. package/.framework/tests/unit/cli-context-api-key.test.ts +114 -0
  234. package/.framework/tests/unit/debug-auth.test.ts +38 -0
  235. package/.framework/tests/unit/deliveries-account-scoping.test.ts +185 -0
  236. package/.framework/tests/unit/integration-outbound-credentials.test.ts +167 -0
  237. package/.framework/tests/unit/integrations-audit-redaction.test.ts +130 -0
  238. package/.framework/tests/unit/logging-app-id.test.ts +75 -0
  239. package/.framework/tests/unit/system-context-denial.test.ts +145 -0
  240. package/.framework/tests/unit/system-cron.test.ts +240 -0
  241. package/.framework/tests/unit/timers.test.ts +159 -0
  242. package/README.md +125 -166
  243. package/config/tsconfig.cli.json +2 -2
  244. package/package.json +15 -4
  245. package/templates/project/package-lock.json +2 -2
  246. package/.framework/docs/admin-routes.md +0 -76
  247. package/.framework/docs/api-docs-progress.md +0 -38
  248. package/.framework/docs/api-governance.md +0 -146
  249. package/.framework/docs/api-testing-results.md +0 -212
  250. package/.framework/docs/assembly-launch-guide.md +0 -138
  251. package/.framework/docs/audit-results.md +0 -590
  252. package/.framework/docs/db-api-inventory.md +0 -95
  253. package/.framework/docs/gap-remediation-backlog.md +0 -103
  254. package/.framework/docs/ui-adoption-verification.md +0 -111
  255. package/.framework/docs/ui-api-coverage.md +0 -84
  256. package/.framework/docs/v2-compatibility-audit.md +0 -228
  257. package/.framework/mcp/index.ts +0 -133
  258. package/.framework/mcp/load-env.ts +0 -60
  259. package/.framework/mcp/shared/app-manifest.ts +0 -275
  260. package/.framework/mcp/shared/db.ts +0 -477
  261. package/.framework/mcp/shared/kb.ts +0 -118
  262. package/.framework/mcp/tools/architect.ts +0 -431
  263. package/.framework/mcp/tools/cil/context.ts +0 -345
  264. package/.framework/mcp/tools/cil/graph.ts +0 -242
  265. package/.framework/mcp/tools/cil/ingest.ts +0 -1217
  266. package/.framework/mcp/tools/cil/pipeline-orchestrator.ts +0 -693
  267. package/.framework/mcp/tools/cil/pipeline.ts +0 -767
  268. package/.framework/mcp/tools/cil/project.ts +0 -791
  269. package/.framework/mcp/tools/cil/retrieval.ts +0 -336
  270. package/.framework/mcp/tools/cil/search-core.ts +0 -454
  271. package/.framework/mcp/tools/cil/search.ts +0 -97
  272. package/.framework/mcp/tools/cil/suggest.ts +0 -186
  273. package/.framework/mcp/tools/cil/validate.ts +0 -1369
  274. package/.framework/mcp/tools/kb/delete.ts +0 -139
  275. package/.framework/mcp/tools/kb/index.ts +0 -52
  276. package/.framework/mcp/tools/kb/ingest.ts +0 -84
  277. package/.framework/mcp/tools/kb/list-types.ts +0 -102
  278. package/.framework/mcp/tools/kb/publish.ts +0 -100
  279. package/.framework/mcp/tools/kb/reindex.ts +0 -86
  280. package/.framework/mcp/tools/kb/revoke.ts +0 -85
  281. package/.framework/mcp/tools/kb/search.ts +0 -101
  282. package/.framework/mcp/tools/kb/upsert.ts +0 -125
  283. package/.framework/mcp/tools/observability.ts +0 -510
@@ -1,73 +1,116 @@
1
1
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:module_header:module_header" type="module_header" identity="module_header" parent="~/.framework/functions/_shared/logging.ts"]
2
- // CIL[DOC-MACRO purpose="Shared logging utilities for admin-data operations and request context"]
3
- // CIL[DOC-RESPONSIBILITY responsibility="Provide logging helpers, log levels and structured log payloads used by admin-data handlers"]
4
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
5
- // CIL[DOC-CONTRACT inputs="none" outputs="module exports" errors="none" side_effects="none"]
6
- // CIL[DOC-MICRO logic_summary="Imports CoreContext, adminDb and formatPrincipalForAudit; defines LogLevel, LogContext, AdminDataLogPayload and helpers for structured admin-data logging" notable_decisions="[]"]
7
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
8
- // CIL[DOC-STABILITY stable]
9
- // CIL[DOC-AUDIENCE audience="framework-developers, admin-data consumers"]
2
+ /**
3
+ * @module logging
4
+ * @audience both
5
+ * @layer shared-core
6
+ * @stability stable
7
+ *
8
+ * This module provides logging functionality that is shared across the application, facilitating consistent logging practices. It integrates with core middleware and database components to ensure that logs are formatted and stored appropriately.
9
+ * INVARIANT: All logs must include relevant context for auditing purposes.
10
+ *
11
+ * @seeAlso middleware.ts (provides core context for logging)
12
+ * @seeAlso db.ts (handles database interactions for log storage)
13
+ * @seeAlso principal.ts (formats principal information for audit logs)
14
+ *
15
+ * @cil-generated
16
+ */
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
10
26
 
11
27
  import { CoreContext } from './middleware'
12
28
  import { adminDb } from './db'
13
29
  import { formatPrincipalForAudit } from './principal'
14
- // CIL[DOC-VECTOR type="context" content="purpose='Shared logging utilities for admin-data operations and request context'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
15
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
16
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
17
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
18
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
19
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
20
30
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:module_header:module_header"]
21
31
 
22
32
 
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
23
48
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:LogLevel:type" type="type" identity="LogLevel" parent="~/.framework/functions/_shared/logging.ts"]
24
- // CIL[DOC-MACRO purpose="Define the set of logging levels used across the framework"]
25
- // CIL[DOC-RESPONSIBILITY responsibility="Type the union of supported logging levels"]
26
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
27
- // CIL[DOC-CONTRACT inputs="none" outputs="LogLevel union type" errors="none" side_effects="none"]
28
- // CIL[DOC-MICRO logic_summary="String-literal union of 'off', 'timing', 'warnings', 'errors' and 'all'" notable_decisions="[]"]
29
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
30
- // CIL[DOC-STABILITY internal]
49
+ /**
50
+ * LogLevel defines a set of string constants representing different logging levels to standardize logging behavior across the application.
51
+ *
52
+ * @sideEffects none
53
+ * @stability internal
54
+ * @cil-generated
55
+ */
31
56
  export type LogLevel = 'off' | 'timing' | 'warnings' | 'errors' | 'all'
32
- // CIL[DOC-VECTOR type="context" content="purpose='Define the set of logging levels used across the framework'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
33
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
34
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
35
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
36
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
37
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
38
57
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:LogLevel:type"]
39
58
 
40
59
 
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
41
75
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:LogContext:interface" type="interface" identity="LogContext" parent="~/.framework/functions/_shared/logging.ts"]
42
- // CIL[DOC-MACRO purpose="Extend the core request context with logging-specific fields"]
43
- // CIL[DOC-RESPONSIBILITY responsibility="Declare optional logging fields attached to a request context"]
44
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
45
- // CIL[DOC-CONTRACT inputs="none" outputs="LogContext interface" errors="none" side_effects="none"]
46
- // CIL[DOC-MICRO logic_summary="Adds appId, source and logLevel properties to CoreContext" notable_decisions="[]"]
47
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
48
- // CIL[DOC-STABILITY internal]
76
+ /**
77
+ * The LogContext interface defines the structure for logging context information within the application, allowing for optional properties that provide additional context for log entries. This enhances the clarity and usefulness of logs by including details like application ID and log level.
78
+ *
79
+ * @sideEffects none
80
+ * @stability internal
81
+ * @cil-generated
82
+ */
49
83
  export interface LogContext extends CoreContext {
50
84
  appId?: string | null
51
85
  source?: string
52
86
  logLevel?: string
53
87
  }
54
- // CIL[DOC-VECTOR type="context" content="purpose='Extend the core request context with logging-specific fields'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
55
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
56
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
57
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
58
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
59
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
60
88
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:LogContext:interface"]
61
89
 
62
90
 
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
63
106
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:AdminDataLogPayload:interface" type="interface" identity="AdminDataLogPayload" parent="~/.framework/functions/_shared/logging.ts"]
64
- // CIL[DOC-MACRO purpose="Define the payload shape for admin-data operation logs"]
65
- // CIL[DOC-RESPONSIBILITY responsibility="Declare all fields logged for an admin-data operation"]
66
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
67
- // CIL[DOC-CONTRACT inputs="none" outputs="AdminDataLogPayload interface" errors="none" side_effects="none"]
68
- // CIL[DOC-MICRO logic_summary="Records entity, action, method, duration, recordId, rowCount, filters, typeSlug, error and warning" notable_decisions="[]"]
69
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
70
- // CIL[DOC-STABILITY internal]
107
+ /**
108
+ * The AdminDataLogPayload interface defines the structure for logging administrative actions within the application. It captures essential details about the entity being acted upon, the action taken, and any relevant metadata.
109
+ *
110
+ * @sideEffects none
111
+ * @stability internal
112
+ * @cil-generated
113
+ */
71
114
  export interface AdminDataLogPayload {
72
115
  entity: string
73
116
  action: string
@@ -80,55 +123,97 @@ export interface AdminDataLogPayload {
80
123
  error?: any
81
124
  warning?: string
82
125
  }
83
- // CIL[DOC-VECTOR type="context" content="purpose='Define the payload shape for admin-data operation logs'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
84
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
85
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
86
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
87
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
88
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
89
126
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:AdminDataLogPayload:interface"]
90
127
 
91
128
 
92
129
 
93
130
 
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
94
146
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:VALID_LEVELS:constant" type="constant" identity="VALID_LEVELS" parent="~/.framework/functions/_shared/logging.ts"]
95
- // CIL[DOC-MACRO purpose="List the valid log levels in priority order"]
96
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the array of supported LogLevel values"]
97
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
98
- // CIL[DOC-CONTRACT inputs="none" outputs="LogLevel[] constant" errors="none" side_effects="none"]
99
- // CIL[DOC-MICRO logic_summary="Array of all LogLevel string literals for filtering and validation" notable_decisions="[]"]
100
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
101
- // CIL[DOC-STABILITY internal]
147
+ /**
148
+ * VALID_LEVELS defines the acceptable logging levels for the application to provide a standardized set of log levels used throughout the logging system.
149
+ *
150
+ * @sideEffects none
151
+ * @stability internal
152
+ * @cil-generated
153
+ */
102
154
  const VALID_LEVELS: LogLevel[] = ['off', 'timing', 'warnings', 'errors', 'all']
155
+ // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:VALID_LEVELS:constant"]
103
156
 
104
157
  // Module-level cache of the `system_settings` rows for key='logging'. The
105
158
  // per-ctx cache in resolveLogLevels only dedupes within one request; polling
106
159
  // clients re-issue this query on every request otherwise.
160
+
107
161
  let loggingSettingsCache: { rows: any[]; expiresAt: number } | null = null
162
+
163
+ // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:LOGGING_SETTINGS_TTL_MS:constant" type="constant" identity="LOGGING_SETTINGS_TTL_MS" parent="~/.framework/functions/_shared/logging.ts"]
164
+ /**
165
+ * LOGGING_SETTINGS_TTL_MS defines the time-to-live for logging settings in milliseconds to ensure that module-level caches persist for a specified duration between test cases.
166
+ *
167
+ * @sideEffects none
168
+ * @stability internal
169
+ * @cil-generated
170
+ */
108
171
  const LOGGING_SETTINGS_TTL_MS = 60_000
172
+ // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:LOGGING_SETTINGS_TTL_MS:constant"]
109
173
 
110
174
  // Test hook — module-level caches survive between cases in one process.
175
+ // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:__resetLoggingSettingsCache:component" type="component" identity="__resetLoggingSettingsCache" parent="~/.framework/functions/_shared/logging.ts"]
176
+ /**
177
+ * __resetLoggingSettingsCache resets the logging settings cache to null to clear any cached logging settings, ensuring that fresh settings are retrieved when needed.
178
+ *
179
+ * @outputSpec void
180
+ * @sideEffects sets loggingSettingsCache to null
181
+ * @stability internal
182
+ * @cil-generated
183
+ */
111
184
  export function __resetLoggingSettingsCache() {
112
185
  loggingSettingsCache = null
113
186
  }
114
- // CIL[DOC-VECTOR type="context" content="purpose='List the valid log levels in priority order'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
115
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
116
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
117
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
118
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
119
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
120
- // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:VALID_LEVELS:constant"]
187
+ // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:__resetLoggingSettingsCache:component"]
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
121
203
 
122
204
 
123
205
 
124
206
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:parseLogLevelHeader:function" type="function" identity="parseLogLevelHeader" parent="~/.framework/functions/_shared/logging.ts"]
125
- // CIL[DOC-MACRO purpose="Parse a comma or pipe delimited log level header into a list"]
126
- // CIL[DOC-RESPONSIBILITY responsibility="Convert a raw header string into validated LogLevel values"]
127
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
128
- // CIL[DOC-CONTRACT inputs="value: string | undefined" outputs="LogLevel[]" errors="none" side_effects="none"]
129
- // CIL[DOC-MICRO logic_summary="Splits on commas or pipes, trims and filters to VALID_LEVELS; falls back to a single trimmed value" notable_decisions="[]"]
130
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
131
- // CIL[DOC-STABILITY internal]
207
+ /**
208
+ * Parses a log level header string into an array of valid log levels, ensuring only recognized levels are returned. This function handles both single and multiple log levels.
209
+ *
210
+ * @inputSpec
211
+ * - value: string | undefined (optional) — the log level header string to parse.
212
+ * @outputSpec LogLevel[] — an array of valid log levels.
213
+ * @sideEffects none
214
+ * @stability internal
215
+ * @cil-generated
216
+ */
132
217
  function parseLogLevelHeader(value: string | undefined): LogLevel[] {
133
218
  if (!value) return []
134
219
  const parts = value.split(/[,|]/).map(p => p.trim()).filter(Boolean)
@@ -141,66 +226,104 @@ function parseLogLevelHeader(value: string | undefined): LogLevel[] {
141
226
  const levels = parts.filter(p => VALID_LEVELS.includes(p as LogLevel)) as LogLevel[]
142
227
  return levels
143
228
  }
144
- // CIL[DOC-VECTOR type="context" content="purpose='Parse a comma or pipe delimited log level header into a list'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
145
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
146
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
147
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
148
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
149
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
150
229
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:parseLogLevelHeader:function"]
151
230
 
152
231
 
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
153
247
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:getCache:function" type="function" identity="getCache" parent="~/.framework/functions/_shared/logging.ts"]
154
- // CIL[DOC-MACRO purpose="Retrieve the per-context logging cache if it exists"]
155
- // CIL[DOC-RESPONSIBILITY responsibility="Return the logging cache from a LogContext"]
156
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
157
- // CIL[DOC-CONTRACT inputs="ctx: LogContext" outputs="Map<string, any> | undefined" errors="none" side_effects="none"]
158
- // CIL[DOC-MICRO logic_summary="Accesses (ctx as any).__loggingCache" notable_decisions="[]"]
159
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
160
- // CIL[DOC-STABILITY internal]
248
+ /**
249
+ * Retrieves the logging cache from the provided log context if it exists. This function is useful for accessing cached logging data associated with a specific context.
250
+ *
251
+ * @inputSpec
252
+ * - ctx: LogContext (required) — the logging context from which to retrieve the cache.
253
+ * @outputSpec Map<string, any> | undefined — returns the logging cache map or undefined if it does not exist.
254
+ * @sideEffects none
255
+ * @stability internal
256
+ * @cil-generated
257
+ */
161
258
  function getCache(ctx: LogContext): Map<string, any> | undefined {
162
259
  return (ctx as any).__loggingCache
163
260
  }
164
- // CIL[DOC-VECTOR type="context" content="purpose='Retrieve the per-context logging cache if it exists'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
165
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
166
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
167
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
168
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
169
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
170
261
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:getCache:function"]
171
262
 
172
263
 
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
173
279
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:getOrCreateCache:function" type="function" identity="getOrCreateCache" parent="~/.framework/functions/_shared/logging.ts"]
174
- // CIL[DOC-MACRO purpose="Return a per-context logging cache, creating one if needed"]
175
- // CIL[DOC-RESPONSIBILITY responsibility="Ensure a LogContext has an attached logging cache"]
176
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
177
- // CIL[DOC-CONTRACT inputs="ctx: LogContext" outputs="Map<string, any>" errors="none" side_effects="Mutates ctx.__loggingCache when missing"]
178
- // CIL[DOC-MICRO logic_summary="Checks for an existing cache and initializes a new Map if absent" notable_decisions="[]"]
179
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
180
- // CIL[DOC-STABILITY internal]
280
+ /**
281
+ * This function retrieves an existing logging cache from the provided context or creates a new one if it doesn't exist. It ensures that logging operations can efficiently store and retrieve log-related data.
282
+ *
283
+ * @inputSpec
284
+ * ctx: LogContext (required) — the logging context that may contain a cache.
285
+ * @outputSpec Map<string, any> — a Map object representing the logging cache.
286
+ * @sideEffects none
287
+ * @stability internal
288
+ * @cil-generated
289
+ */
181
290
  function getOrCreateCache(ctx: LogContext): Map<string, any> {
182
291
  if (!(ctx as any).__loggingCache) {
183
292
  ;(ctx as any).__loggingCache = new Map()
184
293
  }
185
294
  return (ctx as any).__loggingCache
186
295
  }
187
- // CIL[DOC-VECTOR type="context" content="purpose='Return a per-context logging cache, creating one if needed'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
188
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
189
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
190
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
191
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
192
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
193
296
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:getOrCreateCache:function"]
194
297
 
195
298
 
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+
196
314
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:findSetting:function" type="function" identity="findSetting" parent="~/.framework/functions/_shared/logging.ts"]
197
- // CIL[DOC-MACRO purpose="Find the log levels configured for a given scope and optional scopeId"]
198
- // CIL[DOC-RESPONSIBILITY responsibility="Search system_settings rows for a matching logging configuration"]
199
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
200
- // CIL[DOC-CONTRACT inputs="rows: any[], scope: string, scopeId?: string | null" outputs="LogLevel[] | undefined" errors="none" side_effects="none"]
201
- // CIL[DOC-MICRO logic_summary="Uses Array.find with a predicate comparing scope and scope_id, then returns row.value.levels" notable_decisions="[]"]
202
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
203
- // CIL[DOC-STABILITY internal]
315
+ /**
316
+ * Retrieves logging levels associated with a specific scope and optional scope ID from a list of rows. This function is used to configure logging settings based on the provided parameters.
317
+ *
318
+ * @inputSpec
319
+ * rows: any[] (required) — an array of row objects containing logging settings.
320
+ * scope: string (required) — the scope to filter the rows by.
321
+ * scopeId: string | null (optional) — an optional identifier to further filter the rows.
322
+ * @outputSpec LogLevel[] | undefined — an array of logging levels or undefined if no matching row is found.
323
+ * @sideEffects none
324
+ * @stability internal
325
+ * @cil-generated
326
+ */
204
327
  function findSetting(
205
328
  rows: any[],
206
329
  scope: string,
@@ -211,23 +334,39 @@ function findSetting(
211
334
  )
212
335
  return row?.value?.levels as LogLevel[] | undefined
213
336
  }
214
- // CIL[DOC-VECTOR type="context" content="purpose='Find the log levels configured for a given scope and optional scopeId'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
215
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
216
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
217
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
218
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
219
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
220
337
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:findSetting:function"]
221
338
 
222
339
 
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+
223
355
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:resolveLogLevels:function" type="function" identity="resolveLogLevels" parent="~/.framework/functions/_shared/logging.ts"]
224
- // CIL[DOC-MACRO purpose="Resolve the effective log levels for a request and optional entity/action"]
225
- // CIL[DOC-RESPONSIBILITY responsibility="Combine cache, system settings and request context to determine active log levels"]
226
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
227
- // CIL[DOC-CONTRACT inputs="ctx: LogContext, options?: { entity?: string; action?: string }" outputs="Promise<LogLevel[]>" errors="none" side_effects="Reads system_settings via adminDb, cached module-level with a short TTL"]
228
- // CIL[DOC-MICRO logic_summary="Checks module-level settings cache, fetches system_settings on miss, applies header override, then overlays global/source/principal/account/app/tool scopes" notable_decisions="settings rows are shared across requests so the hot admin-data path doesn't re-read them per call; tests reset the cache via the exported reset hook"]
229
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
230
- // CIL[DOC-STABILITY internal]
356
+ /**
357
+ * Resolves logging levels based on the provided context and options, caching results for efficiency. It retrieves settings from a database if not already cached.
358
+ *
359
+ * @macro Async function that determines log levels for a given context and options.
360
+ * @micro Uses a caching mechanism to store and retrieve log levels, querying a database when necessary.
361
+ * @inputSpec
362
+ * ctx: LogContext (required) — the logging context containing relevant information.
363
+ * options: { entity?: string; action?: string } (optional) — optional parameters to specify the entity and action for logging.
364
+ * @outputSpec Promise<LogLevel[]> — an array of resolved log levels.
365
+ * @sideEffects Database query to 'system_settings' if cache is expired or empty.
366
+ * @stability internal
367
+ * @calls getOrCreateCache, adminDb.from('system_settings'), findSetting, parseLogLevelHeader
368
+ * @cil-generated
369
+ */
231
370
  export async function resolveLogLevels(
232
371
  ctx: LogContext,
233
372
  options?: { entity?: string; action?: string }
@@ -294,23 +433,133 @@ export async function resolveLogLevels(
294
433
  cache.set(cacheKey, levels)
295
434
  return levels
296
435
  }
297
- // CIL[DOC-VECTOR type="context" content="purpose='Resolve the effective log levels for a request and optional entity/action'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
298
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
299
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
300
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
301
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
302
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
303
436
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:resolveLogLevels:function"]
304
437
 
305
438
 
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+ // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:APP_UUID_TTL_MS:constant" type="constant" identity="APP_UUID_TTL_MS" parent="~/.framework/functions/_shared/logging.ts"]
454
+ /**
455
+ * APP_UUID_TTL_MS defines the time-to-live duration for application UUIDs in milliseconds. This constant helps manage the lifecycle of UUIDs within the application.
456
+ *
457
+ * @sideEffects none
458
+ * @stability internal
459
+ * @cil-generated
460
+ */
461
+ const APP_UUID_TTL_MS = 5 * 60_000
462
+ // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:APP_UUID_TTL_MS:constant"]
463
+ // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:appUuidCache:constant" type="constant" identity="appUuidCache" parent="~/.framework/functions/_shared/logging.ts"]
464
+ /**
465
+ * The appUuidCache stores mappings of application UUIDs to their corresponding metadata, allowing for efficient retrieval of this information. It exists to optimize the management of UUIDs and their associated data within the application.
466
+ *
467
+ * @sideEffects none
468
+ * @stability internal
469
+ * @cil-generated
470
+ */
471
+ const appUuidCache = new Map<string, { id: string | null; at: number }>()
472
+ // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:appUuidCache:constant"]
473
+ // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:UUID_PATTERN:constant" type="constant" identity="UUID_PATTERN" parent="~/.framework/functions/_shared/logging.ts"]
474
+ /**
475
+ * UUID_PATTERN is a regular expression that validates the format of UUIDs to ensure consistency and correctness in logging. It is essential for maintaining the integrity of UUIDs used within the application.
476
+ *
477
+ * @sideEffects none
478
+ * @stability internal
479
+ * @cil-generated
480
+ */
481
+ const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
482
+ // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:UUID_PATTERN:constant"]
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+ // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:resolveAppUuid:function" type="function" identity="resolveAppUuid" parent="~/.framework/functions/_shared/logging.ts"]
500
+ /**
501
+ * Resolves the application UUID based on a given reference string by checking a cache and querying a database if necessary. This function is essential for retrieving application identifiers in a consistent manner.
502
+ *
503
+ * @macro Async function that resolves application UUIDs from references.
504
+ * @micro Utilizes a caching mechanism and database query to retrieve the UUID efficiently.
505
+ * @inputSpec
506
+ * - ref: string | null | undefined — The reference string used to look up the application UUID.
507
+ * @outputSpec Promise<string | null> — Returns the application UUID or null if not found.
508
+ * @sideEffects Writes to appUuidCache and queries the adminDb database.
509
+ * @stability internal
510
+ * @calls adminDb.from('apps')
511
+ * @errorHandling returns null on database query error.
512
+ * @cil-generated
513
+ */
514
+ export async function resolveAppUuid(ref: string | null | undefined): Promise<string | null> {
515
+ if (!ref) return null
516
+ if (UUID_PATTERN.test(ref)) return ref
517
+ const hit = appUuidCache.get(ref)
518
+ if (hit && Date.now() - hit.at < APP_UUID_TTL_MS) return hit.id
519
+ try {
520
+ const { data, error } = await adminDb
521
+ .from('apps')
522
+ .select('id')
523
+ .eq('slug', ref)
524
+ .maybeSingle()
525
+ if (error) return null
526
+ const id = data?.id ?? null
527
+ appUuidCache.set(ref, { id, at: Date.now() })
528
+ return id
529
+ } catch {
530
+ return null
531
+ }
532
+ }
533
+ // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:resolveAppUuid:function"]
534
+
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
548
+
549
+
306
550
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:buildMessage:function" type="function" identity="buildMessage" parent="~/.framework/functions/_shared/logging.ts"]
307
- // CIL[DOC-MACRO purpose="Build a human-readable log message from an admin-data payload"]
308
- // CIL[DOC-RESPONSIBILITY responsibility="Format a concise message string describing the operation"]
309
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
310
- // CIL[DOC-CONTRACT inputs="payload: AdminDataLogPayload" outputs="string" errors="none" side_effects="none"]
311
- // CIL[DOC-MICRO logic_summary="Concatenates action, entity, method, recordId, duration, warning and error details" notable_decisions="[]"]
312
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
313
- // CIL[DOC-STABILITY internal]
551
+ /**
552
+ * Builds a log message string based on the provided payload containing administrative data log details. This function is used for generating consistent log messages for various administrative actions.
553
+ *
554
+ * @macro Log message builder for administrative actions.
555
+ * @micro Constructs a message string by conditionally appending details from the payload.
556
+ * @inputSpec
557
+ * payload: AdminDataLogPayload (required) — object containing details for the log message.
558
+ * @outputSpec string — formatted log message.
559
+ * @sideEffects none
560
+ * @stability internal
561
+ * @cil-generated
562
+ */
314
563
  function buildMessage(payload: AdminDataLogPayload): string {
315
564
  const { entity, action, method, durationMs, recordId, error, warning } = payload
316
565
  let msg = `admin-data ${action} ${entity}`
@@ -321,23 +570,37 @@ function buildMessage(payload: AdminDataLogPayload): string {
321
570
  if (error) msg += ` failed: ${error.message || String(error)}`
322
571
  return msg
323
572
  }
324
- // CIL[DOC-VECTOR type="context" content="purpose='Build a human-readable log message from an admin-data payload'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
325
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
326
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
327
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
328
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
329
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
330
573
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:buildMessage:function"]
331
574
 
332
575
 
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+
584
+
585
+
586
+
587
+
588
+
589
+
590
+
333
591
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:buildContext:function" type="function" identity="buildContext" parent="~/.framework/functions/_shared/logging.ts"]
334
- // CIL[DOC-MACRO purpose="Build the structured context object for an admin-data log"]
335
- // CIL[DOC-RESPONSIBILITY responsibility="Convert payload fields into a flat context record for storage"]
336
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
337
- // CIL[DOC-CONTRACT inputs="payload: AdminDataLogPayload" outputs="Record<string, any>" errors="none" side_effects="none"]
338
- // CIL[DOC-MICRO logic_summary="Maps duration, method, rowCount, filters, typeSlug, warning and error message into snake_case keys" notable_decisions="[]"]
339
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
340
- // CIL[DOC-STABILITY internal]
592
+ /**
593
+ * The buildContext function constructs a context object from the provided AdminDataLogPayload, extracting relevant properties for logging purposes. It ensures that only defined and relevant fields are included in the resulting context.
594
+ *
595
+ * @macro Context builder for logging structured data.
596
+ * @micro Conditionally adds properties to the context object based on the presence of corresponding fields in the payload.
597
+ * @inputSpec
598
+ * payload: AdminDataLogPayload (required) — the payload containing data for logging.
599
+ * @outputSpec Record<string, any> — an object containing the extracted context properties.
600
+ * @sideEffects none
601
+ * @stability internal
602
+ * @cil-generated
603
+ */
341
604
  function buildContext(payload: AdminDataLogPayload): Record<string, any> {
342
605
  const ctx: Record<string, any> = {}
343
606
  if (payload.durationMs !== undefined) ctx.duration_ms = payload.durationMs
@@ -349,23 +612,35 @@ function buildContext(payload: AdminDataLogPayload): Record<string, any> {
349
612
  if (payload.error) ctx.error_message = payload.error.message || String(payload.error)
350
613
  return ctx
351
614
  }
352
- // CIL[DOC-VECTOR type="context" content="purpose='Build the structured context object for an admin-data log'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
353
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
354
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
355
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
356
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
357
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
358
615
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:buildContext:function"]
359
616
 
360
617
 
618
+
619
+
620
+
621
+
622
+
623
+
624
+
625
+
626
+
627
+
628
+
629
+
630
+
631
+
632
+
361
633
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:traceLogFields:function" type="function" identity="traceLogFields" parent="~/.framework/functions/_shared/logging.ts"]
362
- // CIL[DOC-MACRO purpose="Extract OpenTelemetry trace fields from the request context"]
363
- // CIL[DOC-RESPONSIBILITY responsibility="Return trace metadata for a log row"]
364
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
365
- // CIL[DOC-CONTRACT inputs="ctx: LogContext" outputs="Record<string, any>" errors="none" side_effects="none"]
366
- // CIL[DOC-MICRO logic_summary="Reads ctx.trace and maps traceId, spanId, parentSpanId, traceFlags, traceState and sampled" notable_decisions="[]"]
367
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
368
- // CIL[DOC-STABILITY internal]
634
+ /**
635
+ * The function extracts trace-related fields from a logging context if available, providing structured trace information for logging purposes. This enhances the logging capabilities by including relevant trace data.
636
+ *
637
+ * @inputSpec
638
+ * ctx: LogContext (required) — the logging context containing trace information.
639
+ * @outputSpec Record<string, any> — an object containing trace fields or an empty object if no trace is present.
640
+ * @sideEffects none
641
+ * @stability internal
642
+ * @cil-generated
643
+ */
369
644
  function traceLogFields(ctx: LogContext): Record<string, any> {
370
645
  const trace = ctx.trace
371
646
  if (!trace) return {}
@@ -378,23 +653,39 @@ function traceLogFields(ctx: LogContext): Record<string, any> {
378
653
  sampled: trace.sampled
379
654
  }
380
655
  }
381
- // CIL[DOC-VECTOR type="context" content="purpose='Extract OpenTelemetry trace fields from the request context'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
382
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
383
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
384
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
385
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
386
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
387
656
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:traceLogFields:function"]
388
657
 
389
658
 
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
390
674
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:buildMetadata:function" type="function" identity="buildMetadata" parent="~/.framework/functions/_shared/logging.ts"]
391
- // CIL[DOC-MACRO purpose="Build the metadata object for an admin-data log row"]
392
- // CIL[DOC-RESPONSIBILITY responsibility="Combine request, principal and trace metadata into a log record"]
393
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
394
- // CIL[DOC-CONTRACT inputs="ctx: LogContext, payload: AdminDataLogPayload" outputs="Record<string, any>" errors="none" side_effects="none"]
395
- // CIL[DOC-MICRO logic_summary="Merges request_id, source, entity, action, formatted principal and trace fields, with optional record_id and truncated stack" notable_decisions="[]"]
396
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
397
- // CIL[DOC-STABILITY internal]
675
+ /**
676
+ * The buildMetadata function constructs a metadata object for logging purposes, aggregating information from the log context and payload. It facilitates the logging of administrative actions with relevant details.
677
+ *
678
+ * @macro Function that generates a structured metadata object for logging.
679
+ * @micro Utilizes properties from the log context and payload, conditionally adding fields based on the presence of specific data.
680
+ * @inputSpec
681
+ * - ctx: LogContext (required) — context containing request and principal information.
682
+ * - payload: AdminDataLogPayload (required) — data payload containing entity and action details.
683
+ * @outputSpec Record<string, any> — an object containing structured metadata for logging.
684
+ * @sideEffects none
685
+ * @stability internal
686
+ * @calls formatPrincipalForAudit, traceLogFields
687
+ * @cil-generated
688
+ */
398
689
  function buildMetadata(
399
690
  ctx: LogContext,
400
691
  payload: AdminDataLogPayload
@@ -413,23 +704,35 @@ function buildMetadata(
413
704
  }
414
705
  return meta
415
706
  }
416
- // CIL[DOC-VECTOR type="context" content="purpose='Build the metadata object for an admin-data log row'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
417
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
418
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
419
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
420
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
421
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
422
707
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:buildMetadata:function"]
423
708
 
424
709
 
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
425
725
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:extractLogResult:function" type="function" identity="extractLogResult" parent="~/.framework/functions/_shared/logging.ts"]
426
- // CIL[DOC-MACRO purpose="Extract recordId and rowCount from an admin-data operation result"]
427
- // CIL[DOC-RESPONSIBILITY responsibility="Normalize an admin-data result into log-relevant identifiers and counts"]
428
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
429
- // CIL[DOC-CONTRACT inputs="result: any" outputs="{ recordId?: string; rowCount?: number }" errors="none" side_effects="none"]
430
- // CIL[DOC-MICRO logic_summary="Handles arrays, single records, result.data arrays/objects and result.count, preferring the first id when available" notable_decisions="[]"]
431
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
432
- // CIL[DOC-STABILITY internal]
726
+ /**
727
+ * Extracts relevant log result information from a given input object, returning either a record ID or row count. This function helps standardize the output format for logging purposes.
728
+ *
729
+ * @inputSpec
730
+ * result: any (required) — the input object from which to extract log information.
731
+ * @outputSpec { recordId?: string; rowCount?: number } — an object containing either a record ID or a row count based on the input.
732
+ * @sideEffects none
733
+ * @stability internal
734
+ * @cil-generated
735
+ */
433
736
  function extractLogResult(result: any): { recordId?: string; rowCount?: number } {
434
737
  if (!result || typeof result !== 'object') return {}
435
738
 
@@ -459,23 +762,40 @@ function extractLogResult(result: any): { recordId?: string; rowCount?: number }
459
762
 
460
763
  return {}
461
764
  }
462
- // CIL[DOC-VECTOR type="context" content="purpose='Extract recordId and rowCount from an admin-data operation result'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
463
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
464
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
465
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
466
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
467
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
468
765
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:extractLogResult:function"]
469
766
 
470
767
 
768
+
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+
782
+
471
783
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:logAdminDataOperation:function" type="function" identity="logAdminDataOperation" parent="~/.framework/functions/_shared/logging.ts"]
472
- // CIL[DOC-MACRO purpose="Write a structured admin-data operation log to the logs table"]
473
- // CIL[DOC-RESPONSIBILITY responsibility="Persist a log row based on resolved log levels and payload"]
474
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
475
- // CIL[DOC-CONTRACT inputs="ctx: LogContext, payload: AdminDataLogPayload" outputs="Promise<void>" errors="none" side_effects="Inserts a row into the logs table via ctx.db or adminDb"]
476
- // CIL[DOC-MICRO logic_summary="Resolves levels, filters by error/warning/timing, builds message/context/metadata and inserts a log row" notable_decisions="[]"]
477
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
478
- // CIL[DOC-STABILITY internal]
784
+ /**
785
+ * Logs administrative data operations to a database, ensuring that only relevant log entries are recorded based on the provided payload and context. This function filters logs based on log levels and error/warning status.
786
+ *
787
+ * @macro Async function responsible for logging administrative data operations.
788
+ * @micro Determines the appropriate log level based on the presence of errors or warnings and the resolved log levels.
789
+ * @inputSpec
790
+ * ctx: LogContext (required) — context containing logging and user information.
791
+ * payload: AdminDataLogPayload (required) — data payload containing details about the operation being logged.
792
+ * @outputSpec Promise<void>
793
+ * @sideEffects Writes log entries to the database.
794
+ * @stability internal
795
+ * @calls resolveLogLevels, resolveAppUuid, traceLogFields, buildMessage, buildContext, buildMetadata, ctx.db.from('logs').insert
796
+ * @errorHandling Logs errors to the console if logging fails.
797
+ * @cil-generated
798
+ */
479
799
  export async function logAdminDataOperation(
480
800
  ctx: LogContext,
481
801
  payload: AdminDataLogPayload
@@ -510,7 +830,7 @@ export async function logAdminDataOperation(
510
830
  source_id: payload.recordId || null,
511
831
  person_id: ctx.principal?.id || null,
512
832
  created_by: ctx.principal?.id || null,
513
- app_id: ctx.appId || null,
833
+ app_id: await resolveAppUuid(ctx.appId),
514
834
  account_id: ctx.accountId || null,
515
835
  span_name: `admin-data.${payload.action}`,
516
836
  kind: 'event',
@@ -529,23 +849,40 @@ export async function logAdminDataOperation(
529
849
  console.error('Failed to write admin-data log:', err)
530
850
  }
531
851
  }
532
- // CIL[DOC-VECTOR type="context" content="purpose='Write a structured admin-data operation log to the logs table'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
533
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
534
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
535
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
536
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
537
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
538
852
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:logAdminDataOperation:function"]
539
853
 
540
854
 
855
+
856
+
857
+
858
+
859
+
860
+
861
+
862
+
863
+
864
+
865
+
866
+
867
+
868
+
869
+
541
870
  // CIL[BEGIN stable_id="~/.framework/functions/_shared/logging.ts:withAdminLogging:function" type="function" identity="withAdminLogging" parent="~/.framework/functions/_shared/logging.ts"]
542
- // CIL[DOC-MACRO purpose="Wrap an admin-data operation with automatic timing and logging"]
543
- // CIL[DOC-RESPONSIBILITY responsibility="Run an async operation and emit a structured log on completion or error"]
544
- // CIL[DOC-CONTEXT module="functions/_shared/logging" layer="shared" related_files=".framework/functions/_shared/db.ts,.framework/functions/_shared/logging.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/principal.ts"]
545
- // CIL[DOC-CONTRACT inputs="ctx: LogContext, params: Omit<AdminDataLogPayload, 'durationMs' | 'error' | 'recordId' | 'rowCount'>, operation: () => Promise<T>" outputs="Promise<T>" errors="Re-throws operation errors" side_effects="Calls logAdminDataOperation after the operation"]
546
- // CIL[DOC-MICRO logic_summary="Times the operation, extracts recordId/rowCount from result, catches and re-throws errors, and logs in finally" notable_decisions="[]"]
547
- // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
548
- // CIL[DOC-STABILITY internal]
871
+ /**
872
+ * The withAdminLogging function wraps an asynchronous operation with logging capabilities for admin data operations. It captures execution time, potential errors, and relevant result metadata for logging purposes.
873
+ *
874
+ * @macro Async function that logs admin data operations.
875
+ * @micro Measures execution duration and logs details in a finally block regardless of success or failure.
876
+ * @inputSpec
877
+ * ctx: LogContext (required) — the logging context for the operation.
878
+ * params: Omit<AdminDataLogPayload, 'durationMs' | 'error' | 'recordId' | 'rowCount'> (required) — parameters for logging excluding certain fields.
879
+ * operation: () => Promise<T> (required) — the asynchronous operation to execute.
880
+ * @outputSpec Promise<T> — the result of the executed operation.
881
+ * @sideEffects Logs admin data operation details to an external logging service.
882
+ * @stability internal
883
+ * @calls extractLogResult, logAdminDataOperation
884
+ * @cil-generated
885
+ */
549
886
  export async function withAdminLogging<T>(
550
887
  ctx: LogContext,
551
888
  params: Omit<AdminDataLogPayload, 'durationMs' | 'error' | 'recordId' | 'rowCount'>,
@@ -577,10 +914,11 @@ export async function withAdminLogging<T>(
577
914
  }).catch(console.error)
578
915
  }
579
916
  }
580
- // CIL[DOC-VECTOR type="context" content="purpose='Wrap an admin-data operation with automatic timing and logging'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/principal.ts"]
581
- // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
582
- // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
583
- // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
584
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
585
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
586
917
  // CIL[END stable_id="~/.framework/functions/_shared/logging.ts:withAdminLogging:function"]
918
+
919
+
920
+
921
+
922
+
923
+
924
+