sandloom-admin 0.7.0a6__tar.gz

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 (37) hide show
  1. sandloom_admin-0.7.0a6/.gitignore +4 -0
  2. sandloom_admin-0.7.0a6/CHANGELOG.md +15 -0
  3. sandloom_admin-0.7.0a6/LICENSE +202 -0
  4. sandloom_admin-0.7.0a6/NOTICE +8 -0
  5. sandloom_admin-0.7.0a6/PKG-INFO +50 -0
  6. sandloom_admin-0.7.0a6/README.md +32 -0
  7. sandloom_admin-0.7.0a6/pyproject.toml +37 -0
  8. sandloom_admin-0.7.0a6/sandloom_admin/__init__.py +13 -0
  9. sandloom_admin-0.7.0a6/sandloom_admin/api.py +140 -0
  10. sandloom_admin-0.7.0a6/sandloom_admin/console/LICENSE +202 -0
  11. sandloom_admin-0.7.0a6/sandloom_admin/console/Manrope-OFL.txt +93 -0
  12. sandloom_admin-0.7.0a6/sandloom_admin/console/NOTICE +13 -0
  13. sandloom_admin-0.7.0a6/sandloom_admin/console/apple-touch-icon.png +0 -0
  14. sandloom_admin-0.7.0a6/sandloom_admin/console/assets/index-CfjL8uLg.js +1 -0
  15. sandloom_admin-0.7.0a6/sandloom_admin/console/assets/index-DAJ9yBQ3.css +2 -0
  16. sandloom_admin-0.7.0a6/sandloom_admin/console/assets/manrope-cyrillic-wght-normal-Dvxsihut.woff2 +0 -0
  17. sandloom_admin-0.7.0a6/sandloom_admin/console/assets/manrope-greek-wght-normal-DL7QRZyv.woff2 +0 -0
  18. sandloom_admin-0.7.0a6/sandloom_admin/console/assets/manrope-latin-ext-wght-normal-Ch3YOpNY.woff2 +0 -0
  19. sandloom_admin-0.7.0a6/sandloom_admin/console/assets/manrope-latin-wght-normal-DHIcAJRg.woff2 +0 -0
  20. sandloom_admin-0.7.0a6/sandloom_admin/console/assets/manrope-vietnamese-wght-normal-usUDDRr7.woff2 +0 -0
  21. sandloom_admin-0.7.0a6/sandloom_admin/console/assets/radix-BdE3MoQ5.js +41 -0
  22. sandloom_admin-0.7.0a6/sandloom_admin/console/assets/react-CU93doju.js +11 -0
  23. sandloom_admin-0.7.0a6/sandloom_admin/console/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
  24. sandloom_admin-0.7.0a6/sandloom_admin/console/assets/tanstack-C0DV4W2S.js +4 -0
  25. sandloom_admin-0.7.0a6/sandloom_admin/console/console.json +15 -0
  26. sandloom_admin-0.7.0a6/sandloom_admin/console/favicon-96.png +0 -0
  27. sandloom_admin-0.7.0a6/sandloom_admin/console/favicon.ico +0 -0
  28. sandloom_admin-0.7.0a6/sandloom_admin/console/favicon.svg +1 -0
  29. sandloom_admin-0.7.0a6/sandloom_admin/console/fonts/Hack-LICENSE.md +45 -0
  30. sandloom_admin-0.7.0a6/sandloom_admin/console/fonts/Hack-SOURCE.json +19 -0
  31. sandloom_admin-0.7.0a6/sandloom_admin/console/fonts/hack-nerd-mono-bold.woff2 +0 -0
  32. sandloom_admin-0.7.0a6/sandloom_admin/console/fonts/hack-nerd-mono-regular.woff2 +0 -0
  33. sandloom_admin-0.7.0a6/sandloom_admin/console/index.html +25 -0
  34. sandloom_admin-0.7.0a6/sandloom_admin/console/sandloom-mark.svg +1 -0
  35. sandloom_admin-0.7.0a6/sandloom_admin/console/third-party-licenses.txt +2754 -0
  36. sandloom_admin-0.7.0a6/sandloom_admin/module.snapshot.json +10 -0
  37. sandloom_admin-0.7.0a6/sandloom_admin/routes.snapshot.json +50 -0
