@x-tech-laboratories/x-app 0.120.0 → 0.121.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 +20 -1
- package/dist/app/daemon.d.ts +7 -1
- package/dist/app/daemon.js +76 -8
- package/dist/app/define.d.ts +22 -1
- package/dist/app/define.js +34 -1
- package/dist/app/desktop.d.ts +13 -0
- package/dist/app/desktop.js +35 -3
- package/dist/app/host_tables.d.ts +20 -0
- package/dist/app/host_tables.js +91 -0
- package/dist/app/preload.js +5 -0
- package/dist/app/protocol.d.ts +29 -1
- package/dist/app/protocol.js +8 -1
- package/dist/app/remote_access.d.ts +17 -0
- package/dist/app/remote_access.js +85 -0
- package/dist/app/server.d.ts +11 -3
- package/dist/app/server.js +49 -14
- package/dist/app/services.d.ts +15 -0
- package/dist/app/web/app_page.js +43 -6
- package/dist/app/web/hosts.d.ts +4 -2
- package/dist/app/web/hosts.js +33 -0
- package/dist/app/web/page.d.ts +3 -0
- package/dist/app/web/page.js +24 -4
- package/dist/app/web/portal.d.ts +14 -0
- package/dist/app/web/portal.js +115 -0
- package/dist/app/web/settings_page.d.ts +5 -1
- package/dist/app/web/settings_page.js +25 -6
- package/dist/change_checks.js +1 -1
- package/dist/github_targets.d.ts +12 -0
- package/dist/github_targets.js +90 -0
- package/dist/remote_access_protocol.d.ts +26 -0
- package/dist/remote_access_protocol.js +33 -0
- package/dist/server/github_webhook.d.ts +2 -12
- package/dist/server/github_webhook.js +2 -87
- package/dist/web/react/remote_access_settings.d.ts +5 -0
- package/dist/web/react/remote_access_settings.js +55 -0
- package/dist/web/remote_daemon.d.ts +26 -0
- package/dist/web/remote_daemon.js +105 -0
- package/package.json +1 -1
package/dist/app/web/hosts.js
CHANGED
|
@@ -4,6 +4,22 @@
|
|
|
4
4
|
import { LOCAL_CONNECTION_ID } from "../../connection_protocol.js";
|
|
5
5
|
import { LoginNeeded } from "../../web/states.js";
|
|
6
6
|
import { data_change_of } from "../protocol.js";
|
|
7
|
+
// ── Host tables ──────────────────────────────────────────────────────────────
|
|
8
|
+
// What the host lets the page reach, or nothing while it cannot be asked, such as before signing in.
|
|
9
|
+
export async function read_host_abilities(read) {
|
|
10
|
+
try {
|
|
11
|
+
const found = (await read());
|
|
12
|
+
return { admin: found?.admin === true, tables: Array.isArray(found?.tables) ? found.tables.filter((name) => typeof name === "string") : [] };
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return { admin: false, tables: [] };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// The host tables the abilities name, each a client built by the host's own way of calling.
|
|
19
|
+
export function host_tables_of(app, abilities, client_of) {
|
|
20
|
+
const known = abilities.tables.filter((name) => Object.hasOwn(app.bridges.host_tables, name));
|
|
21
|
+
return Object.fromEntries(known.map((name) => [name, client_of(name)]));
|
|
22
|
+
}
|
|
7
23
|
// ── Web ──────────────────────────────────────────────────────────────────────
|
|
8
24
|
// Relative, so a server behind a proxy under a folder keeps it.
|
|
9
25
|
const call_path = "api/call/";
|
|
@@ -11,6 +27,7 @@ const backups_path = "api/backups/";
|
|
|
11
27
|
// The server's own sync calls sit beside the route paired devices sync through.
|
|
12
28
|
const device_path = "api/sync/";
|
|
13
29
|
const events_path = "api/events";
|
|
30
|
+
const host_path = "api/host/";
|
|
14
31
|
const client_id_header = "x-client-id";
|
|
15
32
|
const reconnect_delay_ms = 5000;
|
|
16
33
|
// A greeting after the first means the stream reconnected and may have missed changes, so the page reloads too.
|
|
@@ -72,8 +89,18 @@ export function web_api(app) {
|
|
|
72
89
|
listener(change);
|
|
73
90
|
}, (given) => (client_id = given), named);
|
|
74
91
|
const { bridges } = app;
|
|
92
|
+
// What this viewer reaches on the server, read again once they sign in.
|
|
93
|
+
const read_abilities = () => read_host_abilities(() => post_call(host_path, "get_host_abilities", []));
|
|
94
|
+
const reach = (abilities) => ({
|
|
95
|
+
admin: abilities.admin,
|
|
96
|
+
tables: host_tables_of(app, abilities, (name) => bridges.host_tables[name].web_rpc((method, args) => post_call(`api/${name}/`, method, args))),
|
|
97
|
+
});
|
|
75
98
|
return {
|
|
76
99
|
host: "web",
|
|
100
|
+
// None until read, which render_app does before the page shows, and again once the viewer signs in.
|
|
101
|
+
tables: {},
|
|
102
|
+
admin: false,
|
|
103
|
+
reread_abilities: async () => reach(await read_abilities()),
|
|
77
104
|
calls: bridges.calls.web_rpc((method, args) => post_call(call_path, method, args)),
|
|
78
105
|
// The server's own sync peer and backups, which only an admin reaches.
|
|
79
106
|
device: bridges.device.web_rpc((method, args) => post_call(device_path, method, args)),
|
|
@@ -104,8 +131,14 @@ export async function desktop_api(app) {
|
|
|
104
131
|
const events = exposed[bridges.events.api_name];
|
|
105
132
|
const connections = exposed[bridges.connections.api_name];
|
|
106
133
|
const is_here = (await connections.list_connections()).current === LOCAL_CONNECTION_ID;
|
|
134
|
+
const host = exposed[bridges.host.api_name];
|
|
135
|
+
const abilities = await read_host_abilities(async () => host?.get_host_abilities());
|
|
107
136
|
return {
|
|
108
137
|
host: "desktop",
|
|
138
|
+
admin: abilities.admin,
|
|
139
|
+
tables: host_tables_of(app, abilities, (name) => exposed[bridges.host_tables[name].api_name]),
|
|
140
|
+
daemon_is_here: is_here,
|
|
141
|
+
...(is_here && app.remote_access && exposed[bridges.remote_access.api_name] ? { remote_access: exposed[bridges.remote_access.api_name] } : {}),
|
|
109
142
|
calls: exposed[bridges.calls.api_name],
|
|
110
143
|
// Sync belongs to this computer's own daemon, so it shows only while that daemon is in use.
|
|
111
144
|
device: is_here ? exposed[bridges.device.api_name] : null,
|
package/dist/app/web/page.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ import type { PageApi } from "../protocol.ts";
|
|
|
4
4
|
type AnyMethods = Record<string, (...args: never[]) => unknown>;
|
|
5
5
|
export declare const data_watch: import("../../web/watch.ts").Watch;
|
|
6
6
|
export declare function set_page_api<Methods extends Record<keyof Methods, (...args: never[]) => unknown>>(api: PageApi<Methods>): void;
|
|
7
|
+
export declare function set_page_reach(reach: Pick<PageApi, "admin" | "tables">): void;
|
|
7
8
|
export declare function page(): PageApi;
|
|
8
9
|
export declare function calls(): Client<AnyMethods>;
|
|
10
|
+
export declare function host_table<Methods extends Record<keyof Methods, (...args: never[]) => unknown> = AnyMethods>(name: string): Client<Methods> | null;
|
|
9
11
|
export declare function use_data<Data>(load: (api: Client<AnyMethods>) => Promise<Data>, dependencies?: unknown[]): Resource<Data>;
|
|
10
12
|
export declare function use_settings(): Resource<Record<string, unknown>>;
|
|
11
13
|
export declare function page_hooks<Methods extends Record<keyof Methods, (...args: never[]) => unknown>>(): {
|
|
@@ -13,5 +15,6 @@ export declare function page_hooks<Methods extends Record<keyof Methods, (...arg
|
|
|
13
15
|
calls: () => Client<Methods>;
|
|
14
16
|
use_data: <Data>(load: (api: Client<Methods>) => Promise<Data>, dependencies?: unknown[]) => Resource<Data>;
|
|
15
17
|
use_settings: typeof use_settings;
|
|
18
|
+
host_table: typeof host_table;
|
|
16
19
|
};
|
|
17
20
|
export {};
|
package/dist/app/web/page.js
CHANGED
|
@@ -6,9 +6,9 @@ import { is_read_only } from "../define.js";
|
|
|
6
6
|
// Bumped after each write this page makes and each change from elsewhere.
|
|
7
7
|
export const data_watch = create_watch();
|
|
8
8
|
let page_api = null;
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
// Each call of a table, a write telling this page's views too, since the host only tells the other pages.
|
|
10
|
+
function watched(table) {
|
|
11
|
+
return Object.fromEntries(Object.entries(table).map(([name, call]) => [
|
|
12
12
|
name,
|
|
13
13
|
async (...args) => {
|
|
14
14
|
const result = await call(...args);
|
|
@@ -17,9 +17,23 @@ export function set_page_api(api) {
|
|
|
17
17
|
return result;
|
|
18
18
|
},
|
|
19
19
|
]));
|
|
20
|
-
|
|
20
|
+
}
|
|
21
|
+
let following_changes = false;
|
|
22
|
+
export function set_page_api(api) {
|
|
23
|
+
const tables = api.tables ? Object.fromEntries(Object.entries(api.tables).map(([name, table]) => [name, watched(table)])) : undefined;
|
|
24
|
+
page_api = { ...api, calls: watched(api.calls), ...(tables ? { tables } : {}) };
|
|
25
|
+
// Set again when what the host lets the page reach changed, such as after signing in, but followed once.
|
|
26
|
+
if (following_changes)
|
|
27
|
+
return;
|
|
28
|
+
following_changes = true;
|
|
21
29
|
api.on_change(() => data_watch.bump());
|
|
22
30
|
}
|
|
31
|
+
// What the host lets the page reach, read again, such as once a browser signed in.
|
|
32
|
+
export function set_page_reach(reach) {
|
|
33
|
+
const api = page();
|
|
34
|
+
const tables = reach.tables ? Object.fromEntries(Object.entries(reach.tables).map(([name, table]) => [name, watched(table)])) : api.tables;
|
|
35
|
+
page_api = { ...api, ...(reach.admin === undefined ? {} : { admin: reach.admin }), ...(tables ? { tables } : {}) };
|
|
36
|
+
}
|
|
23
37
|
export function page() {
|
|
24
38
|
if (!page_api)
|
|
25
39
|
throw new Error("the page's api has not been set up");
|
|
@@ -29,6 +43,11 @@ export function page() {
|
|
|
29
43
|
export function calls() {
|
|
30
44
|
return page().calls;
|
|
31
45
|
}
|
|
46
|
+
// One of the app's host tables, such as host_table("stages"), or null where the host does not answer it or does not
|
|
47
|
+
// let this viewer reach it.
|
|
48
|
+
export function host_table(name) {
|
|
49
|
+
return page().tables?.[name] ?? null;
|
|
50
|
+
}
|
|
32
51
|
// ── Hooks ────────────────────────────────────────────────────────────────────
|
|
33
52
|
// Loads with the page's calls and loads again quietly whenever the data changed.
|
|
34
53
|
export function use_data(load, dependencies = []) {
|
|
@@ -45,5 +64,6 @@ export function page_hooks() {
|
|
|
45
64
|
calls: calls,
|
|
46
65
|
use_data: use_data,
|
|
47
66
|
use_settings,
|
|
67
|
+
host_table,
|
|
48
68
|
};
|
|
49
69
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type LocalNotificationsLike } from "../../phone_notices.ts";
|
|
2
|
+
import type { App } from "../define.ts";
|
|
3
|
+
import { type AppNotice, type PageApi } from "../protocol.ts";
|
|
4
|
+
import type { PhoneLifecycle } from "./android.ts";
|
|
5
|
+
export declare function read_notice_switches(app: Pick<App, "desktop_settings">, saved: string | null): Record<string, boolean>;
|
|
6
|
+
export declare function phone_notice_shower(plugin: LocalNotificationsLike, open_link: (url: string) => void): (notice: AppNotice) => void;
|
|
7
|
+
export interface PortalOptions {
|
|
8
|
+
lifecycle: PhoneLifecycle;
|
|
9
|
+
notifications?: LocalNotificationsLike;
|
|
10
|
+
storage?: Pick<Storage, "getItem" | "setItem">;
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
reload?: () => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function portal_api(app: App, options: PortalOptions): Promise<PageApi>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// The phone's page for an app whose phone keeps no data: a window onto a daemon or server on another computer, chosen
|
|
2
|
+
// under Settings → Connections and signed in once as this phone. Every call goes there with the phone's token, its
|
|
3
|
+
// events keep the page current, and the notices that host tells of show as phone notifications where this phone's
|
|
4
|
+
// switch for their kind is on. Only the phone build loads it.
|
|
5
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
6
|
+
import { create_connections } from "../../connections.js";
|
|
7
|
+
import { notice_id } from "../../phone_notices.js";
|
|
8
|
+
import { phone_certificates } from "../../phone_certificates.js";
|
|
9
|
+
import { local_connection_storage } from "../../web/connection_storage.js";
|
|
10
|
+
import { call_remote, follow_remote } from "../../web/remote_daemon.js";
|
|
11
|
+
import { route_of_link } from "../links.js";
|
|
12
|
+
import { data_change_of, notice_event, notice_is_on } from "../protocol.js";
|
|
13
|
+
import { host_tables_of, read_host_abilities } from "./hosts.js";
|
|
14
|
+
// ── Switches ─────────────────────────────────────────────────────────────────
|
|
15
|
+
// The notice switches this phone keeps, each of the app's `notify_` desktop switches at its default where unset.
|
|
16
|
+
export function read_notice_switches(app, saved) {
|
|
17
|
+
let parsed = {};
|
|
18
|
+
try {
|
|
19
|
+
parsed = JSON.parse(saved ?? "{}");
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
parsed = {};
|
|
23
|
+
}
|
|
24
|
+
const notice_keys = Object.entries(app.desktop_settings ?? {}).filter(([key]) => key.startsWith("notify_"));
|
|
25
|
+
// Saved by kind, as notify_<kind> or by the kind alone, as an older phone kept them.
|
|
26
|
+
return Object.fromEntries(notice_keys.map(([key, spec]) => {
|
|
27
|
+
const value = parsed[key] ?? parsed[key.slice("notify_".length)];
|
|
28
|
+
return [key, typeof value === "boolean" ? value : spec.default];
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
// ── Notices ──────────────────────────────────────────────────────────────────
|
|
32
|
+
// Shows notices at once without asking for exact alarms, which would open a settings screen; a tap opens the page its
|
|
33
|
+
// link names.
|
|
34
|
+
export function phone_notice_shower(plugin, open_link) {
|
|
35
|
+
void plugin.addListener("localNotificationActionPerformed", (action) => open_link(String(action.notification.extra?.url ?? "")));
|
|
36
|
+
void plugin.checkPermissions().then(({ display }) => (display === "granted" || display === "denied" ? undefined : plugin.requestPermissions()));
|
|
37
|
+
return (notice) => void plugin.schedule({ notifications: [{ id: notice_id(notice.key), title: notice.title, body: notice.body, extra: { url: notice.url }, isExactNotification: false }] }).catch((error) => console.error("could not show a notice", error));
|
|
38
|
+
}
|
|
39
|
+
export async function portal_api(app, options) {
|
|
40
|
+
const storage = options.storage ?? localStorage;
|
|
41
|
+
const switches_key = `${app.id}-notice-kinds`;
|
|
42
|
+
const connections = create_connections({ storage: local_connection_storage(`${app.id}-connections`), offers_local: false, device_name: `${app.name} on Android` });
|
|
43
|
+
let client_id = "";
|
|
44
|
+
const link = {
|
|
45
|
+
daemon: () => {
|
|
46
|
+
const current = connections.current();
|
|
47
|
+
return current?.kind === "remote" ? { address: current.address, token: current.token } : null;
|
|
48
|
+
},
|
|
49
|
+
client_id: () => client_id,
|
|
50
|
+
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
51
|
+
};
|
|
52
|
+
// Another host chosen, or one added first: the page starts again on it.
|
|
53
|
+
connections.subscribe(() => (options.reload ?? (() => location.reload()))());
|
|
54
|
+
const listeners = new Set();
|
|
55
|
+
const named = new Map();
|
|
56
|
+
const announce = (change = null) => {
|
|
57
|
+
for (const listener of listeners)
|
|
58
|
+
listener(change);
|
|
59
|
+
};
|
|
60
|
+
const rpc = (path) => (method, args) => call_remote(link, `/api/${path}/${method}`, args);
|
|
61
|
+
const { bridges } = app;
|
|
62
|
+
const abilities = link.daemon() ? await read_host_abilities(() => call_remote(link, "/api/host/get_host_abilities", [])) : { admin: false, tables: [] };
|
|
63
|
+
const switches = () => read_notice_switches(app, storage.getItem(switches_key));
|
|
64
|
+
const open_link = (url) => {
|
|
65
|
+
const route = app.link_scheme ? route_of_link(app.link_scheme, url) : null;
|
|
66
|
+
if (route)
|
|
67
|
+
location.hash = route;
|
|
68
|
+
};
|
|
69
|
+
const show = options.notifications ? phone_notice_shower(options.notifications, open_link) : null;
|
|
70
|
+
if (link.daemon()) {
|
|
71
|
+
follow_remote(link, (event, data) => {
|
|
72
|
+
if (event === "hello")
|
|
73
|
+
client_id = data;
|
|
74
|
+
else if (event === "changed")
|
|
75
|
+
announce(data_change_of(data));
|
|
76
|
+
else {
|
|
77
|
+
const parsed = data === "" ? null : JSON.parse(data);
|
|
78
|
+
if (event === notice_event && show && notice_is_on(parsed.kind, switches()))
|
|
79
|
+
show(parsed);
|
|
80
|
+
for (const listener of named.get(event) ?? [])
|
|
81
|
+
listener(parsed);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
// A reconnect may have missed changes, so the page reads again.
|
|
85
|
+
{ on_connect: () => announce() });
|
|
86
|
+
// Back from the background, the page catches up on what it missed.
|
|
87
|
+
options.lifecycle.addListener("resume", () => announce());
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
host: "android",
|
|
91
|
+
calls: bridges.calls.web_rpc(rpc("call")),
|
|
92
|
+
device: null,
|
|
93
|
+
// The host's backups, which only an admin there reaches.
|
|
94
|
+
backups: abilities.admin ? bridges.backups.web_rpc(rpc("backups")) : null,
|
|
95
|
+
connections: connections.methods,
|
|
96
|
+
certificates: phone_certificates(),
|
|
97
|
+
admin: abilities.admin,
|
|
98
|
+
tables: host_tables_of(app, abilities, (name) => bridges.host_tables[name].web_rpc(rpc(name))),
|
|
99
|
+
notice_switches: {
|
|
100
|
+
get: async () => switches(),
|
|
101
|
+
set: async (key, on) => storage.setItem(switches_key, JSON.stringify({ ...switches(), [key]: on })),
|
|
102
|
+
},
|
|
103
|
+
on_change: (listener) => {
|
|
104
|
+
listeners.add(listener);
|
|
105
|
+
return () => listeners.delete(listener);
|
|
106
|
+
},
|
|
107
|
+
on_event: (event, listener) => {
|
|
108
|
+
let kept = named.get(event);
|
|
109
|
+
if (!kept)
|
|
110
|
+
named.set(event, (kept = new Set()));
|
|
111
|
+
kept.add(listener);
|
|
112
|
+
return () => void kept.delete(listener);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IconGlyph } from "../../web/react/icons.tsx";
|
|
2
2
|
import { type SettingsCategory, type SettingsSection } from "../../web/react/layout.tsx";
|
|
3
3
|
import type { ShellSidePane, SidebarWidth } from "../../web/react/shell.tsx";
|
|
4
|
+
import type { LocalNotificationsLike } from "../../phone_notices.ts";
|
|
4
5
|
import type { App } from "../define.ts";
|
|
5
6
|
import type { StartPhoneServices } from "./android.ts";
|
|
6
7
|
export interface PageSettingsProps {
|
|
@@ -16,6 +17,7 @@ export interface AppPage {
|
|
|
16
17
|
use_badge?: () => number | string | null;
|
|
17
18
|
in_sidebar?: boolean;
|
|
18
19
|
active_as?: string;
|
|
20
|
+
view_key?: (parts: string[]) => string;
|
|
19
21
|
children?: readonly AppSubpage[];
|
|
20
22
|
}
|
|
21
23
|
export interface AppSubpage {
|
|
@@ -33,7 +35,7 @@ export interface AppChrome {
|
|
|
33
35
|
sidebar_width?: SidebarWidth;
|
|
34
36
|
}
|
|
35
37
|
export interface AppPages {
|
|
36
|
-
app: Pick<App, "id" | "name" | "data_name" | "server_example" | "bridges"> & Partial<Pick<App, "desktop_settings" | "synced_theme">>;
|
|
38
|
+
app: Pick<App, "id" | "name" | "data_name" | "server_example" | "bridges"> & Partial<Pick<App, "desktop_settings" | "synced_theme" | "phone">>;
|
|
37
39
|
pages: readonly AppPage[];
|
|
38
40
|
general_settings?: (props: PageSettingsProps) => SettingsSection[];
|
|
39
41
|
settings_categories?: (props: PageSettingsProps) => SettingsCategory[];
|
|
@@ -41,6 +43,8 @@ export interface AppPages {
|
|
|
41
43
|
default_page?: string;
|
|
42
44
|
use_chrome?: (parts: readonly string[]) => AppChrome;
|
|
43
45
|
phone_services?: () => Promise<StartPhoneServices>;
|
|
46
|
+
phone_notifications?: () => Promise<LocalNotificationsLike>;
|
|
47
|
+
remote_access_reach?: string;
|
|
44
48
|
}
|
|
45
49
|
export declare function SettingsView({ pages, is_admin }: {
|
|
46
50
|
pages: AppPages;
|
|
@@ -10,6 +10,7 @@ import { LocalMcpSettings } from "../../web/react/local_mcp_settings.js";
|
|
|
10
10
|
import { Switch } from "../../web/react/controls.js";
|
|
11
11
|
import { PageHeading, SettingRow, SettingsPage } from "../../web/react/layout.js";
|
|
12
12
|
import { Loaded } from "../../web/react/states.js";
|
|
13
|
+
import { RemoteAccessSettings } from "../../web/react/remote_access_settings.js";
|
|
13
14
|
import { PeerListeningSettings, SyncSettings } from "../../web/react/sync_settings.js";
|
|
14
15
|
import { attempt } from "../../web/react/toasts.js";
|
|
15
16
|
import { calls, data_watch, page, use_settings } from "./page.js";
|
|
@@ -43,17 +44,35 @@ function DataFolder({ desktop }) {
|
|
|
43
44
|
return null;
|
|
44
45
|
return (_jsx(SettingRow, { label: "Database", hint: _jsx("span", { className: "path", children: paths.database }), children: _jsx("button", { type: "button", onClick: () => attempt(desktop.show_data_path("database")), children: "Show in folder" }) }));
|
|
45
46
|
}
|
|
46
|
-
//
|
|
47
|
-
function
|
|
48
|
-
const
|
|
47
|
+
// Which kinds of notice this phone shows, of those the host it works on tells of.
|
|
48
|
+
function NoticeSwitches({ app, switches }) {
|
|
49
|
+
const [values, set_values] = useState(null);
|
|
50
|
+
useEffect(() => void switches.get().then(set_values, () => undefined), [switches]);
|
|
51
|
+
if (!values)
|
|
52
|
+
return null;
|
|
53
|
+
const notice_specs = Object.entries(app.desktop_settings ?? {}).filter(([key]) => key.startsWith("notify_"));
|
|
54
|
+
return (_jsx(_Fragment, { children: notice_specs.map(([key, spec]) => (_jsx(SettingRow, { label: spec.label, ...(spec.hint ? { hint: spec.hint } : {}), as_label: true, children: _jsx(Switch, { label: spec.label, checked: values[key] ?? spec.default, on_change: (on) => {
|
|
55
|
+
set_values({ ...values, [key]: on });
|
|
56
|
+
attempt(switches.set(key, on));
|
|
57
|
+
} }) }, key))) }));
|
|
58
|
+
}
|
|
59
|
+
// A desktop window on a server's daemon, or a phone that keeps no data, works on the host's data, as a browser does.
|
|
60
|
+
function storage_category(pages, is_admin) {
|
|
61
|
+
const { app } = pages;
|
|
62
|
+
const { backups, backup_folder, certificates, connections, desktop, device, host, local_mcp, notice_switches, peer_listening, remote_access } = page();
|
|
49
63
|
const { data_name, name } = app;
|
|
50
|
-
const on_server = host === "web" ||
|
|
64
|
+
const on_server = host === "web" || !device;
|
|
51
65
|
const sections = [];
|
|
52
66
|
if (connections) {
|
|
53
|
-
|
|
67
|
+
const hint = host === "android" ? `The ${name} daemon or server this phone works on, signed in once as this phone.` : `The ${data_name} this window works on: This computer's own, or an ${name} server's.`;
|
|
68
|
+
sections.push({ id: "connections", heading: "Connections", hint, content: _jsxs(_Fragment, { children: [_jsx(ConnectionSettings, { client: connections, certificates: certificates, placeholder: app.server_example }), !device && certificates && _jsx(TrustedCertificates, { certificates: certificates })] }) });
|
|
54
69
|
}
|
|
55
70
|
if (desktop)
|
|
56
71
|
sections.push({ id: "desktop", heading: "Desktop app", content: _jsx(Desktop, { app_name: name, own: app.desktop_settings ?? {} }) });
|
|
72
|
+
if (notice_switches)
|
|
73
|
+
sections.push({ id: "notices", heading: "Notifications", hint: `What this phone tells you of from the ${name} it works on.`, content: _jsx(NoticeSwitches, { app: app, switches: notice_switches }) });
|
|
74
|
+
if (remote_access)
|
|
75
|
+
sections.push({ id: "remote", heading: "Other devices", hint: `Let phones, browsers and other computers work on this computer's ${data_name}.`, content: _jsx(RemoteAccessSettings, { remote: remote_access, ...(pages.remote_access_reach ? { reach: pages.remote_access_reach } : {}) }) });
|
|
57
76
|
if (local_mcp)
|
|
58
77
|
sections.push({ id: "mcp", heading: "MCP server", hint: `Let AI assistants such as Claude Code reach this computer's ${data_name} without the server.`, content: _jsx(LocalMcpSettings, { device: local_mcp, name: name }) });
|
|
59
78
|
if (device && (!on_server || is_admin)) {
|
|
@@ -84,7 +103,7 @@ export function SettingsView({ pages, is_admin = true }) {
|
|
|
84
103
|
...pages.pages
|
|
85
104
|
.map((each) => ({ heading: each.label, sections: each.settings?.(props) ?? [] }))
|
|
86
105
|
.filter((category) => category.sections.length > 0),
|
|
87
|
-
...storage_category(pages
|
|
106
|
+
...storage_category(pages, is_admin && page().admin !== false),
|
|
88
107
|
] }));
|
|
89
108
|
} })] }));
|
|
90
109
|
}
|
package/dist/change_checks.js
CHANGED
|
@@ -10,7 +10,7 @@ export const x_tech_options = {
|
|
|
10
10
|
commit_trailer: "Assisted-by",
|
|
11
11
|
trailer_organisations: ["x-tech-laboratories"],
|
|
12
12
|
ai_mention: /\b(claude|anthropic|co-authored-by|generated with|ai[- ]generated|chatgpt|copilot)\b/i,
|
|
13
|
-
wrapped_libraries: ["drizzle-orm", "@tanstack/react-table", "lucide-react", "marked", "dompurify", "@tiptap/", "fflate", "rrule", "frimousse", "squarify", "react-error-boundary", "es-module-lexer", "hookable", "parse-duration", "pretty-bytes", "emojibase", "emojibase-data", "@sqlite.org/sqlite-wasm", "@modelcontextprotocol/server", "@fastify/session", "nodemailer", "sshpk"],
|
|
13
|
+
wrapped_libraries: ["drizzle-orm", "@tanstack/react-table", "lucide-react", "marked", "dompurify", "@tiptap/", "fflate", "rrule", "frimousse", "squarify", "react-error-boundary", "es-module-lexer", "hookable", "parse-duration", "pretty-bytes", "emojibase", "emojibase-data", "@sqlite.org/sqlite-wasm", "@modelcontextprotocol/server", "@fastify/session", "nodemailer", "sshpk", "diff", "parse-diff"],
|
|
14
14
|
wrapping_repositories: ["x-tech-laboratories/X-App"],
|
|
15
15
|
allowed_licences: ["0BSD", "MIT", "MIT-0", "ISC", "BSD-2-Clause", "BSD-3-Clause", "Apache-2.0", "Zlib", "Unlicense", "CC0-1.0", "CC-BY-3.0", "CC-BY-4.0", "BlueOak-1.0.0", "Python-2.0", "Artistic-2.0", "MPL-2.0", "LGPL-2.1-or-later", "LGPL-3.0-or-later", "GPL-3.0-only", "GPL-3.0-or-later"],
|
|
16
16
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const github_target_events: readonly ["pull_request", "check_suite", "check_run", "status", "workflow_run", "issues", "issue_comment"];
|
|
2
|
+
export interface WebhookTargets {
|
|
3
|
+
repository: string;
|
|
4
|
+
pull_requests: number[];
|
|
5
|
+
branches: string[];
|
|
6
|
+
issues: number[];
|
|
7
|
+
}
|
|
8
|
+
export declare function is_repository_name(name: string): boolean;
|
|
9
|
+
export declare function repository_of(payload: unknown): string | null;
|
|
10
|
+
export declare function delivery_id_of(header: unknown): string;
|
|
11
|
+
export declare function targets_of(event: string, payload: unknown): WebhookTargets | null;
|
|
12
|
+
export declare function read_targets(repository: string, stored: string): WebhookTargets;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// GitHub's webhook deliveries as any part of an app reads them, the same in a page, a phone and Node: the events that
|
|
2
|
+
// name what changed, the repository and the pull requests, branches and issues a payload names, and a delivery's id.
|
|
3
|
+
// server/github_webhook receives them.
|
|
4
|
+
// ── Shapes ───────────────────────────────────────────────────────────────────
|
|
5
|
+
// The events that name pull requests, branches or issues, for the app to tick on GitHub.
|
|
6
|
+
export const github_target_events = ["pull_request", "check_suite", "check_run", "status", "workflow_run", "issues", "issue_comment"];
|
|
7
|
+
const repository_pattern = /^[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100}$/;
|
|
8
|
+
const branch_pattern = /^[A-Za-z0-9._/-]{1,255}$/;
|
|
9
|
+
const delivery_pattern = /^[A-Za-z0-9-]{1,100}$/;
|
|
10
|
+
const most_targets = 50;
|
|
11
|
+
function fields_of(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
13
|
+
}
|
|
14
|
+
function number_of(value) {
|
|
15
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 && value < 2 ** 31 ? value : null;
|
|
16
|
+
}
|
|
17
|
+
function branch_of(value) {
|
|
18
|
+
return typeof value === "string" && branch_pattern.test(value) && !value.includes("..") && !value.startsWith("-") ? value : null;
|
|
19
|
+
}
|
|
20
|
+
// The pull request numbers in a list such as check_suite.pull_requests, left out where they are not plain numbers.
|
|
21
|
+
function numbers_in(list) {
|
|
22
|
+
return (Array.isArray(list) ? list : []).map((entry) => number_of(fields_of(entry).number)).filter((number) => number !== null);
|
|
23
|
+
}
|
|
24
|
+
// Whether a name is a repository as owner/name.
|
|
25
|
+
export function is_repository_name(name) {
|
|
26
|
+
return repository_pattern.test(name);
|
|
27
|
+
}
|
|
28
|
+
// The repository a payload names as owner/name, or null when it names none that looks like one.
|
|
29
|
+
export function repository_of(payload) {
|
|
30
|
+
const name = fields_of(fields_of(payload).repository).full_name;
|
|
31
|
+
return typeof name === "string" && repository_pattern.test(name) ? name : null;
|
|
32
|
+
}
|
|
33
|
+
// The delivery id as GitHub sends it, or "" when it is missing or not an id.
|
|
34
|
+
export function delivery_id_of(header) {
|
|
35
|
+
return typeof header === "string" && delivery_pattern.test(header) ? header : "";
|
|
36
|
+
}
|
|
37
|
+
// The repository and the pull requests, branches and issues a delivery names, or null; nothing else in it is kept.
|
|
38
|
+
export function targets_of(event, payload) {
|
|
39
|
+
const repository = repository_of(payload);
|
|
40
|
+
if (repository === null)
|
|
41
|
+
return null;
|
|
42
|
+
const values = fields_of(payload);
|
|
43
|
+
const pull_requests = [];
|
|
44
|
+
const branches = [];
|
|
45
|
+
const issues = [];
|
|
46
|
+
if (event === "ping") {
|
|
47
|
+
// Only says the hook works.
|
|
48
|
+
}
|
|
49
|
+
else if (event === "pull_request") {
|
|
50
|
+
const pull = fields_of(values.pull_request);
|
|
51
|
+
const head = fields_of(pull.head);
|
|
52
|
+
pull_requests.push(number_of(pull.number) ?? number_of(values.number));
|
|
53
|
+
// A fork's branch is not one of the repository's own, so only a branch of the same repository counts.
|
|
54
|
+
if (fields_of(head.repo).full_name === repository)
|
|
55
|
+
branches.push(branch_of(head.ref));
|
|
56
|
+
}
|
|
57
|
+
else if (event === "check_suite" || event === "workflow_run") {
|
|
58
|
+
const suite = fields_of(values[event]);
|
|
59
|
+
branches.push(branch_of(suite.head_branch));
|
|
60
|
+
pull_requests.push(...numbers_in(suite.pull_requests));
|
|
61
|
+
}
|
|
62
|
+
else if (event === "check_run") {
|
|
63
|
+
const run = fields_of(values.check_run);
|
|
64
|
+
branches.push(branch_of(fields_of(run.check_suite).head_branch));
|
|
65
|
+
pull_requests.push(...numbers_in(run.pull_requests));
|
|
66
|
+
}
|
|
67
|
+
else if (event === "status") {
|
|
68
|
+
branches.push(...(Array.isArray(values.branches) ? values.branches : []).map((branch) => branch_of(fields_of(branch).name)));
|
|
69
|
+
}
|
|
70
|
+
else if (event === "issues" || event === "issue_comment") {
|
|
71
|
+
issues.push(number_of(fields_of(values.issue).number));
|
|
72
|
+
}
|
|
73
|
+
else
|
|
74
|
+
return null;
|
|
75
|
+
const kept = (list) => [...new Set(list.filter((value) => value !== null))].slice(0, most_targets);
|
|
76
|
+
return { repository, pull_requests: kept(pull_requests), branches: kept(branches), issues: kept(issues) };
|
|
77
|
+
}
|
|
78
|
+
// A delivery's targets as stored, each list left empty where the stored text is damaged.
|
|
79
|
+
export function read_targets(repository, stored) {
|
|
80
|
+
let fields = {};
|
|
81
|
+
try {
|
|
82
|
+
fields = fields_of(JSON.parse(stored));
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
fields = {};
|
|
86
|
+
}
|
|
87
|
+
const numbers = (value) => (Array.isArray(value) ? value.map(number_of).filter((number) => number !== null) : []);
|
|
88
|
+
const names = Array.isArray(fields.branches) ? fields.branches.map(branch_of).filter((branch) => branch !== null) : [];
|
|
89
|
+
return { repository, pull_requests: numbers(fields.pull_requests), branches: names, issues: numbers(fields.issues) };
|
|
90
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface RemoteAccessSettings {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
host: string;
|
|
4
|
+
port: number;
|
|
5
|
+
certificate_file: string;
|
|
6
|
+
key_file: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function remote_access_defaults(port: number): RemoteAccessSettings;
|
|
9
|
+
export declare function read_remote_access(saved: unknown, default_port: number): RemoteAccessSettings;
|
|
10
|
+
export declare function remote_access_problem(settings: RemoteAccessSettings, admins: string[]): string;
|
|
11
|
+
export interface RemoteAccessStatus {
|
|
12
|
+
settings: RemoteAccessSettings;
|
|
13
|
+
admins: string[];
|
|
14
|
+
listening: string;
|
|
15
|
+
problem: string;
|
|
16
|
+
}
|
|
17
|
+
export interface RemoteAccessMethods {
|
|
18
|
+
get_remote_access: () => RemoteAccessStatus;
|
|
19
|
+
set_remote_access: (settings: RemoteAccessSettings) => Promise<RemoteAccessStatus>;
|
|
20
|
+
set_remote_admin: (name: string, password: string) => Promise<RemoteAccessStatus>;
|
|
21
|
+
remove_remote_admin: (name: string) => Promise<RemoteAccessStatus>;
|
|
22
|
+
}
|
|
23
|
+
export declare const remote_access_method_names: readonly ["get_remote_access", "set_remote_access", "set_remote_admin", "remove_remote_admin"];
|
|
24
|
+
export type RemoteAccessClient = {
|
|
25
|
+
[Name in keyof RemoteAccessMethods]: (...args: Parameters<RemoteAccessMethods[Name]>) => Promise<Awaited<ReturnType<RemoteAccessMethods[Name]>>>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// "Let other devices connect" for a desktop daemon's own calls: its network address, off unless turned on, behind the
|
|
2
|
+
// sign-in, so a phone, a browser or another computer's desktop app can work on this computer, such as on files only it
|
|
3
|
+
// holds. It is apart from sync's own listening, which lets paired devices sync with it.
|
|
4
|
+
// Off, on every network, at the port given, such as the app's web server's, over plain http.
|
|
5
|
+
export function remote_access_defaults(port) {
|
|
6
|
+
return { enabled: false, host: "0.0.0.0", port, certificate_file: "", key_file: "" };
|
|
7
|
+
}
|
|
8
|
+
const host_pattern = /^[A-Za-z0-9.:[\]_-]+$/;
|
|
9
|
+
// Settings saved on the computer, each default where it is missing or damaged.
|
|
10
|
+
export function read_remote_access(saved, default_port) {
|
|
11
|
+
const defaults = remote_access_defaults(default_port);
|
|
12
|
+
const fields = (saved ?? {});
|
|
13
|
+
const port = Number(fields.port);
|
|
14
|
+
const text = (value) => (typeof value === "string" ? value.trim() : "");
|
|
15
|
+
return {
|
|
16
|
+
enabled: fields.enabled === true,
|
|
17
|
+
host: typeof fields.host === "string" && host_pattern.test(fields.host.trim()) ? fields.host.trim() : defaults.host,
|
|
18
|
+
port: Number.isInteger(port) && port > 0 && port < 65536 ? port : defaults.port,
|
|
19
|
+
certificate_file: text(fields.certificate_file),
|
|
20
|
+
key_file: text(fields.key_file),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// Why the settings cannot be used as they are, or "" when they can.
|
|
24
|
+
export function remote_access_problem(settings, admins) {
|
|
25
|
+
if (!settings.enabled)
|
|
26
|
+
return "";
|
|
27
|
+
if (admins.length === 0)
|
|
28
|
+
return "Add an admin first, so a device has someone to sign in as.";
|
|
29
|
+
if ((settings.certificate_file === "") !== (settings.key_file === ""))
|
|
30
|
+
return "Give both the certificate and its key, or neither.";
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
export const remote_access_method_names = ["get_remote_access", "set_remote_access", "set_remote_admin", "remove_remote_admin"];
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import type { IncomingHttpHeaders } from "node:http";
|
|
2
2
|
import { AddressLockout, type WebhookAnswer } from "./forge_webhook.ts";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
repository: string;
|
|
6
|
-
pull_requests: number[];
|
|
7
|
-
branches: string[];
|
|
8
|
-
issues: number[];
|
|
9
|
-
}
|
|
3
|
+
export { github_target_events, is_repository_name, repository_of, delivery_id_of, targets_of, read_targets, type WebhookTargets } from "../github_targets.ts";
|
|
4
|
+
import type { WebhookTargets } from "../github_targets.ts";
|
|
10
5
|
export interface GitHubDelivery {
|
|
11
6
|
delivery_id: string;
|
|
12
7
|
event: string;
|
|
@@ -20,11 +15,6 @@ export interface GitHubReceiverOptions {
|
|
|
20
15
|
remembered?: number;
|
|
21
16
|
unsigned_text?: string;
|
|
22
17
|
}
|
|
23
|
-
export declare function is_repository_name(name: string): boolean;
|
|
24
|
-
export declare function repository_of(payload: unknown): string | null;
|
|
25
|
-
export declare function delivery_id_of(header: unknown): string;
|
|
26
|
-
export declare function targets_of(event: string, payload: unknown): WebhookTargets | null;
|
|
27
|
-
export declare function read_targets(repository: string, stored: string): WebhookTargets;
|
|
28
18
|
export declare function read_public_url(typed: string): string;
|
|
29
19
|
export declare function payload_url_of(public_url: string, path: string): string;
|
|
30
20
|
export declare function create_github_receiver({ secret, events, on_delivery, lockout, remembered, unsigned_text }: GitHubReceiverOptions): (address: string, headers: IncomingHttpHeaders, body: Buffer) => WebhookAnswer;
|