@x-tech-laboratories/x-app 0.126.0 → 0.128.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/README.md +10 -3
- package/dist/app/daemon.js +1 -1
- package/dist/app/define.d.ts +8 -0
- package/dist/app/define.js +1 -0
- package/dist/app/desktop.js +47 -11
- package/dist/app/preload.js +1 -0
- package/dist/app/protocol.d.ts +1 -0
- package/dist/app/server.d.ts +2 -0
- package/dist/app/server.js +6 -2
- package/dist/app/server_fetch.d.ts +7 -0
- package/dist/app/server_fetch.js +37 -0
- package/dist/app/web/hosts.js +5 -0
- package/dist/app/web/portal.js +3 -0
- package/dist/app/web/settings_page.d.ts +3 -0
- package/dist/app/web/settings_page.js +6 -1
- package/dist/server/account_store.js +10 -1
- package/dist/server/passwords.d.ts +2 -2
- package/dist/server/passwords.js +5 -4
- package/dist/site/build.js +4 -8
- package/dist/site/markdown.d.ts +0 -2
- package/dist/site/markdown.js +1 -20
- package/dist/web/react/site.d.ts +1 -3
- package/dist/web/react/site.js +5 -48
- package/dist/web/site/client.d.ts +1 -5
- package/dist/web/site/client.js +3 -3
- package/package.json +1 -5
- package/dist/web/site/mermaid.d.ts +0 -11
- package/dist/web/site/mermaid.js +0 -65
package/README.md
CHANGED
|
@@ -275,6 +275,14 @@ An app whose work needs a computer, such as one that runs programs on checkouts,
|
|
|
275
275
|
services keep them through `context.files`, the server and daemon serve them at `/api/files/<name>` to those signed
|
|
276
276
|
in, and the page shows one from `page().file_src(name)`: the server's route, the desktop's `<id>-file://<name>` from
|
|
277
277
|
this computer or the server in use, or a blob on the phone.
|
|
278
|
+
- **A desktop portal**: `desktop: "portal"` makes the desktop app a window onto a server chosen under Connections, as
|
|
279
|
+
`phone: "portal"` does the phone: it runs no daemon, keeps no data and keeps its own switches in its profile.
|
|
280
|
+
- **Pages on REST routes**: `page().fetch("api/runs")` reaches the app's own server routes from every host: the
|
|
281
|
+
browser's own sign-in, and on a portal the server chosen under Connections with this device's token, the desktop's
|
|
282
|
+
through its main process (`app/server_fetch` does the rewriting).
|
|
283
|
+
- **Sign-in from the config**: `admin_name` names the admin a bare hash in the accounts file signs in as, and
|
|
284
|
+
`proxy_user_header` (with `trusted_proxies`, 127.0.0.1 and ::1 unless set) signs in whoever a reverse proxy on those
|
|
285
|
+
addresses names; `define_app`'s `check_access` checks a user's access when an admin sets it, such as a list of grants.
|
|
278
286
|
- **Keys in a settings export**: `render_app`'s `exports_secrets: true` offers "Include keys and tokens" on exporting
|
|
279
287
|
the settings, for an app whose settings hold other services' keys.
|
|
280
288
|
- **Links to other apps**: `run_desktop`'s `external_schemes`, such as `["stremio:", "steam:"]`, opens those links in
|
|
@@ -812,9 +820,8 @@ so it reads without JavaScript and its search, outline, menus and theme work wit
|
|
|
812
820
|
- **GitHub's own Markdown**: alerts such as `> [!TIP]` show as asides and raw HTML such as a table of pictures is
|
|
813
821
|
kept, so a page reads the same on GitHub and on the site; a page with no `title` takes its opening `# heading`, which
|
|
814
822
|
is then not drawn twice, so an MDX page can show a README with `import Readme from "../README.md"`; links that start at the root move under the base in Markdown and in a component's `href` or `src`.
|
|
815
|
-
- **Diagrams**:
|
|
816
|
-
|
|
817
|
-
JavaScript. The browser loads mermaid only on a site with a diagram, which adds `mermaid` to its own dependencies.
|
|
823
|
+
- **Diagrams**: images like any other. Draw them in [draw.io](https://www.drawio.com/), keep the `.drawio` source beside
|
|
824
|
+
its PNG export in `public/`, and show the PNG; a ```` ```mermaid ```` block is only code.
|
|
818
825
|
- **Pages beside a package**: the scan skips `node_modules`, `dist`, `public` and hidden folders, so a site can live in
|
|
819
826
|
an app's `docs/` folder with a `package.json` of its own.
|
|
820
827
|
|
package/dist/app/daemon.js
CHANGED
|
@@ -126,7 +126,7 @@ export async function start_daemon(app, options) {
|
|
|
126
126
|
default_port: app.ports.server,
|
|
127
127
|
build: (admins, https) => build_server(app, {
|
|
128
128
|
database: opened.database,
|
|
129
|
-
accounts: new AccountStore({ database: accounts_database, app_name: app.name, declared: admins, ...(app.token_prefix ? { token_prefix: app.token_prefix } : {}) }),
|
|
129
|
+
accounts: new AccountStore({ database: accounts_database, app_name: app.name, declared: admins, ...(app.token_prefix ? { token_prefix: app.token_prefix } : {}), ...(app.check_access ? { check_access: app.check_access } : {}) }),
|
|
130
130
|
web_folder,
|
|
131
131
|
changes,
|
|
132
132
|
backup_methods: opened.backup_methods,
|
package/dist/app/define.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type Caller } from "../caller.ts";
|
|
|
5
5
|
import { type CertificateMethods } from "../certificate_protocol.ts";
|
|
6
6
|
import { type ConnectionMethods } from "../connection_protocol.ts";
|
|
7
7
|
import { type Bridge } from "../electron/bridge.ts";
|
|
8
|
+
import type { FetchMethod } from "../electron/fetch.ts";
|
|
8
9
|
import { type EventsBridge } from "../electron/events.ts";
|
|
9
10
|
import type { History } from "../history.ts";
|
|
10
11
|
import type { ScopeSpec } from "../server/declared_tokens.ts";
|
|
@@ -94,8 +95,10 @@ export interface AppOptions<Features extends readonly Feature[]> {
|
|
|
94
95
|
synced_theme?: boolean;
|
|
95
96
|
host_tables?: Readonly<Record<string, HostTable>>;
|
|
96
97
|
remote_access?: boolean;
|
|
98
|
+
desktop?: "daemon" | "portal";
|
|
97
99
|
phone?: "device" | "portal";
|
|
98
100
|
roles?: readonly string[];
|
|
101
|
+
check_access?: (value: unknown) => unknown;
|
|
99
102
|
sync?: boolean;
|
|
100
103
|
declared_tokens?: {
|
|
101
104
|
key: string;
|
|
@@ -133,6 +136,9 @@ export interface AppBridges<Methods extends Record<keyof Methods, (...args: neve
|
|
|
133
136
|
events: EventsBridge<AppEvents>;
|
|
134
137
|
host: Bridge<HostAbilityMethods>;
|
|
135
138
|
remote_access: Bridge<RemoteAccessMethods>;
|
|
139
|
+
fetch: Bridge<{
|
|
140
|
+
http_fetch: FetchMethod;
|
|
141
|
+
}>;
|
|
136
142
|
host_tables: Readonly<Record<string, Bridge<Record<string, (...args: never[]) => unknown>>>>;
|
|
137
143
|
}
|
|
138
144
|
export declare function define_app<const Features extends readonly Feature[]>(options: AppOptions<Features>): {
|
|
@@ -174,8 +180,10 @@ export declare function define_app<const Features extends readonly Feature[]>(op
|
|
|
174
180
|
};
|
|
175
181
|
synced_theme?: boolean;
|
|
176
182
|
remote_access?: boolean;
|
|
183
|
+
desktop?: "daemon" | "portal";
|
|
177
184
|
phone?: "device" | "portal";
|
|
178
185
|
roles?: readonly string[];
|
|
186
|
+
check_access?: (value: unknown) => unknown;
|
|
179
187
|
sync?: boolean;
|
|
180
188
|
declared_tokens?: {
|
|
181
189
|
key: string;
|
package/dist/app/define.js
CHANGED
|
@@ -266,6 +266,7 @@ export function define_app(options) {
|
|
|
266
266
|
local_mcp: define_bridge(`${prefix}_local_mcp`, local_mcp_method_names),
|
|
267
267
|
events: define_events(`${prefix}_events`),
|
|
268
268
|
host: define_bridge(`${prefix}_host`, host_ability_method_names),
|
|
269
|
+
fetch: define_bridge(`${prefix}_fetch`, ["http_fetch"]),
|
|
269
270
|
// Letting other devices reach this computer's daemon, answered over its socket alone.
|
|
270
271
|
remote_access: define_bridge(`${prefix}_remote`, remote_access_method_names),
|
|
271
272
|
host_tables: Object.fromEntries(Object.entries(options.host_tables ?? {}).map(([name, table]) => [name, define_bridge(`${prefix}_${name}`, Object.keys(table.api))])),
|
package/dist/app/desktop.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// work to this computer's daemon or to a server chosen under Settings → Connections. The app hands in Electron, so this
|
|
3
3
|
// module builds without it.
|
|
4
4
|
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
5
|
-
import { unwatchFile, watchFile } from "node:fs";
|
|
5
|
+
import { existsSync, readFileSync, unwatchFile, watchFile } from "node:fs";
|
|
6
6
|
import { homedir, hostname } from "node:os";
|
|
7
7
|
import { writeFile } from "node:fs/promises";
|
|
8
8
|
import { extname, join, resolve } from "node:path";
|
|
@@ -24,9 +24,11 @@ import { peer_listening_method_names, sync_device_method_names } from "../sync_p
|
|
|
24
24
|
import { route_of_link } from "./links.js";
|
|
25
25
|
import { remote_access_method_names } from "../remote_access_protocol.js";
|
|
26
26
|
import { file_response, register_file_scheme } from "../electron/file_protocol.js";
|
|
27
|
+
import { create_main_fetch } from "../electron/fetch.js";
|
|
28
|
+
import { no_server_text, server_headers, server_url } from "./server_fetch.js";
|
|
27
29
|
import { folder_file_store } from "../node_file_store.js";
|
|
28
30
|
import { read_plugin_file } from "../plugin_folder.js";
|
|
29
|
-
import { file_scheme_of, host_ability_method_names, notice_event, notice_is_on, notice_withdrawn_event } from "./protocol.js";
|
|
31
|
+
import { file_scheme_of, host_ability_method_names, notice_event, read_desktop_settings, notice_is_on, notice_withdrawn_event } from "./protocol.js";
|
|
30
32
|
// The Save dialog's options for a file name: Downloads with that name, offering files of its kind.
|
|
31
33
|
export function save_dialog_options(file_name, downloads) {
|
|
32
34
|
const extension = extname(file_name).slice(1);
|
|
@@ -41,6 +43,8 @@ export function run_desktop(app, electron, options) {
|
|
|
41
43
|
const start = options.start_daemon ?? start_daemon;
|
|
42
44
|
const call_socket = options.call_daemon ?? call_daemon;
|
|
43
45
|
const write_autostart = options.set_autostart ?? set_autostart;
|
|
46
|
+
// A portal runs no daemon and keeps no data: it works on a server chosen under Connections.
|
|
47
|
+
const portal = app.desktop === "portal";
|
|
44
48
|
// ── Profile ──────────────────────────────────────────────────────────
|
|
45
49
|
// Dev runs set this so they never touch the installed app's data.
|
|
46
50
|
const own_profile = env[`${prefix}_USER_DATA`];
|
|
@@ -61,6 +65,8 @@ export function run_desktop(app, electron, options) {
|
|
|
61
65
|
// Opening the app replaces a daemon another build left running, such as one from before an upgrade. Only opening does:
|
|
62
66
|
// two windows of different builds that both replaced on reconnecting would stop each other's daemon in turn.
|
|
63
67
|
function ensure_daemon(replace_other_build = false) {
|
|
68
|
+
if (portal)
|
|
69
|
+
return Promise.resolve("portal");
|
|
64
70
|
// Only the user's own daemon reads what this computer's configuration declares, unless a run names a file itself.
|
|
65
71
|
const declared = is_own_profile ? {} : { [`${prefix}_DECLARED_FILE`]: env[`${prefix}_DECLARED_FILE`] ?? "" };
|
|
66
72
|
const own_env = options.daemon_env?.({ path: profile, is_own_profile }) ?? {};
|
|
@@ -83,7 +89,7 @@ export function run_desktop(app, electron, options) {
|
|
|
83
89
|
trust_certificates();
|
|
84
90
|
watchFile(certificates_file, { interval: 2000 }, trust_certificates);
|
|
85
91
|
// This computer's daemon, and servers each signed in once with a token of this device's own.
|
|
86
|
-
const connections = create_connections({ storage: connection_file_storage(join(profile, "connections.json")), offers_local:
|
|
92
|
+
const connections = create_connections({ storage: connection_file_storage(join(profile, "connections.json")), offers_local: !portal, device_name: `${app.name} on ${hostname()}` });
|
|
87
93
|
const link = create_daemon_link({ connections, socket_path });
|
|
88
94
|
const windows = () => BrowserWindow.getAllWindows();
|
|
89
95
|
// A daemon elsewhere tells of its notices as events; this computer shows them by its own switches, as its own
|
|
@@ -104,9 +110,11 @@ export function run_desktop(app, electron, options) {
|
|
|
104
110
|
const router = create_daemon_router({
|
|
105
111
|
connections,
|
|
106
112
|
link,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
...(portal ? {} : {
|
|
114
|
+
call_local: (path, args, headers) => call_socket(socket_path, path, args, headers),
|
|
115
|
+
restart_local: () => ensure_daemon(),
|
|
116
|
+
}),
|
|
117
|
+
local_tables: portal ? [] : [...default_local_tables, "peer_listening", "remote", ...own_tables],
|
|
110
118
|
is_read_only: app.is_read_only,
|
|
111
119
|
on_change: (change) => {
|
|
112
120
|
app.bridges.events.emit(windows(), "changed", change);
|
|
@@ -153,14 +161,38 @@ export function run_desktop(app, electron, options) {
|
|
|
153
161
|
if (synced_files && electron.protocol)
|
|
154
162
|
register_file_scheme(electron.protocol, file_scheme_of(app.id));
|
|
155
163
|
// This computer's own settings, always from its own daemon.
|
|
156
|
-
|
|
157
|
-
|
|
164
|
+
// A portal keeps them in the profile itself, as it runs no daemon to keep them.
|
|
165
|
+
const portal_settings_file = join(profile, "desktop.json");
|
|
166
|
+
async function get_desktop_settings() {
|
|
167
|
+
if (!portal)
|
|
168
|
+
return call("daemon/get_desktop_settings");
|
|
169
|
+
return read_desktop_settings(existsSync(portal_settings_file) ? JSON.parse(readFileSync(portal_settings_file, "utf8")) : null, app.desktop_settings);
|
|
170
|
+
}
|
|
171
|
+
async function set_desktop_setting(key, value) {
|
|
172
|
+
if (!portal)
|
|
173
|
+
return void (await call("daemon/set_desktop_setting", [key, value]));
|
|
174
|
+
await writeFile(portal_settings_file, JSON.stringify(read_desktop_settings({ ...(await get_desktop_settings()), [key]: value }, app.desktop_settings), null, 2));
|
|
175
|
+
}
|
|
176
|
+
// The page's request to its server's routes, sent to the server the window works on with this device's token.
|
|
177
|
+
const main_fetch = create_main_fetch({
|
|
178
|
+
get hosts() {
|
|
179
|
+
const daemon = connections.current();
|
|
180
|
+
return daemon?.kind === "remote" ? [new URL(daemon.address).host] : [];
|
|
181
|
+
},
|
|
182
|
+
allow_http: true,
|
|
183
|
+
});
|
|
184
|
+
function http_fetch(request) {
|
|
185
|
+
const daemon = connections.current();
|
|
186
|
+
if (daemon?.kind !== "remote")
|
|
187
|
+
throw new Error(no_server_text);
|
|
188
|
+
return main_fetch({ ...request, url: server_url(daemon.address, request.url), headers: server_headers(request.headers, daemon.token) });
|
|
158
189
|
}
|
|
159
190
|
// The tray as its setting says, and, for the user's own profile only, the login entry; a dev run never writes it.
|
|
160
191
|
async function apply_window_settings() {
|
|
161
192
|
const settings = await get_desktop_settings();
|
|
162
193
|
tray?.set_shown(settings.show_tray_icon);
|
|
163
|
-
|
|
194
|
+
// A portal has no daemon to start at login.
|
|
195
|
+
if (!is_own_profile || portal)
|
|
164
196
|
return;
|
|
165
197
|
write_autostart({ id: `${app.id}-daemon`, name: `${app.name} in the background`, comment: `Sync and backups for ${app.name}`, icon: icon_path, command: own_command(["--daemon"]) }, settings.start_at_login && settings.keep_running_in_background);
|
|
166
198
|
}
|
|
@@ -171,6 +203,8 @@ export function run_desktop(app, electron, options) {
|
|
|
171
203
|
};
|
|
172
204
|
// The daemon's services keep quiet, such as about notifications, while a window is in front.
|
|
173
205
|
function tell_in_front() {
|
|
206
|
+
if (portal)
|
|
207
|
+
return;
|
|
174
208
|
const in_front = windows().some((each) => each.isFocused() && each.isVisible());
|
|
175
209
|
void call("daemon/set_window_in_front", [in_front]).catch(() => undefined);
|
|
176
210
|
}
|
|
@@ -213,7 +247,8 @@ export function run_desktop(app, electron, options) {
|
|
|
213
247
|
// Stops the daemon as well, so nothing runs until the app is opened again.
|
|
214
248
|
async function quit_completely() {
|
|
215
249
|
router.quitting();
|
|
216
|
-
|
|
250
|
+
if (!portal)
|
|
251
|
+
await call("daemon/stop_daemon").catch(() => undefined);
|
|
217
252
|
electron.app.quit();
|
|
218
253
|
}
|
|
219
254
|
// ── Tray ───────────────────────────────────────────────────────────
|
|
@@ -274,12 +309,13 @@ export function run_desktop(app, electron, options) {
|
|
|
274
309
|
if (app.remote_access)
|
|
275
310
|
bridges.remote_access.handle(ipcMain, forwarded(remote_access_method_names, "remote"), handle_options);
|
|
276
311
|
bridges.host.handle(ipcMain, forwarded(host_ability_method_names, "host"), handle_options);
|
|
312
|
+
bridges.fetch.handle(ipcMain, { http_fetch }, handle_options);
|
|
277
313
|
for (const [name, bridge] of Object.entries(bridges.host_tables))
|
|
278
314
|
bridge.handle(ipcMain, forwarded(Object.keys(app.host_tables[name].api), name), handle_options);
|
|
279
315
|
const desktop = {
|
|
280
316
|
get_desktop_settings,
|
|
281
317
|
set_desktop_setting: async (key, value) => {
|
|
282
|
-
await
|
|
318
|
+
await set_desktop_setting(String(key), value);
|
|
283
319
|
await apply_window_settings();
|
|
284
320
|
},
|
|
285
321
|
quit_completely,
|
package/dist/app/preload.js
CHANGED
|
@@ -11,6 +11,7 @@ export function run_preload(app, { contextBridge, ipcRenderer }) {
|
|
|
11
11
|
if (app.remote_access)
|
|
12
12
|
bridges.remote_access.expose(contextBridge, ipcRenderer, { envelopes: true });
|
|
13
13
|
bridges.host.expose(contextBridge, ipcRenderer, { envelopes: true });
|
|
14
|
+
bridges.fetch.expose(contextBridge, ipcRenderer, { envelopes: true });
|
|
14
15
|
for (const bridge of Object.values(bridges.host_tables))
|
|
15
16
|
bridge.expose(contextBridge, ipcRenderer, { envelopes: true });
|
|
16
17
|
bridges.events.expose(contextBridge, ipcRenderer);
|
package/dist/app/protocol.d.ts
CHANGED
|
@@ -91,6 +91,7 @@ export interface PageApi<Methods extends Record<keyof Methods, (...args: never[]
|
|
|
91
91
|
};
|
|
92
92
|
reread_abilities?: () => Promise<Pick<PageApi, "admin" | "tables">>;
|
|
93
93
|
server_theme?: ServerTheme;
|
|
94
|
+
fetch?: typeof fetch;
|
|
94
95
|
file_src?: (name: string) => Promise<string>;
|
|
95
96
|
plugin_base?: string;
|
|
96
97
|
read_plugin_file?: (path: string) => Promise<string>;
|
package/dist/app/server.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { DatabaseSync } from "node:sqlite";
|
|
|
2
2
|
import { type FastifyInstance } from "fastify";
|
|
3
3
|
import { type MethodSpec } from "../api_spec.ts";
|
|
4
4
|
import { type BackupMethods } from "../backups.ts";
|
|
5
|
+
import { type ProxySignIn } from "../server/account_sign_in.ts";
|
|
5
6
|
import { OidcClient } from "../server/oidc.ts";
|
|
6
7
|
import { AccountStore } from "../server/account_store.ts";
|
|
7
8
|
import { type Channel } from "../server/notify/channels.ts";
|
|
@@ -51,6 +52,7 @@ export interface ServerOptions {
|
|
|
51
52
|
plugins_folder?: string | null;
|
|
52
53
|
files?: SyncFileStore | null;
|
|
53
54
|
second_factor_from?: string | null;
|
|
55
|
+
proxy?: ProxySignIn | null;
|
|
54
56
|
}
|
|
55
57
|
export declare const backup_tools: Record<"list_backups" | "create_backup" | "get_backup_schedule", MethodSpec>;
|
|
56
58
|
export declare const user_only_backup_calls: ReadonlySet<string>;
|
package/dist/app/server.js
CHANGED
|
@@ -225,7 +225,8 @@ export async function build_server(app, options) {
|
|
|
225
225
|
// A phone that keeps no data calls from a page of its own with a token, the sign-in included; the event stream
|
|
226
226
|
// writes its own head, so it carries the open origin itself.
|
|
227
227
|
if (app.phone === "portal") {
|
|
228
|
-
|
|
228
|
+
// An app built on its REST routes takes PUT and DELETE from its portals too.
|
|
229
|
+
await register_open_cors(server, { allowed_headers: sync_peer_headers, methods: ["GET", "POST", "PUT", "DELETE"] });
|
|
229
230
|
server.addHook("onRequest", async (request, reply) => {
|
|
230
231
|
if (request.url.split("?")[0] === "/api/events")
|
|
231
232
|
reply.raw.setHeader("access-control-allow-origin", "*");
|
|
@@ -245,6 +246,7 @@ export async function build_server(app, options) {
|
|
|
245
246
|
open_prefixes: options.routes?.open_prefixes ?? [],
|
|
246
247
|
guarded_paths: options.routes?.guarded_paths ?? [],
|
|
247
248
|
oidc: options.oidc ?? null,
|
|
249
|
+
proxy: options.proxy ?? null,
|
|
248
250
|
...(options.session_seconds !== undefined ? { session_seconds: options.session_seconds } : {}),
|
|
249
251
|
...(options.remembered_seconds !== undefined ? { remembered_seconds: options.remembered_seconds } : {}),
|
|
250
252
|
...(options.second_factor_from ? { second_factor_from: options.second_factor_from } : {}),
|
|
@@ -371,8 +373,9 @@ export async function run_server(app, options) {
|
|
|
371
373
|
app_name: app.name,
|
|
372
374
|
...(app.roles ? { roles: app.roles } : {}),
|
|
373
375
|
...(app.token_prefix ? { token_prefix: app.token_prefix } : {}),
|
|
376
|
+
...(app.check_access ? { check_access: app.check_access } : {}),
|
|
374
377
|
...(config.token_days !== undefined ? { longest_token_days: config.token_days } : {}),
|
|
375
|
-
declared: load_accounts(`${prefix}_PASSWORD_HASH_FILE`, server_config.values.password_hash_file),
|
|
378
|
+
declared: load_accounts(`${prefix}_PASSWORD_HASH_FILE`, server_config.values.password_hash_file, config.admin_name?.toLowerCase()),
|
|
376
379
|
declared_tokens: declared_tokens.filter((token) => token.role !== null),
|
|
377
380
|
});
|
|
378
381
|
const oidc_settings = oidc_from_environment(prefix, options.env ?? process.env);
|
|
@@ -407,6 +410,7 @@ export async function run_server(app, options) {
|
|
|
407
410
|
...(config.session_seconds !== undefined ? { session_seconds: config.session_seconds } : {}),
|
|
408
411
|
...(config.remembered_seconds !== undefined ? { remembered_seconds: config.remembered_seconds } : {}),
|
|
409
412
|
...(config.second_factor_from ? { second_factor_from: config.second_factor_from } : {}),
|
|
413
|
+
...(config.proxy_user_header ? { proxy: { header: config.proxy_user_header.toLowerCase(), trusted: new Set(config.trusted_proxies ?? ["127.0.0.1", "::1"]) } } : {}),
|
|
410
414
|
theme: read_server_theme(config.theme),
|
|
411
415
|
plugins_folder: config.plugins_folder ? resolve(config.plugins_folder) : null,
|
|
412
416
|
files,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const no_server_text = "No server is chosen yet. Choose one under Settings \u2192 Connections.";
|
|
2
|
+
export declare function server_url(address: string, requested: string): string;
|
|
3
|
+
export declare function server_headers(headers: Iterable<[string, string]>, token: string): [string, string][];
|
|
4
|
+
export declare function server_fetch(server: () => {
|
|
5
|
+
address: string;
|
|
6
|
+
token: string;
|
|
7
|
+
} | null, send?: typeof fetch): typeof fetch;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// A page's request to its own server's routes, such as "/api/runs?limit=5", sent from a portal on another device: the
|
|
2
|
+
// path under the server's address chosen under Connections, with this device's token in place of the page's own
|
|
3
|
+
// credentials. The desktop's main process and the phone's portal both send it so.
|
|
4
|
+
// ── Requests ─────────────────────────────────────────────────────────────────
|
|
5
|
+
export const no_server_text = "No server is chosen yet. Choose one under Settings → Connections.";
|
|
6
|
+
// The server's URL for a request the page made to its own origin; only the API is reached.
|
|
7
|
+
export function server_url(address, requested) {
|
|
8
|
+
const url = new URL(requested, "http://page.invalid");
|
|
9
|
+
// A relative path resolves against the page's own address, such as a desktop page's file:// one, so the route is
|
|
10
|
+
// read from its /api/ on.
|
|
11
|
+
const at = url.pathname.indexOf("/api/");
|
|
12
|
+
if (at === -1)
|
|
13
|
+
throw new Error(`${url.pathname} is not one of the server's routes.`);
|
|
14
|
+
return `${address.replace(/\/+$/, "")}${url.pathname.slice(at)}${url.search}`;
|
|
15
|
+
}
|
|
16
|
+
// The page's headers with this device's token in place of any credentials or origin the page's own request carried.
|
|
17
|
+
export function server_headers(headers, token) {
|
|
18
|
+
const dropped = new Set(["authorization", "cookie", "origin", "referer", "host"]);
|
|
19
|
+
const kept = [...headers].filter(([name]) => !dropped.has(name.toLowerCase()));
|
|
20
|
+
return [...kept, ["authorization", `Bearer ${token}`]];
|
|
21
|
+
}
|
|
22
|
+
// A fetch of the page's that goes to the server the connection names, or refuses while none is chosen.
|
|
23
|
+
export function server_fetch(server, send = fetch) {
|
|
24
|
+
return async (input, init) => {
|
|
25
|
+
const chosen = server();
|
|
26
|
+
if (!chosen)
|
|
27
|
+
throw new Error(no_server_text);
|
|
28
|
+
const request = new Request(new URL(String(input instanceof Request ? input.url : input), "http://page.invalid"), init);
|
|
29
|
+
const path = new URL(request.url);
|
|
30
|
+
return send(server_url(chosen.address, `${path.pathname}${path.search}`), {
|
|
31
|
+
method: request.method,
|
|
32
|
+
headers: server_headers(request.headers.entries(), chosen.token),
|
|
33
|
+
body: request.method === "GET" || request.method === "HEAD" ? null : await request.arrayBuffer(),
|
|
34
|
+
...(init?.signal ? { signal: init.signal } : {}),
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
package/dist/app/web/hosts.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Where the page runs and how it reaches the data there: a browser posts every call to the server it was loaded from
|
|
2
2
|
// and follows its event stream; the desktop app's preload has put the main process's calls on the window, which go to
|
|
3
3
|
// this computer's daemon or to the server Settings → Connections chose.
|
|
4
|
+
import { create_page_fetch } from "../../electron/fetch.js";
|
|
4
5
|
import { LOCAL_CONNECTION_ID } from "../../connection_protocol.js";
|
|
5
6
|
import { LoginNeeded } from "../../web/states.js";
|
|
6
7
|
import { data_change_of, desktop_plugin_base, file_scheme_of } from "../protocol.js";
|
|
@@ -107,6 +108,8 @@ export function web_api(app) {
|
|
|
107
108
|
backups: bridges.backups.web_rpc((method, args) => post_call(backups_path, method, args)),
|
|
108
109
|
...(app.synced_files ? { file_src: async (name) => `api/files/${encodeURIComponent(name)}` } : {}),
|
|
109
110
|
plugin_base: "api/plugins/",
|
|
111
|
+
// The server's own routes, with the browser's sign-in.
|
|
112
|
+
fetch: (input, init) => fetch(input, init),
|
|
110
113
|
on_change: (listener) => {
|
|
111
114
|
listeners.add(listener);
|
|
112
115
|
return () => listeners.delete(listener);
|
|
@@ -154,6 +157,8 @@ export async function desktop_api(app) {
|
|
|
154
157
|
...(app.synced_files && app.id ? { file_src: async (name) => `${file_scheme_of(app.id)}://${name}` } : {}),
|
|
155
158
|
plugin_base: desktop_plugin_base,
|
|
156
159
|
read_plugin_file: (path) => desktop.read_plugin_file(path),
|
|
160
|
+
// The routes of the server the window works on, sent on by the main process with this device's token.
|
|
161
|
+
...(exposed[bridges.fetch.api_name] ? { fetch: create_page_fetch((request) => exposed[bridges.fetch.api_name].http_fetch(request)) } : {}),
|
|
157
162
|
on_change: (listener) => events.on("changed", listener),
|
|
158
163
|
on_event: (event, listener) => events.on("app_event", (sent) => sent.event === event && listener(sent.data)),
|
|
159
164
|
};
|
package/dist/app/web/portal.js
CHANGED
|
@@ -11,6 +11,7 @@ import { call_remote, follow_remote } from "../../web/remote_daemon.js";
|
|
|
11
11
|
import { route_of_link } from "../links.js";
|
|
12
12
|
import { data_change_of, notice_event, notice_is_on, notice_withdrawn_event } from "../protocol.js";
|
|
13
13
|
import { host_tables_of, read_host_abilities } from "./hosts.js";
|
|
14
|
+
import { server_fetch } from "../server_fetch.js";
|
|
14
15
|
// ── Switches ─────────────────────────────────────────────────────────────────
|
|
15
16
|
// The notice switches this phone keeps, each of the app's `notify_` desktop switches at its default where unset.
|
|
16
17
|
export function read_notice_switches(app, saved) {
|
|
@@ -100,6 +101,8 @@ export async function portal_api(app, options) {
|
|
|
100
101
|
return {
|
|
101
102
|
host: "android",
|
|
102
103
|
calls: bridges.calls.web_rpc(rpc("call")),
|
|
104
|
+
// The routes of the host this phone works on, with its token.
|
|
105
|
+
fetch: server_fetch(link.daemon, options.fetch ?? ((input, init) => fetch(input, init))),
|
|
103
106
|
device: null,
|
|
104
107
|
// The host's backups, which only an admin there reaches.
|
|
105
108
|
backups: abilities.admin ? bridges.backups.web_rpc(rpc("backups")) : null,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IconGlyph } from "../../web/react/icons.tsx";
|
|
2
2
|
import type { AccountsClient, Me } from "../../web/accounts.ts";
|
|
3
|
+
import { type AccessEditor } from "../../web/react/accounts.tsx";
|
|
3
4
|
import { type SettingsCategory, type SettingsSection } from "../../web/react/layout.tsx";
|
|
4
5
|
import type { ShellSidePane, SidebarWidth } from "../../web/react/shell.tsx";
|
|
5
6
|
import type { LocalNotificationsLike } from "../../phone_notices.ts";
|
|
@@ -50,6 +51,8 @@ export interface AppPages {
|
|
|
50
51
|
remote_access_reach?: string;
|
|
51
52
|
exports_secrets?: boolean;
|
|
52
53
|
role_text?: Readonly<Record<string, string>>;
|
|
54
|
+
access_text?: (access: unknown) => string;
|
|
55
|
+
access_editor?: AccessEditor;
|
|
53
56
|
}
|
|
54
57
|
export interface SettingsViewer {
|
|
55
58
|
client: AccountsClient;
|
|
@@ -116,7 +116,12 @@ function storage_category(pages, is_admin) {
|
|
|
116
116
|
function users_category(pages, viewer) {
|
|
117
117
|
if (viewer === null)
|
|
118
118
|
return [];
|
|
119
|
-
const sections = users_settings({
|
|
119
|
+
const sections = users_settings({
|
|
120
|
+
client: viewer.client, me: viewer.me,
|
|
121
|
+
...(pages.role_text ? { role_text: pages.role_text } : {}),
|
|
122
|
+
...(pages.access_text ? { access_text: pages.access_text } : {}),
|
|
123
|
+
...(pages.access_editor ? { access_editor: pages.access_editor } : {}),
|
|
124
|
+
});
|
|
120
125
|
return sections.length > 0 ? [{ heading: "Users", sections }] : [];
|
|
121
126
|
}
|
|
122
127
|
export function SettingsView({ pages, is_admin = true, viewer = null }) {
|
|
@@ -147,7 +147,16 @@ export class AccountStore {
|
|
|
147
147
|
this.app_name = options.app_name;
|
|
148
148
|
this.roles = options.roles ?? default_roles;
|
|
149
149
|
this.declared = options.declared ?? new Map();
|
|
150
|
-
|
|
150
|
+
// An app's own check may throw a plain Error, such as one defined beside its page; it is refused as an account error.
|
|
151
|
+
const check = options.check_access ?? only_everything;
|
|
152
|
+
this.check_access = (value) => {
|
|
153
|
+
try {
|
|
154
|
+
return check(value);
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
throw error instanceof AccountError ? error : new AccountError(error instanceof Error ? error.message : String(error));
|
|
158
|
+
}
|
|
159
|
+
};
|
|
151
160
|
this.token_prefix = options.token_prefix ?? "xt";
|
|
152
161
|
this.shortest_password = options.shortest_password ?? 12;
|
|
153
162
|
this.declared_token_list = options.declared_tokens ?? [];
|
|
@@ -33,6 +33,6 @@ export declare class PasswordHashSlots {
|
|
|
33
33
|
private in_slot;
|
|
34
34
|
}
|
|
35
35
|
export declare const shared_password_hashes: PasswordHashSlots;
|
|
36
|
-
export declare function parse_accounts(text: string, source?: string): Accounts;
|
|
37
|
-
export declare function load_accounts(variable: string, file_path?: string | undefined): Accounts;
|
|
36
|
+
export declare function parse_accounts(text: string, source?: string, bare_name?: string): Accounts;
|
|
37
|
+
export declare function load_accounts(variable: string, file_path?: string | undefined, bare_name?: string): Accounts;
|
|
38
38
|
export declare function set_account(text: string, name: string, stored: string): string;
|
package/dist/server/passwords.js
CHANGED
|
@@ -95,14 +95,14 @@ export class PasswordHashSlots {
|
|
|
95
95
|
export const shared_password_hashes = new PasswordHashSlots();
|
|
96
96
|
// ── Accounts file ────────────────────────────────────────────────────────────
|
|
97
97
|
// Reads `name:hash` lines, skipping blank lines and `#` comments.
|
|
98
|
-
export function parse_accounts(text, source = "the accounts file") {
|
|
98
|
+
export function parse_accounts(text, source = "the accounts file", bare_name = default_account_name) {
|
|
99
99
|
const accounts = new Map();
|
|
100
100
|
for (const [index, raw_line] of text.split("\n").entries()) {
|
|
101
101
|
const line = raw_line.trim();
|
|
102
102
|
if (line === "" || line.startsWith("#"))
|
|
103
103
|
continue;
|
|
104
104
|
const separator = line.indexOf(":");
|
|
105
|
-
const name = separator === -1 ?
|
|
105
|
+
const name = separator === -1 ? bare_name : line.slice(0, separator);
|
|
106
106
|
const stored = separator === -1 ? line : line.slice(separator + 1);
|
|
107
107
|
const where = `${source} line ${index + 1}`;
|
|
108
108
|
if (!account_name_pattern.test(name))
|
|
@@ -116,10 +116,11 @@ export function parse_accounts(text, source = "the accounts file") {
|
|
|
116
116
|
return accounts;
|
|
117
117
|
}
|
|
118
118
|
// The accounts in the file the environment variable names, such as X_NIX_PASSWORD_HASH_FILE.
|
|
119
|
-
|
|
119
|
+
// A line holding a hash alone is the admin named bare_name, "admin" unless set.
|
|
120
|
+
export function load_accounts(variable, file_path = process.env[variable], bare_name = default_account_name) {
|
|
120
121
|
if (!file_path)
|
|
121
122
|
throw new Error(`${variable} is not set; create one with \`npm run hash-password -- <name> <file>\`.`);
|
|
122
|
-
const accounts = parse_accounts(readFileSync(file_path, "utf8"), file_path);
|
|
123
|
+
const accounts = parse_accounts(readFileSync(file_path, "utf8"), file_path, bare_name);
|
|
123
124
|
if (accounts.size === 0)
|
|
124
125
|
throw new Error(`${file_path} holds no users; add one with \`npm run hash-password -- <name> ${file_path}\`.`);
|
|
125
126
|
return accounts;
|
package/dist/site/build.js
CHANGED
|
@@ -16,7 +16,7 @@ import { pathToFileURL } from "node:url";
|
|
|
16
16
|
import { build, createServer, preview } from "vite";
|
|
17
17
|
import { text_direction } from "../i18n.js";
|
|
18
18
|
import { read_content } from "./content.js";
|
|
19
|
-
import {
|
|
19
|
+
import { mdx_plugin } from "./markdown.js";
|
|
20
20
|
import { build_sidebar, extract_headings, neighbours, page_path, plan_routes, root_locale, site_locales, with_base, } from "./model.js";
|
|
21
21
|
import { messages_for } from "./ui_strings.js";
|
|
22
22
|
// ── The project ──────────────────────────────────────────────────────────────
|
|
@@ -106,8 +106,8 @@ export function page_data(project, plan, route, locale = route?.locale ?? root_l
|
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
// ── Vite ─────────────────────────────────────────────────────────────────────
|
|
109
|
-
// The entries Vite starts from: the page modules by content file, the browser's entry with the site's stylesheets
|
|
110
|
-
//
|
|
109
|
+
// The entries Vite starts from: the page modules by content file, the browser's entry with the site's stylesheets, and the
|
|
110
|
+
// server's; written only when they change, so the dev server does not
|
|
111
111
|
// reload for nothing.
|
|
112
112
|
export function write_entries(project, plan) {
|
|
113
113
|
mkdirSync(project.work_folder, { recursive: true });
|
|
@@ -117,13 +117,9 @@ export function write_entries(project, plan) {
|
|
|
117
117
|
};
|
|
118
118
|
const page_lines = plan.pages.map((page) => ` ${JSON.stringify(page.id)}: () => import(${JSON.stringify(from_work(join(project.content_folder, page.id)))}),`);
|
|
119
119
|
const css_lines = (project.config.css ?? []).map((sheet) => `import ${JSON.stringify(sheet.startsWith(".") ? from_work(resolve(project.root, sheet)) : sheet)};`);
|
|
120
|
-
const draws_diagrams = plan.pages.some((page) => has_mermaid(readFileSync(join(project.content_folder, page.id), "utf8")));
|
|
121
|
-
const start = draws_diagrams
|
|
122
|
-
? `import { mermaid_drawer } from "@x-tech-laboratories/x-app/web/site/mermaid";\nimport { pages } from "./pages.js";\n\nstart_site(pages, { draw_diagram: mermaid_drawer(() => import("mermaid")) });\n`
|
|
123
|
-
: `import { pages } from "./pages.js";\n\nstart_site(pages);\n`;
|
|
124
120
|
const files = {
|
|
125
121
|
"pages.js": `export const pages = {\n${page_lines.join("\n")}\n};\n`,
|
|
126
|
-
"client.js": `${css_lines.join("\n")}\nimport { start_site } from "@x-tech-laboratories/x-app/web/site/client";\
|
|
122
|
+
"client.js": `${css_lines.join("\n")}\nimport { start_site } from "@x-tech-laboratories/x-app/web/site/client";\nimport { pages } from "./pages.js";\n\nstart_site(pages);\n`,
|
|
127
123
|
"server.js": `export { load_content, render_content, render_page } from "@x-tech-laboratories/x-app/web/site/server";\nexport { pages } from "./pages.js";\n`,
|
|
128
124
|
".gitignore": "*\n",
|
|
129
125
|
};
|
package/dist/site/markdown.d.ts
CHANGED
|
@@ -4,6 +4,4 @@ import type { Plugin } from "vite";
|
|
|
4
4
|
export declare function rehype_base_links(base: string): (tree: Root) => void;
|
|
5
5
|
export declare function remark_github_alerts(): (tree: MarkdownRoot) => void;
|
|
6
6
|
export declare function remark_drop_title_heading(): (tree: MarkdownRoot) => void;
|
|
7
|
-
export declare function rehype_mermaid_blocks(): (tree: Root) => void;
|
|
8
|
-
export declare function has_mermaid(text: string): boolean;
|
|
9
7
|
export declare function mdx_plugin(base: string): Plugin;
|
package/dist/site/markdown.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// How a site's Markdown and MDX become pages, on MDX's own compiler: GitHub's tables, task lists, autolinks, alerts
|
|
2
2
|
// and raw HTML, frontmatter and a leading title heading kept out of the page, an id and an anchor link on every heading, code coloured by Shiki through Halon's
|
|
3
|
-
// tokens,
|
|
3
|
+
// tokens, and links within the site moved under its base.
|
|
4
4
|
import mdx from "@mdx-js/rollup";
|
|
5
5
|
import rehype_shiki from "@shikijs/rehype";
|
|
6
6
|
import rehype_autolink_headings from "rehype-autolink-headings";
|
|
@@ -76,24 +76,6 @@ export function remark_drop_title_heading() {
|
|
|
76
76
|
tree.children.splice(index, 1);
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
-
// A ```mermaid block kept as its source in a marked <pre>, which the page draws as a diagram and Shiki leaves alone.
|
|
80
|
-
export function rehype_mermaid_blocks() {
|
|
81
|
-
return (tree) => {
|
|
82
|
-
visit(tree, "element", (node) => {
|
|
83
|
-
const code = node.tagName === "pre" ? node.children.find((child) => child.type === "element" && child.tagName === "code") : undefined;
|
|
84
|
-
const classes = code?.properties.className;
|
|
85
|
-
if (!code || !Array.isArray(classes) || !classes.includes("language-mermaid"))
|
|
86
|
-
return;
|
|
87
|
-
const source = code.children.map((child) => (child.type === "text" ? child.value : "")).join("");
|
|
88
|
-
node.properties = { dataMermaid: "" };
|
|
89
|
-
node.children = [{ type: "text", value: source }];
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
// Whether a page's Markdown holds a ```mermaid block, so the site's browser entry loads mermaid.
|
|
94
|
-
export function has_mermaid(text) {
|
|
95
|
-
return /^[ \t]*(```|~~~)[ \t]*mermaid\b/m.test(text);
|
|
96
|
-
}
|
|
97
79
|
// MDX's own nodes, which raw HTML parsing must pass through untouched.
|
|
98
80
|
const mdx_node_types = ["mdxFlowExpression", "mdxJsxFlowElement", "mdxJsxTextElement", "mdxTextExpression", "mdxjsEsm"];
|
|
99
81
|
export function mdx_plugin(base) {
|
|
@@ -104,7 +86,6 @@ export function mdx_plugin(base) {
|
|
|
104
86
|
[rehype_raw, { passThrough: mdx_node_types }],
|
|
105
87
|
rehype_slug,
|
|
106
88
|
[rehype_autolink_headings, { behavior: "append", properties: { className: ["heading-anchor"], ariaHidden: "true", tabIndex: -1, dataPagefindIgnore: "" }, content: { type: "text", value: "#" } }],
|
|
107
|
-
rehype_mermaid_blocks,
|
|
108
89
|
[rehype_shiki, { theme: halon_code_theme, defaultLanguage: "text", fallbackLanguage: "text" }],
|
|
109
90
|
[rehype_base_links, base],
|
|
110
91
|
],
|
package/dist/web/react/site.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type ComponentType, type ReactNode } from "react";
|
|
2
2
|
import { type NavItem, type PageData } from "../../site/model.ts";
|
|
3
|
-
import type { DiagramDrawer } from "../site/mermaid.ts";
|
|
4
3
|
import { type SearchHit } from "./search_dialog.tsx";
|
|
5
4
|
export type { PageData } from "../../site/model.ts";
|
|
6
5
|
export declare function use_site_page(): PageData;
|
|
@@ -11,9 +10,8 @@ interface SitePageProps {
|
|
|
11
10
|
page: PageData;
|
|
12
11
|
Content: PageContent;
|
|
13
12
|
search?: (query: string) => Promise<SearchHit[]>;
|
|
14
|
-
draw_diagram?: DiagramDrawer;
|
|
15
13
|
}
|
|
16
|
-
export declare function SitePage({ page, Content, search
|
|
14
|
+
export declare function SitePage({ page, Content, search }: SitePageProps): import("react").JSX.Element;
|
|
17
15
|
export declare function SiteNav({ items, current }: {
|
|
18
16
|
items: NavItem[];
|
|
19
17
|
current: string;
|
package/dist/web/react/site.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
// A static site's page in the X-apps' frame: the Shell with the site's sidebar, search, links and language picker in
|
|
3
3
|
// the top bar, the page's outline beside it, and edit, date and previous and next links at its foot. The pieces a page's
|
|
4
4
|
// MDX can use, such as cards and asides, are here too.
|
|
5
|
-
import { createContext, useContext,
|
|
5
|
+
import { createContext, useContext, useMemo, useState } from "react";
|
|
6
6
|
import { with_base } from "../../site/model.js";
|
|
7
7
|
import { create_translator } from "../../i18n.js";
|
|
8
8
|
import { theme_choice } from "../theme.js";
|
|
@@ -19,50 +19,7 @@ export function use_site_page() {
|
|
|
19
19
|
throw new Error("Site content is drawn outside a SitePage.");
|
|
20
20
|
return page;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
const DiagramDrawing = createContext(null);
|
|
24
|
-
// Whether the page shows its dark scheme: the theme picked, else the system's, followed as either changes.
|
|
25
|
-
function use_dark_page() {
|
|
26
|
-
return useSyncExternalStore((changed) => {
|
|
27
|
-
const media = matchMedia("(prefers-color-scheme: dark)");
|
|
28
|
-
const observer = new MutationObserver(changed);
|
|
29
|
-
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
|
|
30
|
-
media.addEventListener("change", changed);
|
|
31
|
-
return () => {
|
|
32
|
-
observer.disconnect();
|
|
33
|
-
media.removeEventListener("change", changed);
|
|
34
|
-
};
|
|
35
|
-
}, () => {
|
|
36
|
-
const theme = document.documentElement.dataset.theme;
|
|
37
|
-
return theme === undefined ? matchMedia("(prefers-color-scheme: dark)").matches : theme === "dark";
|
|
38
|
-
}, () => false);
|
|
39
|
-
}
|
|
40
|
-
// A ```mermaid block: its source until the page has drawn it, then the diagram, drawn again when the scheme changes.
|
|
41
|
-
function Diagram({ source }) {
|
|
42
|
-
const draw = useContext(DiagramDrawing);
|
|
43
|
-
const dark = use_dark_page();
|
|
44
|
-
const [svg, set_svg] = useState(null);
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
if (draw === null)
|
|
47
|
-
return;
|
|
48
|
-
let shown = true;
|
|
49
|
-
draw(source, dark).then((drawn) => shown && set_svg(drawn), () => shown && set_svg(null));
|
|
50
|
-
return () => {
|
|
51
|
-
shown = false;
|
|
52
|
-
};
|
|
53
|
-
}, [draw, source, dark]);
|
|
54
|
-
if (svg === null)
|
|
55
|
-
return _jsx("pre", { className: "site-diagram-source", "data-pagefind-ignore": "", children: source });
|
|
56
|
-
return _jsx("div", { className: "site-diagram", "data-pagefind-ignore": "", dangerouslySetInnerHTML: { __html: svg } });
|
|
57
|
-
}
|
|
58
|
-
// A Markdown <pre>: a diagram when the build marked it as mermaid, else code as it is.
|
|
59
|
-
function SitePre({ "data-mermaid": mermaid, ...props }) {
|
|
60
|
-
if (mermaid === undefined)
|
|
61
|
-
return _jsx("pre", { ...props });
|
|
62
|
-
return _jsx(Diagram, { source: typeof props.children === "string" ? props.children : String(props.children ?? "") });
|
|
63
|
-
}
|
|
64
|
-
const content_components = { pre: SitePre };
|
|
65
|
-
export function SitePage({ page, Content, search, draw_diagram }) {
|
|
22
|
+
export function SitePage({ page, Content, search }) {
|
|
66
23
|
const t = create_translator(page.ui);
|
|
67
24
|
const theme = useMemo(() => theme_choice(page.site.theme_key), [page.site.theme_key]);
|
|
68
25
|
const [is_searching, set_searching] = useState(false);
|
|
@@ -77,7 +34,7 @@ export function SitePage({ page, Content, search, draw_diagram }) {
|
|
|
77
34
|
change_theme: t("change_theme"),
|
|
78
35
|
};
|
|
79
36
|
const tools = (_jsxs("div", { className: "site-tools", children: [search && page.site.search && _jsx(SearchButton, { label: t("search"), on_open: () => set_searching(true) }), _jsxs("div", { className: "site-tools-end", children: [_jsx(SocialLinks, { links: page.site.social }), _jsx(LanguagePicker, { page: page, label: t("language") })] })] }));
|
|
80
|
-
return (
|
|
37
|
+
return (_jsxs(SiteData.Provider, { value: page, children: [_jsx(Shell, { brand: page.site.title, brand_icon: page.site.logo_replaces_title ? undefined : page.site.logo, brand_logo: page.site.logo_replaces_title ? page.site.logo : undefined, brand_href: page.site.home, sidebar: _jsx(SiteNav, { items: page.nav, current: page.href }), theme: theme, tools: tools, labels: labels, view_key: page.href, children: page.template === "splash" ? _jsx(SplashLayout, { page: page, Content: Content, t: t }) : _jsx(DocLayout, { page: page, Content: Content, t: t }) }), is_searching && search && (_jsx(SearchDialog, { search: search, on_close: () => set_searching(false), labels: { title: t("search_title"), placeholder: t("search_placeholder"), no_results: t("search_no_results"), searching: t("search_searching") } }))] }));
|
|
81
38
|
}
|
|
82
39
|
// Search indexes only a page's own words, so the missing-page page and one shown in the default language for want of a
|
|
83
40
|
// translation are left out.
|
|
@@ -87,11 +44,11 @@ function search_body(page) {
|
|
|
87
44
|
function DocLayout({ page, Content, t }) {
|
|
88
45
|
const has_outline = page.toc && page.headings.length > 0;
|
|
89
46
|
const outline = [{ heading: t("on_this_page"), items: page.headings.map((heading) => ({ target: heading.id, label: heading.text, level: heading.level })) }];
|
|
90
|
-
return (_jsxs("div", { className: has_outline ? "site-page with-outline" : "site-page", children: [_jsxs("div", { className: "site-main", children: [has_outline && (_jsxs("details", { className: "site-outline-narrow", children: [_jsx("summary", { children: t("on_this_page") }), _jsx(Outline, { groups: [{ items: outline[0].items }], label: t("on_this_page"), update_hash: true })] })), _jsxs("article", { className: "site-article", ...search_body(page), children: [_jsx("h1", { className: "site-title", children: page.title }), page.description && _jsx("p", { className: "site-lead", children: page.description }), page.fallback_language && _jsx("p", { className: "banner site-notice", children: t("not_translated", { language: page.fallback_language }) }), _jsx("div", { className: "markdown site-content", children: _jsx(Content, {
|
|
47
|
+
return (_jsxs("div", { className: has_outline ? "site-page with-outline" : "site-page", children: [_jsxs("div", { className: "site-main", children: [has_outline && (_jsxs("details", { className: "site-outline-narrow", children: [_jsx("summary", { children: t("on_this_page") }), _jsx(Outline, { groups: [{ items: outline[0].items }], label: t("on_this_page"), update_hash: true })] })), _jsxs("article", { className: "site-article", ...search_body(page), children: [_jsx("h1", { className: "site-title", children: page.title }), page.description && _jsx("p", { className: "site-lead", children: page.description }), page.fallback_language && _jsx("p", { className: "banner site-notice", children: t("not_translated", { language: page.fallback_language }) }), _jsx("div", { className: "markdown site-content", children: _jsx(Content, {}) })] }), _jsx(PageFoot, { page: page, t: t })] }), has_outline && (_jsx("aside", { className: "site-outline", children: _jsx(Outline, { groups: outline, label: t("on_this_page"), update_hash: true }) }))] }));
|
|
91
48
|
}
|
|
92
49
|
function SplashLayout({ page, Content, t }) {
|
|
93
50
|
const hero = page.hero ?? {};
|
|
94
|
-
return (_jsx("div", { className: "site-page splash", children: _jsxs("div", { className: "site-main", children: [_jsxs("article", { className: "site-article", ...search_body(page), children: [_jsxs("header", { className: "site-hero", children: [_jsxs("div", { className: "site-hero-text", children: [_jsx("h1", { className: "site-title", children: hero.title ?? page.title }), (hero.tagline ?? page.description) && _jsx("p", { className: "site-hero-tagline", children: hero.tagline ?? page.description }), hero.actions && hero.actions.length > 0 && (_jsx("div", { className: "site-hero-actions", children: hero.actions.map((action) => (_jsx("a", { href: with_base(page.base, action.link), className: action_class(action.variant), children: action.text }, action.link))) }))] }), hero.image && _jsx("img", { className: "site-hero-image", src: hero.image, alt: "" })] }), page.fallback_language && _jsx("p", { className: "banner site-notice", children: t("not_translated", { language: page.fallback_language }) }), _jsx("div", { className: "markdown site-content", children: _jsx(Content, {
|
|
51
|
+
return (_jsx("div", { className: "site-page splash", children: _jsxs("div", { className: "site-main", children: [_jsxs("article", { className: "site-article", ...search_body(page), children: [_jsxs("header", { className: "site-hero", children: [_jsxs("div", { className: "site-hero-text", children: [_jsx("h1", { className: "site-title", children: hero.title ?? page.title }), (hero.tagline ?? page.description) && _jsx("p", { className: "site-hero-tagline", children: hero.tagline ?? page.description }), hero.actions && hero.actions.length > 0 && (_jsx("div", { className: "site-hero-actions", children: hero.actions.map((action) => (_jsx("a", { href: with_base(page.base, action.link), className: action_class(action.variant), children: action.text }, action.link))) }))] }), hero.image && _jsx("img", { className: "site-hero-image", src: hero.image, alt: "" })] }), page.fallback_language && _jsx("p", { className: "banner site-notice", children: t("not_translated", { language: page.fallback_language }) }), _jsx("div", { className: "markdown site-content", children: _jsx(Content, {}) })] }), _jsx(PageFoot, { page: page, t: t })] }) }));
|
|
95
52
|
}
|
|
96
53
|
function action_class(variant = "primary") {
|
|
97
54
|
return variant === "primary" ? "button accent solid" : variant === "secondary" ? "button" : "button minimal";
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import type { DiagramDrawer } from "./mermaid.ts";
|
|
2
1
|
import { type PageModules } from "./pages.ts";
|
|
3
|
-
export
|
|
4
|
-
draw_diagram?: DiagramDrawer;
|
|
5
|
-
}
|
|
6
|
-
export declare function start_site(pages: PageModules, options?: SiteOptions): Promise<void>;
|
|
2
|
+
export declare function start_site(pages: PageModules): Promise<void>;
|
package/dist/web/site/client.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
// Picks up a page the build drew, so its search, outline, menus
|
|
2
|
+
// Picks up a page the build drew, so its search, outline, menus and theme work in the browser.
|
|
3
3
|
import { hydrateRoot } from "react-dom/client";
|
|
4
4
|
import { NotFound, SitePage } from "../react/site.js";
|
|
5
5
|
import { pagefind_search } from "./pagefind.js";
|
|
6
6
|
import { load_content } from "./pages.js";
|
|
7
|
-
export async function start_site(pages
|
|
7
|
+
export async function start_site(pages) {
|
|
8
8
|
const page = JSON.parse(document.getElementById("x-site-page").textContent);
|
|
9
9
|
const Content = (await load_content(pages, page.source)) ?? NotFound;
|
|
10
|
-
hydrateRoot(document.getElementById("root"), _jsx(SitePage, { page: page, Content: Content, search: pagefind_search(page.base, page.ui.search_unavailable)
|
|
10
|
+
hydrateRoot(document.getElementById("root"), _jsx(SitePage, { page: page, Content: Content, search: pagefind_search(page.base, page.ui.search_unavailable) }));
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-tech-laboratories/x-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.128.0",
|
|
4
4
|
"description": "Code the X-apps share: agents and their long runs, passwords and sign-in, the Fastify server pieces, durations, and the web page's helpers and widgets",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -61,7 +61,6 @@
|
|
|
61
61
|
"electron-builder": "^26.18.0",
|
|
62
62
|
"electron-vite": "^6.0.0",
|
|
63
63
|
"fastify": "^5.12.7",
|
|
64
|
-
"mermaid": "^11.0.0",
|
|
65
64
|
"nodemailer": "^10.3.1",
|
|
66
65
|
"pagefind": "^1.6.0",
|
|
67
66
|
"react": "^19",
|
|
@@ -138,9 +137,6 @@
|
|
|
138
137
|
"fastify": {
|
|
139
138
|
"optional": true
|
|
140
139
|
},
|
|
141
|
-
"mermaid": {
|
|
142
|
-
"optional": true
|
|
143
|
-
},
|
|
144
140
|
"nodemailer": {
|
|
145
141
|
"optional": true
|
|
146
142
|
},
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export interface MermaidModule {
|
|
2
|
-
initialize(config: Record<string, unknown>): void;
|
|
3
|
-
render(id: string, text: string): Promise<{
|
|
4
|
-
svg: string;
|
|
5
|
-
}>;
|
|
6
|
-
}
|
|
7
|
-
export type DiagramDrawer = (source: string, dark: boolean) => Promise<string>;
|
|
8
|
-
export declare function mermaid_theme(read: (token: string) => string, dark: boolean): Record<string, unknown>;
|
|
9
|
-
export declare function mermaid_drawer(load: () => Promise<{
|
|
10
|
-
default: MermaidModule;
|
|
11
|
-
}>): DiagramDrawer;
|
package/dist/web/site/mermaid.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// Draws a site's ```mermaid blocks with mermaid, coloured by Halon's tokens for the scheme the page shows. The site's
|
|
2
|
-
// browser entry hands in its own import of mermaid, so X-App never needs it and sites without diagrams never load it.
|
|
3
|
-
// ── Colours ──────────────────────────────────────────────────────────────────
|
|
4
|
-
// Mermaid's theme variables from the page's Halon tokens, as the current scheme sets them.
|
|
5
|
-
export function mermaid_theme(read, dark) {
|
|
6
|
-
const surface = read("--surface-default") || (dark ? "#16213a" : "#ffffff");
|
|
7
|
-
const panel = read("--surface-secondary") || (dark ? "#060b14" : "#f1f5f9");
|
|
8
|
-
const text = read("--text-body") || (dark ? "#e2e8f0" : "#1a1a2e");
|
|
9
|
-
const muted = read("--text-secondary") || (dark ? "#cbd5e1" : "#475569");
|
|
10
|
-
const border = read("--border-default") || (dark ? "#334155" : "#e2e8f0");
|
|
11
|
-
return {
|
|
12
|
-
darkMode: dark,
|
|
13
|
-
background: surface,
|
|
14
|
-
fontFamily: read("--font-family-interface") || "Noto Sans, sans-serif",
|
|
15
|
-
fontSize: "14px",
|
|
16
|
-
primaryColor: panel,
|
|
17
|
-
primaryTextColor: text,
|
|
18
|
-
primaryBorderColor: muted,
|
|
19
|
-
secondaryColor: surface,
|
|
20
|
-
tertiaryColor: panel,
|
|
21
|
-
lineColor: muted,
|
|
22
|
-
textColor: text,
|
|
23
|
-
mainBkg: panel,
|
|
24
|
-
nodeBorder: muted,
|
|
25
|
-
clusterBkg: surface,
|
|
26
|
-
clusterBorder: border,
|
|
27
|
-
edgeLabelBackground: surface,
|
|
28
|
-
noteBkgColor: panel,
|
|
29
|
-
noteTextColor: text,
|
|
30
|
-
noteBorderColor: border,
|
|
31
|
-
actorBkg: panel,
|
|
32
|
-
actorBorder: muted,
|
|
33
|
-
actorTextColor: text,
|
|
34
|
-
signalColor: text,
|
|
35
|
-
signalTextColor: text,
|
|
36
|
-
labelBoxBkgColor: panel,
|
|
37
|
-
labelTextColor: text,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
// ── Drawing ──────────────────────────────────────────────────────────────────
|
|
41
|
-
// A drawer that loads mermaid on its first diagram and sets its colours again whenever the scheme changes; diagrams
|
|
42
|
-
// are drawn one at a time, since mermaid's settings are shared by every diagram.
|
|
43
|
-
export function mermaid_drawer(load) {
|
|
44
|
-
let loading = null;
|
|
45
|
-
let scheme = null;
|
|
46
|
-
let count = 0;
|
|
47
|
-
let queue = Promise.resolve();
|
|
48
|
-
const draw = async (source, dark) => {
|
|
49
|
-
loading ??= load().then((module) => module.default);
|
|
50
|
-
const mermaid = await loading;
|
|
51
|
-
if (scheme !== dark) {
|
|
52
|
-
const styles = getComputedStyle(document.documentElement);
|
|
53
|
-
mermaid.initialize({ startOnLoad: false, securityLevel: "strict", theme: "base", themeVariables: mermaid_theme((token) => styles.getPropertyValue(token).trim(), dark) });
|
|
54
|
-
scheme = dark;
|
|
55
|
-
}
|
|
56
|
-
count += 1;
|
|
57
|
-
const { svg } = await mermaid.render(`site-diagram-${count}`, source);
|
|
58
|
-
return svg;
|
|
59
|
-
};
|
|
60
|
-
return (source, dark) => {
|
|
61
|
-
const next = queue.then(() => draw(source, dark));
|
|
62
|
-
queue = next.catch(() => { });
|
|
63
|
-
return next;
|
|
64
|
-
};
|
|
65
|
-
}
|