@@ -0,0 +1,4 @@
1
+ # Build artifacts from `uv build` — not committed.
2
+ dist/
3
+ build/
4
+ *.egg-info/
@@ -0,0 +1,15 @@
1
+ # Changelog — sandloom-admin
2
+
3
+ All notable changes to the `sandloom-admin` distribution are documented here.
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+ Per-package entries are aggregated in the repository-level [docs/changelog.md](../../docs/changelog.md).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.7.0a6] — 2026-11-01
11
+
12
+ ### Added
13
+
14
+ - The admin console as a package: a prebuilt web UI served by the application at
15
+ `/admin/`, off in production unless `ADMIN_CONSOLE_ENABLED=true`.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,8 @@
1
+ Sandloom
2
+ Copyright 2026 Vasyl Cherniavskyi
3
+
4
+ The original Sandloom framework code, documentation and examples are licensed
5
+ under the Apache License, Version 2.0. See LICENSE for the full terms.
6
+
7
+ Third-party components and assets retain their own copyright notices and
8
+ licenses. This notice does not replace or modify those terms.
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.5
2
+ Name: sandloom-admin
3
+ Version: 0.7.0a6
4
+ Summary: The admin console for Sandloom: a prebuilt web UI for the platform owner, with no Node or separate image.
5
+ Project-URL: Homepage, https://sandloom.dev/
6
+ Project-URL: Documentation, https://sandloom.dev/docs/
7
+ Project-URL: Repository, https://github.com/Sandloom-dev/sandloom
8
+ Project-URL: Issues, https://github.com/Sandloom-dev/sandloom/issues
9
+ Project-URL: Changelog, https://github.com/Sandloom-dev/sandloom/blob/main/packages/sandloom-admin/CHANGELOG.md
10
+ Author: Vasyl Cherniavskyi
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ License-File: NOTICE
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Requires-Python: >=3.11
16
+ Requires-Dist: sandloom<0.8,>=0.7.0a6
17
+ Description-Content-Type: text/markdown
18
+
19
+ # sandloom-admin
20
+
21
+ **The admin console for Sandloom.**
22
+
23
+ A web console for the platform owner: users, organizations, billing, audit and
24
+ service health. It ships ready to run inside this package, so you need neither Node
25
+ nor a separate image.
26
+
27
+ Part of [Sandloom](https://github.com/Sandloom-dev/sandloom), the Python backend
28
+ framework for AI-driven development.
29
+
30
+ ## Included
31
+
32
+ - The built console, served by your application at `/admin/`.
33
+ - Screens from the `admin.py` declarations of your modules, with no frontend build.
34
+ - Off in production unless you set `ADMIN_CONSOLE_ENABLED=true`.
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ uvx --from "sandloom[standard]==0.7.0a6" sandloom new myapp --with admin
40
+ ```
41
+
42
+ Or add it to an existing application:
43
+
44
+ ```bash
45
+ uv add "sandloom[admin]"
46
+ ```
47
+
48
+ Add `"admin"` to `BUNDLED` in your `asgi.py`, then run `uv run sandloom generate`.
49
+
50
+ See the [Admin Console documentation](https://sandloom.dev/docs/admin-console/).
@@ -0,0 +1,32 @@
1
+ # sandloom-admin
2
+
3
+ **The admin console for Sandloom.**
4
+
5
+ A web console for the platform owner: users, organizations, billing, audit and
6
+ service health. It ships ready to run inside this package, so you need neither Node
7
+ nor a separate image.
8
+
9
+ Part of [Sandloom](https://github.com/Sandloom-dev/sandloom), the Python backend
10
+ framework for AI-driven development.
11
+
12
+ ## Included
13
+
14
+ - The built console, served by your application at `/admin/`.
15
+ - Screens from the `admin.py` declarations of your modules, with no frontend build.
16
+ - Off in production unless you set `ADMIN_CONSOLE_ENABLED=true`.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ uvx --from "sandloom[standard]==0.7.0a6" sandloom new myapp --with admin
22
+ ```
23
+
24
+ Or add it to an existing application:
25
+
26
+ ```bash
27
+ uv add "sandloom[admin]"
28
+ ```
29
+
30
+ Add `"admin"` to `BUNDLED` in your `asgi.py`, then run `uv run sandloom generate`.
31
+
32
+ See the [Admin Console documentation](https://sandloom.dev/docs/admin-console/).
@@ -0,0 +1,37 @@
1
+ [project]
2
+ name = "sandloom-admin"
3
+ version = "0.7.0a6"
4
+ classifiers = ["Development Status :: 3 - Alpha"]
5
+ description = "The admin console for Sandloom: a prebuilt web UI for the platform owner, with no Node or separate image."
6
+ readme = "README.md"
7
+ license = "Apache-2.0"
8
+ license-files = ["LICENSE", "NOTICE"]
9
+ authors = [{ name = "Vasyl Cherniavskyi" }]
10
+ requires-python = ">=3.11"
11
+ # An ecosystem module like any third party's: a compatible framework range.
12
+ # The console signs in through identity, a separate distribution, which the
13
+ # `sandloom[admin]` extra and `sandloom new --with admin` add.
14
+ dependencies = [
15
+ "sandloom>=0.7.0a6,<0.8",
16
+ ]
17
+
18
+ [project.urls]
19
+ Homepage = "https://sandloom.dev/"
20
+ Documentation = "https://sandloom.dev/docs/"
21
+ Repository = "https://github.com/Sandloom-dev/sandloom"
22
+ Issues = "https://github.com/Sandloom-dev/sandloom/issues"
23
+ Changelog = "https://github.com/Sandloom-dev/sandloom/blob/main/packages/sandloom-admin/CHANGELOG.md"
24
+
25
+ # The module name and
26
+ # its import path; SANDLOOM_MODULES may name it by either.
27
+ [project.entry-points."sandloom.modules"]
28
+ admin = "sandloom_admin"
29
+
30
+ [build-system]
31
+ requires = [
32
+ "hatchling>=1.27",
33
+ ]
34
+ build-backend = "hatchling.build"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["sandloom_admin"]
@@ -0,0 +1,13 @@
1
+ """The platform owner's console: a prebuilt web UI, served at ``/admin/``.
2
+
3
+ The UI talks only to the modules' public APIs, so this module holds no tables,
4
+ events or contracts, and every authorization decision stays with those APIs.
5
+ The screens come from the ``admin.py`` declarations of the composed modules,
6
+ which ``sandloom generate`` compiles to ``<app>/shared/admin-manifest.json``.
7
+ """
8
+
9
+ from sandloom.sdk import define_module
10
+
11
+ register = define_module(__name__, version="1.0.0")
12
+
13
+ __all__ = ["register"]
@@ -0,0 +1,140 @@
1
+ """Serve the console's files, its configuration and the application's manifest."""
2
+
3
+ import json
4
+ from importlib import resources
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ from fastapi import Depends, HTTPException
9
+ from fastapi.responses import FileResponse, JSONResponse, RedirectResponse
10
+
11
+ from sandloom.sdk import module_router, public
12
+ from sandloom.sdk.infra import settings
13
+
14
+ MANIFEST = "admin-manifest.json"
15
+ PACKAGED = Path(__file__).parent / "console"
16
+ #: The UI loads nothing from elsewhere and is framed by nothing.
17
+ CSP = (
18
+ "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; "
19
+ "img-src 'self' data:; font-src 'self' data:; connect-src 'self'; "
20
+ "frame-ancestors 'none'; base-uri 'self'; form-action 'self'"
21
+ )
22
+ NOT_GENERATED = "The admin manifest is missing: run `sandloom generate` and restart."
23
+
24
+
25
+ def _enabled() -> None:
26
+ enabled = settings.admin_console_enabled
27
+ if enabled is None:
28
+ enabled = settings.environment.value != "prod"
29
+ if not enabled:
30
+ raise HTTPException(404, "Not found")
31
+
32
+
33
+ router = module_router(
34
+ prefix="/admin",
35
+ tags=["admin-console"],
36
+ dependencies=[
37
+ public(reason="the console's static files; every API it calls checks access"),
38
+ Depends(_enabled),
39
+ ],
40
+ )
41
+
42
+
43
+ def _console() -> Path:
44
+ custom = settings.admin_console_dist
45
+ return Path(custom) if custom else PACKAGED
46
+
47
+
48
+ def _read_manifest() -> dict[str, Any] | None:
49
+ """The first manifest found in the application's generated packages."""
50
+ for package in (*settings.contract_dto_packages, "sandloom.shared"):
51
+ try:
52
+ file = resources.files(package) / MANIFEST
53
+ if file.is_file():
54
+ parsed: dict[str, Any] = json.loads(file.read_text(encoding="utf-8"))
55
+ return parsed
56
+ except ModuleNotFoundError:
57
+ continue
58
+ return None
59
+
60
+
61
+ def _problem(manifest: dict[str, Any], console: dict[str, Any]) -> str | None:
62
+ """Why this console cannot show this manifest, in terms the operator can act on."""
63
+ if manifest.get("version") not in console["manifest_versions"]:
64
+ return (
65
+ f"This console does not support admin manifest version "
66
+ f"{manifest.get('version')!r}: align the sandloom and sandloom-admin "
67
+ "versions, then run `sandloom generate`."
68
+ )
69
+ named = {
70
+ widget
71
+ for resource in manifest.get("resources", [])
72
+ for field in ("show_widgets", "edit_widgets")
73
+ for widget in resource.get(field, [])
74
+ }
75
+ unknown = sorted(named - set(console["widgets"]))
76
+ if unknown:
77
+ return (
78
+ f"This console does not include {', '.join(unknown)}: upgrade "
79
+ "sandloom-admin to match the installed modules."
80
+ )
81
+ return None
82
+
83
+
84
+ def _usable_manifest() -> dict[str, Any]:
85
+ manifest = _read_manifest()
86
+ if manifest is None:
87
+ raise HTTPException(503, NOT_GENERATED)
88
+ described = _console() / "console.json"
89
+ if described.is_file():
90
+ problem = _problem(manifest, json.loads(described.read_text(encoding="utf-8")))
91
+ if problem:
92
+ raise HTTPException(503, problem)
93
+ return manifest
94
+
95
+
96
+ def _json(payload: dict[str, Any]) -> JSONResponse:
97
+ return JSONResponse(payload, headers={"Cache-Control": "no-store"})
98
+
99
+
100
+ @router.get("", include_in_schema=False)
101
+ async def console_root() -> RedirectResponse:
102
+ return RedirectResponse("/admin/", status_code=308)
103
+
104
+
105
+ @router.get(f"/{MANIFEST}", include_in_schema=False)
106
+ async def admin_manifest() -> JSONResponse:
107
+ return _json(_usable_manifest())
108
+
109
+
110
+ @router.get("/config.json", include_in_schema=False)
111
+ async def console_config() -> JSONResponse:
112
+ """Every section the manifest declares: composition already selected them."""
113
+ modules = [m for m in _usable_manifest()["modules"] if m != "core"]
114
+ if "identity" not in modules:
115
+ raise HTTPException(503, "The admin console needs the identity module.")
116
+ return _json({"modules": modules})
117
+
118
+
119
+ @router.get("/{path:path}", include_in_schema=False)
120
+ async def console_file(path: str) -> FileResponse:
121
+ root = _console().resolve()
122
+ file = (root / path).resolve()
123
+ if file != root and root in file.parents and file.is_file():
124
+ if "assets" in file.relative_to(root).parts:
125
+ # The file name carries its content hash.
126
+ cache = "public, max-age=31536000, immutable"
127
+ else:
128
+ cache = "no-store"
129
+ return FileResponse(file, headers={"Cache-Control": cache})
130
+ # A deep link is the browser's route. A missing file must stay a 404, or a
131
+ # stale script tag would receive HTML.
132
+ if "." in path.rsplit("/", 1)[-1]:
133
+ raise HTTPException(404, "Not found")
134
+ index = root / "index.html"
135
+ if not index.is_file():
136
+ raise HTTPException(503, "The admin console files are missing.")
137
+ return FileResponse(
138
+ index,
139
+ headers={"Cache-Control": "no-store", "Content-Security-Policy": CSP},
140
+ )