@fonderie/admin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/brain/outcomes.md +14 -0
- package/brain/signatures.md +42 -0
- package/dist/index.cjs +107 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +39 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fonderie, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @fonderie/admin
|
|
2
|
+
|
|
3
|
+
The operator's surface. One reserved path (default `/_admin`) behind one admin
|
|
4
|
+
token, answering what the founder cannot see after deploy: **which bricks are
|
|
5
|
+
installed, at what version, whether they are ready, and every route that is
|
|
6
|
+
exposed.**
|
|
7
|
+
|
|
8
|
+
Status: **experimental** (0.x). Design and roadmap: `docs/ADMIN-BRICK-DESIGN.md`.
|
|
9
|
+
|
|
10
|
+
## Use it
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { AdminModule } from '@fonderie/admin';
|
|
14
|
+
|
|
15
|
+
app.register(new AdminModule({ adminToken: process.env.ADMIN_TOKEN }));
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
curl -H "Authorization: Bearer $ADMIN_TOKEN" https://api.example.com/_admin/manifest
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- **No token, no surface.** Unset `adminToken` ⇒ nothing is registered (404),
|
|
23
|
+
never an open route. Same rule as every other brick's admin routes
|
|
24
|
+
(`docs/ADMIN-AUTH-SPEC.md`); the token is strength-checked at boot.
|
|
25
|
+
- **The prefix is reserved.** No other module can mount under it — a collision
|
|
26
|
+
fails boot, naming both sides. `path` moves the whole surface
|
|
27
|
+
(`{ path: '/ops' }`); it is relative to the app's `basePath`, like every route.
|
|
28
|
+
|
|
29
|
+
## `GET /_admin/manifest`
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"generatedAt": "…", "env": "production",
|
|
34
|
+
"admin": { "version": "0.1.0" },
|
|
35
|
+
"modules": [
|
|
36
|
+
{ "name": "@fonderie/auth", "version": null, "readiness": { "ok": true, "problems": [] } },
|
|
37
|
+
{ "name": "@fonderie/config", "version": null, "readiness": { "ok": true, "problems": [ { "severity": "warning", "message": "no secretEncryptor configured — …" } ] } }
|
|
38
|
+
],
|
|
39
|
+
"readiness": { "ok": true, "problems": [ … ] },
|
|
40
|
+
"routes": [ { "method": "POST", "path": "/auth/login", "module": "@fonderie/auth" }, … ]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`version` is `null` until a brick reports one (`IFonderieModule.version`).
|
|
45
|
+
Readiness problems are shown here in production — unlike `/readyz`, which is
|
|
46
|
+
public — because the operator is the audience.
|
|
47
|
+
|
|
48
|
+
## Why it's a brick
|
|
49
|
+
|
|
50
|
+
The model that assembled the app knows what is installed, wired and
|
|
51
|
+
configured. The human who deployed it does not, unless they are back in a
|
|
52
|
+
development session and can ask. `@fonderie/core` already computes the
|
|
53
|
+
answer (`securityReport()`, `app.routes()`); this brick gives it an address.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!-- GENERATED — do not edit. Regenerate with: npm run docs:signatures -->
|
|
2
|
+
|
|
3
|
+
# @fonderie/admin — outcomes
|
|
4
|
+
|
|
5
|
+
What this package does to a running app: tables its migrations create,
|
|
6
|
+
rows it seeds, routes it registers. Generated from the migration SQL and
|
|
7
|
+
route tables in source — trust this file instead of reading `dist/` or
|
|
8
|
+
downloading tarballs.
|
|
9
|
+
|
|
10
|
+
## HTTP routes registered
|
|
11
|
+
|
|
12
|
+
| Method | Path | Middleware chain (auth / validation / handler) |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| GET | `/_admin/manifest` | `g(async () => setApiResponse( HTTP.OK, 'ADMIN_MANIFEST', 'Deployment manifest', buildManifest(app, { version: this.version }), ), )` |
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<!-- GENERATED — do not edit. Regenerate with: npm run docs:signatures -->
|
|
2
|
+
|
|
3
|
+
# @fonderie/admin — signatures
|
|
4
|
+
|
|
5
|
+
## @fonderie/admin
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
new AdminModule(options?: IAdminOptions): AdminModule
|
|
9
|
+
.name: "@fonderie/admin"
|
|
10
|
+
.version: string
|
|
11
|
+
.path: string
|
|
12
|
+
.install(app: IFonderieApp): void
|
|
13
|
+
.checkReadiness(): IReadinessProblem[]
|
|
14
|
+
|
|
15
|
+
const ADMIN_VERSION: string
|
|
16
|
+
|
|
17
|
+
const DEFAULT_ADMIN_PATH: "/_admin"
|
|
18
|
+
|
|
19
|
+
function buildManifest(app: IFonderieApp, admin: { version: string; }): IAdminManifest
|
|
20
|
+
|
|
21
|
+
interface IAdminOptions {
|
|
22
|
+
adminToken?: string;
|
|
23
|
+
path?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface IAdminManifest {
|
|
27
|
+
generatedAt: string;
|
|
28
|
+
env: string;
|
|
29
|
+
admin: {
|
|
30
|
+
version: string;
|
|
31
|
+
};
|
|
32
|
+
modules: IAdminModuleEntry[];
|
|
33
|
+
readiness: IReadinessReport;
|
|
34
|
+
routes: IRouteEntry[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface IAdminModuleEntry {
|
|
38
|
+
name: string;
|
|
39
|
+
version: string | null;
|
|
40
|
+
readiness: IReadinessReport;
|
|
41
|
+
}
|
|
42
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ADMIN_VERSION: () => ADMIN_VERSION,
|
|
24
|
+
AdminModule: () => AdminModule,
|
|
25
|
+
DEFAULT_ADMIN_PATH: () => DEFAULT_ADMIN_PATH,
|
|
26
|
+
buildManifest: () => buildManifest
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/module.ts
|
|
31
|
+
var import_core = require("@fonderie/core");
|
|
32
|
+
var import_middlewares = require("@fonderie/core/middlewares");
|
|
33
|
+
|
|
34
|
+
// src/manifest.ts
|
|
35
|
+
function buildManifest(app, admin) {
|
|
36
|
+
const report = app.securityReport();
|
|
37
|
+
const byModule = /* @__PURE__ */ new Map();
|
|
38
|
+
for (const p of report.readiness.problems) {
|
|
39
|
+
const list = byModule.get(p.module) ?? [];
|
|
40
|
+
list.push(p);
|
|
41
|
+
byModule.set(p.module, list);
|
|
42
|
+
}
|
|
43
|
+
const modules = report.modules.map(({ name, version }) => {
|
|
44
|
+
const problems = byModule.get(name) ?? [];
|
|
45
|
+
return {
|
|
46
|
+
name,
|
|
47
|
+
version: version ?? null,
|
|
48
|
+
readiness: { ok: !problems.some((p) => p.severity === "error"), problems }
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
generatedAt: report.generatedAt,
|
|
53
|
+
env: report.env,
|
|
54
|
+
admin,
|
|
55
|
+
modules,
|
|
56
|
+
readiness: report.readiness,
|
|
57
|
+
routes: app.routes()
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/module.ts
|
|
62
|
+
var DEFAULT_ADMIN_PATH = "/_admin";
|
|
63
|
+
var ADMIN_VERSION = "0.1.0";
|
|
64
|
+
var AdminModule = class {
|
|
65
|
+
constructor(options = {}) {
|
|
66
|
+
this.options = options;
|
|
67
|
+
this.path = (options.path ?? DEFAULT_ADMIN_PATH).replace(/\/+$/, "");
|
|
68
|
+
}
|
|
69
|
+
options;
|
|
70
|
+
name = "@fonderie/admin";
|
|
71
|
+
version = ADMIN_VERSION;
|
|
72
|
+
path;
|
|
73
|
+
install(app) {
|
|
74
|
+
const token = this.options.adminToken;
|
|
75
|
+
if (!token) return;
|
|
76
|
+
app.reserve(this.path);
|
|
77
|
+
const guard = (0, import_middlewares.requireAdminToken)(token);
|
|
78
|
+
const g = (h) => (ctx, next) => guard(ctx, () => h(ctx, next));
|
|
79
|
+
const at = (p) => this.path + p.slice(DEFAULT_ADMIN_PATH.length);
|
|
80
|
+
const routes = [
|
|
81
|
+
[
|
|
82
|
+
"GET",
|
|
83
|
+
"/_admin/manifest",
|
|
84
|
+
g(
|
|
85
|
+
async () => (0, import_core.setApiResponse)(
|
|
86
|
+
import_core.HTTP.OK,
|
|
87
|
+
"ADMIN_MANIFEST",
|
|
88
|
+
"Deployment manifest",
|
|
89
|
+
buildManifest(app, { version: this.version })
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
]
|
|
93
|
+
];
|
|
94
|
+
for (const [method, path, handler] of routes) app.addRoute(method, at(path), handler);
|
|
95
|
+
}
|
|
96
|
+
checkReadiness() {
|
|
97
|
+
return (0, import_middlewares.validateAdminToken)(this.options.adminToken, { module: this.name });
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
101
|
+
0 && (module.exports = {
|
|
102
|
+
ADMIN_VERSION,
|
|
103
|
+
AdminModule,
|
|
104
|
+
DEFAULT_ADMIN_PATH,
|
|
105
|
+
buildManifest
|
|
106
|
+
});
|
|
107
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/module.ts","../src/manifest.ts"],"sourcesContent":["export { AdminModule, ADMIN_VERSION, DEFAULT_ADMIN_PATH } from './module';\nexport { buildManifest } from './manifest';\nexport type { IAdminOptions, IAdminManifest, IAdminModuleEntry } from './types';\n","import type { IFonderieApp, IFonderieModule, IReadinessProblem, Middleware } from '@fonderie/core';\nimport { HTTP, setApiResponse } from '@fonderie/core';\nimport { requireAdminToken, validateAdminToken } from '@fonderie/core/middlewares';\n\nimport { buildManifest } from './manifest';\nimport type { IAdminOptions } from './types';\n\nexport const DEFAULT_ADMIN_PATH = '/_admin';\n\n// Replaced at build time (tsup env); the fallback is what tests see.\nexport const ADMIN_VERSION: string = process.env['FONDERIE_ADMIN_VERSION'] ?? '0.0.0-dev';\n\nexport class AdminModule implements IFonderieModule {\n\treadonly name = '@fonderie/admin';\n\treadonly version = ADMIN_VERSION;\n\treadonly path: string;\n\n\tconstructor(private options: IAdminOptions = {}) {\n\t\tthis.path = (options.path ?? DEFAULT_ADMIN_PATH).replace(/\\/+$/, '');\n\t}\n\n\tinstall(app: IFonderieApp): void {\n\t\tconst token = this.options.adminToken;\n\t\tif (!token) return;\n\n\t\tapp.reserve(this.path);\n\t\tconst guard = requireAdminToken(token);\n\t\tconst g =\n\t\t\t(h: Middleware): Middleware =>\n\t\t\t(ctx, next) =>\n\t\t\t\tguard(ctx, () => h(ctx, next));\n\t\t// Declared at the default path so the route table reads literally; re-based when configured.\n\t\tconst at = (p: string): string => this.path + p.slice(DEFAULT_ADMIN_PATH.length);\n\n\t\tconst routes: Array<[string, string, Middleware]> = [\n\t\t\t[\n\t\t\t\t'GET',\n\t\t\t\t'/_admin/manifest',\n\t\t\t\tg(async () =>\n\t\t\t\t\tsetApiResponse(\n\t\t\t\t\t\tHTTP.OK,\n\t\t\t\t\t\t'ADMIN_MANIFEST',\n\t\t\t\t\t\t'Deployment manifest',\n\t\t\t\t\t\tbuildManifest(app, { version: this.version }),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t],\n\t\t];\n\t\tfor (const [method, path, handler] of routes) app.addRoute(method, at(path), handler);\n\t}\n\n\tcheckReadiness(): IReadinessProblem[] {\n\t\treturn validateAdminToken(this.options.adminToken, { module: this.name });\n\t}\n}\n","import type { IFonderieApp, IReadinessProblem } from '@fonderie/core';\n\nimport type { IAdminManifest, IAdminModuleEntry } from './types';\n\nexport function buildManifest(app: IFonderieApp, admin: { version: string }): IAdminManifest {\n\tconst report = app.securityReport();\n\tconst byModule = new Map<string, IReadinessProblem[]>();\n\tfor (const p of report.readiness.problems) {\n\t\tconst list = byModule.get(p.module) ?? [];\n\t\tlist.push(p);\n\t\tbyModule.set(p.module, list);\n\t}\n\tconst modules: IAdminModuleEntry[] = report.modules.map(({ name, version }) => {\n\t\tconst problems = byModule.get(name) ?? [];\n\t\treturn {\n\t\t\tname,\n\t\t\tversion: version ?? null,\n\t\t\treadiness: { ok: !problems.some((p) => p.severity === 'error'), problems },\n\t\t};\n\t});\n\treturn {\n\t\tgeneratedAt: report.generatedAt,\n\t\tenv: report.env,\n\t\tadmin,\n\t\tmodules,\n\t\treadiness: report.readiness,\n\t\troutes: app.routes(),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAqC;AACrC,yBAAsD;;;ACE/C,SAAS,cAAc,KAAmB,OAA4C;AAC5F,QAAM,SAAS,IAAI,eAAe;AAClC,QAAM,WAAW,oBAAI,IAAiC;AACtD,aAAW,KAAK,OAAO,UAAU,UAAU;AAC1C,UAAM,OAAO,SAAS,IAAI,EAAE,MAAM,KAAK,CAAC;AACxC,SAAK,KAAK,CAAC;AACX,aAAS,IAAI,EAAE,QAAQ,IAAI;AAAA,EAC5B;AACA,QAAM,UAA+B,OAAO,QAAQ,IAAI,CAAC,EAAE,MAAM,QAAQ,MAAM;AAC9E,UAAM,WAAW,SAAS,IAAI,IAAI,KAAK,CAAC;AACxC,WAAO;AAAA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AK,QAAQ,YAAY,EAAE,QAAQ,KAAK,KAAK,CAAC;AAAA,EACzE;AACD;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IReadinessReport, IRouteEntry, IFonderieModule, IFonderieApp, IReadinessProblem } from '@fonderie/core';
|
|
2
|
+
|
|
3
|
+
interface IAdminOptions {
|
|
4
|
+
adminToken?: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
}
|
|
7
|
+
interface IAdminModuleEntry {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string | null;
|
|
10
|
+
readiness: IReadinessReport;
|
|
11
|
+
}
|
|
12
|
+
interface IAdminManifest {
|
|
13
|
+
generatedAt: string;
|
|
14
|
+
env: string;
|
|
15
|
+
admin: {
|
|
16
|
+
version: string;
|
|
17
|
+
};
|
|
18
|
+
modules: IAdminModuleEntry[];
|
|
19
|
+
readiness: IReadinessReport;
|
|
20
|
+
routes: IRouteEntry[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare const DEFAULT_ADMIN_PATH = "/_admin";
|
|
24
|
+
declare const ADMIN_VERSION: string;
|
|
25
|
+
declare class AdminModule implements IFonderieModule {
|
|
26
|
+
private options;
|
|
27
|
+
readonly name = "@fonderie/admin";
|
|
28
|
+
readonly version: string;
|
|
29
|
+
readonly path: string;
|
|
30
|
+
constructor(options?: IAdminOptions);
|
|
31
|
+
install(app: IFonderieApp): void;
|
|
32
|
+
checkReadiness(): IReadinessProblem[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare function buildManifest(app: IFonderieApp, admin: {
|
|
36
|
+
version: string;
|
|
37
|
+
}): IAdminManifest;
|
|
38
|
+
|
|
39
|
+
export { ADMIN_VERSION, AdminModule, DEFAULT_ADMIN_PATH, type IAdminManifest, type IAdminModuleEntry, type IAdminOptions, buildManifest };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IReadinessReport, IRouteEntry, IFonderieModule, IFonderieApp, IReadinessProblem } from '@fonderie/core';
|
|
2
|
+
|
|
3
|
+
interface IAdminOptions {
|
|
4
|
+
adminToken?: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
}
|
|
7
|
+
interface IAdminModuleEntry {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string | null;
|
|
10
|
+
readiness: IReadinessReport;
|
|
11
|
+
}
|
|
12
|
+
interface IAdminManifest {
|
|
13
|
+
generatedAt: string;
|
|
14
|
+
env: string;
|
|
15
|
+
admin: {
|
|
16
|
+
version: string;
|
|
17
|
+
};
|
|
18
|
+
modules: IAdminModuleEntry[];
|
|
19
|
+
readiness: IReadinessReport;
|
|
20
|
+
routes: IRouteEntry[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare const DEFAULT_ADMIN_PATH = "/_admin";
|
|
24
|
+
declare const ADMIN_VERSION: string;
|
|
25
|
+
declare class AdminModule implements IFonderieModule {
|
|
26
|
+
private options;
|
|
27
|
+
readonly name = "@fonderie/admin";
|
|
28
|
+
readonly version: string;
|
|
29
|
+
readonly path: string;
|
|
30
|
+
constructor(options?: IAdminOptions);
|
|
31
|
+
install(app: IFonderieApp): void;
|
|
32
|
+
checkReadiness(): IReadinessProblem[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare function buildManifest(app: IFonderieApp, admin: {
|
|
36
|
+
version: string;
|
|
37
|
+
}): IAdminManifest;
|
|
38
|
+
|
|
39
|
+
export { ADMIN_VERSION, AdminModule, DEFAULT_ADMIN_PATH, type IAdminManifest, type IAdminModuleEntry, type IAdminOptions, buildManifest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// src/module.ts
|
|
2
|
+
import { HTTP, setApiResponse } from "@fonderie/core";
|
|
3
|
+
import { requireAdminToken, validateAdminToken } from "@fonderie/core/middlewares";
|
|
4
|
+
|
|
5
|
+
// src/manifest.ts
|
|
6
|
+
function buildManifest(app, admin) {
|
|
7
|
+
const report = app.securityReport();
|
|
8
|
+
const byModule = /* @__PURE__ */ new Map();
|
|
9
|
+
for (const p of report.readiness.problems) {
|
|
10
|
+
const list = byModule.get(p.module) ?? [];
|
|
11
|
+
list.push(p);
|
|
12
|
+
byModule.set(p.module, list);
|
|
13
|
+
}
|
|
14
|
+
const modules = report.modules.map(({ name, version }) => {
|
|
15
|
+
const problems = byModule.get(name) ?? [];
|
|
16
|
+
return {
|
|
17
|
+
name,
|
|
18
|
+
version: version ?? null,
|
|
19
|
+
readiness: { ok: !problems.some((p) => p.severity === "error"), problems }
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
generatedAt: report.generatedAt,
|
|
24
|
+
env: report.env,
|
|
25
|
+
admin,
|
|
26
|
+
modules,
|
|
27
|
+
readiness: report.readiness,
|
|
28
|
+
routes: app.routes()
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/module.ts
|
|
33
|
+
var DEFAULT_ADMIN_PATH = "/_admin";
|
|
34
|
+
var ADMIN_VERSION = "0.1.0";
|
|
35
|
+
var AdminModule = class {
|
|
36
|
+
constructor(options = {}) {
|
|
37
|
+
this.options = options;
|
|
38
|
+
this.path = (options.path ?? DEFAULT_ADMIN_PATH).replace(/\/+$/, "");
|
|
39
|
+
}
|
|
40
|
+
options;
|
|
41
|
+
name = "@fonderie/admin";
|
|
42
|
+
version = ADMIN_VERSION;
|
|
43
|
+
path;
|
|
44
|
+
install(app) {
|
|
45
|
+
const token = this.options.adminToken;
|
|
46
|
+
if (!token) return;
|
|
47
|
+
app.reserve(this.path);
|
|
48
|
+
const guard = requireAdminToken(token);
|
|
49
|
+
const g = (h) => (ctx, next) => guard(ctx, () => h(ctx, next));
|
|
50
|
+
const at = (p) => this.path + p.slice(DEFAULT_ADMIN_PATH.length);
|
|
51
|
+
const routes = [
|
|
52
|
+
[
|
|
53
|
+
"GET",
|
|
54
|
+
"/_admin/manifest",
|
|
55
|
+
g(
|
|
56
|
+
async () => setApiResponse(
|
|
57
|
+
HTTP.OK,
|
|
58
|
+
"ADMIN_MANIFEST",
|
|
59
|
+
"Deployment manifest",
|
|
60
|
+
buildManifest(app, { version: this.version })
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
]
|
|
64
|
+
];
|
|
65
|
+
for (const [method, path, handler] of routes) app.addRoute(method, at(path), handler);
|
|
66
|
+
}
|
|
67
|
+
checkReadiness() {
|
|
68
|
+
return validateAdminToken(this.options.adminToken, { module: this.name });
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
ADMIN_VERSION,
|
|
73
|
+
AdminModule,
|
|
74
|
+
DEFAULT_ADMIN_PATH,
|
|
75
|
+
buildManifest
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/module.ts","../src/manifest.ts"],"sourcesContent":["import type { IFonderieApp, IFonderieModule, IReadinessProblem, Middleware } from '@fonderie/core';\nimport { HTTP, setApiResponse } from '@fonderie/core';\nimport { requireAdminToken, validateAdminToken } from '@fonderie/core/middlewares';\n\nimport { buildManifest } from './manifest';\nimport type { IAdminOptions } from './types';\n\nexport const DEFAULT_ADMIN_PATH = '/_admin';\n\n// Replaced at build time (tsup env); the fallback is what tests see.\nexport const ADMIN_VERSION: string = process.env['FONDERIE_ADMIN_VERSION'] ?? '0.0.0-dev';\n\nexport class AdminModule implements IFonderieModule {\n\treadonly name = '@fonderie/admin';\n\treadonly version = ADMIN_VERSION;\n\treadonly path: string;\n\n\tconstructor(private options: IAdminOptions = {}) {\n\t\tthis.path = (options.path ?? DEFAULT_ADMIN_PATH).replace(/\\/+$/, '');\n\t}\n\n\tinstall(app: IFonderieApp): void {\n\t\tconst token = this.options.adminToken;\n\t\tif (!token) return;\n\n\t\tapp.reserve(this.path);\n\t\tconst guard = requireAdminToken(token);\n\t\tconst g =\n\t\t\t(h: Middleware): Middleware =>\n\t\t\t(ctx, next) =>\n\t\t\t\tguard(ctx, () => h(ctx, next));\n\t\t// Declared at the default path so the route table reads literally; re-based when configured.\n\t\tconst at = (p: string): string => this.path + p.slice(DEFAULT_ADMIN_PATH.length);\n\n\t\tconst routes: Array<[string, string, Middleware]> = [\n\t\t\t[\n\t\t\t\t'GET',\n\t\t\t\t'/_admin/manifest',\n\t\t\t\tg(async () =>\n\t\t\t\t\tsetApiResponse(\n\t\t\t\t\t\tHTTP.OK,\n\t\t\t\t\t\t'ADMIN_MANIFEST',\n\t\t\t\t\t\t'Deployment manifest',\n\t\t\t\t\t\tbuildManifest(app, { version: this.version }),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t],\n\t\t];\n\t\tfor (const [method, path, handler] of routes) app.addRoute(method, at(path), handler);\n\t}\n\n\tcheckReadiness(): IReadinessProblem[] {\n\t\treturn validateAdminToken(this.options.adminToken, { module: this.name });\n\t}\n}\n","import type { IFonderieApp, IReadinessProblem } from '@fonderie/core';\n\nimport type { IAdminManifest, IAdminModuleEntry } from './types';\n\nexport function buildManifest(app: IFonderieApp, admin: { version: string }): IAdminManifest {\n\tconst report = app.securityReport();\n\tconst byModule = new Map<string, IReadinessProblem[]>();\n\tfor (const p of report.readiness.problems) {\n\t\tconst list = byModule.get(p.module) ?? [];\n\t\tlist.push(p);\n\t\tbyModule.set(p.module, list);\n\t}\n\tconst modules: IAdminModuleEntry[] = report.modules.map(({ name, version }) => {\n\t\tconst problems = byModule.get(name) ?? [];\n\t\treturn {\n\t\t\tname,\n\t\t\tversion: version ?? null,\n\t\t\treadiness: { ok: !problems.some((p) => p.severity === 'error'), problems },\n\t\t};\n\t});\n\treturn {\n\t\tgeneratedAt: report.generatedAt,\n\t\tenv: report.env,\n\t\tadmin,\n\t\tmodules,\n\t\treadiness: report.readiness,\n\t\troutes: app.routes(),\n\t};\n}\n"],"mappings":";AACA,SAAS,MAAM,sBAAsB;AACrC,SAAS,mBAAmB,0BAA0B;;;ACE/C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MAAM,mBAAmB,MAAM;AAE/E,UAAM,SAA8C;AAAA,MACnD;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,UAAE,YACD;AAAA,YACC,KAAK;AAAA,YACL;AAAA,YACA;AAAA,YACA,cAAc,KAAK,EAAE,SAAS,KAAK,QAAQ,CAAC;AAAA,UAC7C;AAAA,QACD;AAAA,MACD;AAAA,IACD;AACA,eAAW,CAAC,QAAQ,MAAM,OAAO,KAAK,OAAQ,KAAI,SAAS,QAAQ,GAAG,IAAI,GAAG,OAAO;AAAA,EACrF;AAAA,EAEA,iBAAsC;AACrC,WAAO,mBAAmB,KAAK,QAAQ,YAAY,EAAE,QAAQ,KAAK,KAAK,CAAC;AAAA,EACzE;AACD;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fonderie/admin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"fonderie": { "stability": "experimental" },
|
|
5
|
+
"description": "The operator's surface for a Fonderie deployment. Owns one reserved path (default /_admin) behind one admin token, and answers what the founder cannot see after deploy: which bricks are installed, at what version, whether they are ready, and every route that is exposed. The run-time counterpart to the SDK's brain — read by the human through a panel and by a model through curl.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"fonderiejs",
|
|
8
|
+
"admin",
|
|
9
|
+
"manifest",
|
|
10
|
+
"operations",
|
|
11
|
+
"observability",
|
|
12
|
+
"saas",
|
|
13
|
+
"typescript"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=20"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.cjs",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsup",
|
|
32
|
+
"dev": "tsup --watch",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"test": "tsx --test src/__tests__/*.test.ts",
|
|
35
|
+
"lint": "biome lint src",
|
|
36
|
+
"format": "biome format --write src",
|
|
37
|
+
"check": "biome check --write src"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@fonderie/core": "^0.17.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@fonderie/core": "../core",
|
|
44
|
+
"@types/node": "^26.5.1",
|
|
45
|
+
"tsup": "^8.5.1",
|
|
46
|
+
"tsx": "^4.23.13",
|
|
47
|
+
"typescript": "^6.0.3"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist",
|
|
54
|
+
"brain",
|
|
55
|
+
"LICENSE",
|
|
56
|
+
"README.md"
|
|
57
|
+
],
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://github.com/fonderiejs/fonderie.git",
|
|
61
|
+
"directory": "packages/admin"
|
|
62
|
+
},
|
|
63
|
+
"homepage": "https://github.com/fonderiejs/fonderie/tree/main/packages/admin#readme",
|
|
64
|
+
"bugs": {
|
|
65
|
+
"url": "https://github.com/fonderiejs/fonderie/issues"
|
|
66
|
+
}
|
|
67
|
+
}
|