@x-tech-laboratories/x-app 0.106.0 → 0.107.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 CHANGED
@@ -9,12 +9,12 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
9
9
 
10
10
  | Import | What it holds |
11
11
  | ---------------------------------------- | ----------------------------------------------------------------------------- |
12
- | `app/define` | The base app: `define_app` puts an X-app's name, ports, files, its own settings and its `define_feature` features (tables, migrations, calls, `api_spec`, settings, histories) together into one store every device keeps (`open_store` calling each feature's `on_open`, `needs_upgrade`, `bind_methods(database, on_change, caller)` running each call as its `caller`, calling each feature's `after_write`, recording versions and announcing writes, `is_read_only`), `page_only` (the specs' `page_only` calls and the writes of `user_only` settings, refused with `page_only_refusal`), its sync engine, its backups' names and schedule, and its bridges named after the app; `AppMethodsOf<typeof app>` types the app's calls. |
12
+ | `app/define` | The base app: `define_app` puts an X-app's name, ports, files, its own settings and its `define_feature` features (tables, migrations, calls, `api_spec`, settings, histories) together into one store every device keeps (`open_store` calling each feature's `on_open`, `needs_upgrade`, `bind_methods(database, on_change, caller)` running each call as its `caller`, calling each feature's `after_write`, recording versions and announcing writes, `is_read_only`), `page_only` (the specs' `page_only` calls and the writes of `user_only` settings, refused with `page_only_refusal`), its sync engine, its backups' names and schedule, and its bridges named after the app; `AppMethodsOf<typeof app>` types the app's calls. `history_days` sets how far an app's history reaches back until the user chooses (365 unless set); what opening changed is recorded as this device's version. |
13
13
  | `app/server`, `app/daemon` | `run_server(app, { web_folder })`: the web server from `<PREFIX>_CONFIG` with accounts in `accounts.db` (moved there once from the data's own file, tokens starting with the app's `token_prefix`), the calls, OpenAPI, MCP, the server's backups and its sync peer, a token or MCP client refused the app's `page_only` calls and the `user_only_backup_calls` (restore, remove, schedule) and its calls run as the `program` caller; `run_daemon(app)`: the desktop daemon from `<PREFIX>_DB` with sync, letting devices connect, backups, certificates and the desktop settings; Both take the app's `services` (see `app/services`), `run_daemon(app, env, { services })`. `build_server`, `start_daemon`, `open_app_database` (with `on_restore` hooks) and `register_app_calls` for tests and apps that add their own. |
14
14
  | `app/services` | An app's own work beside its calls, run by both hosts: `StartServices` gets a `HostContext` (`kind`, `database()`, `profile`, `device_name`, the server's raw `config`, `plugins_folder`, `declared_file` from `<PREFIX>_DECLARED_FILE` or `/etc/<id>/declared.json`, `announce`, `emit(event, data)` for the page's `on_event`, `side_database(name)` for a never-backed-up file such as `<base>-index.db`, `back_up`) and returns `HostServices` (`before_restore`, `after_restore`, `stop`), stopped before sync and the database. |
15
15
  | `app/links` | `app_link(scheme, route)` and `route_of_link(scheme, link)`: an app's links such as `x-notes://note/<id>` and the page route they open. |
16
16
  | `app/desktop`, `app/preload` | `run_desktop(app, electron, { main_dir })`: Electron's main process as a portal onto this computer's daemon or a server, with the window (`default_size` fixed or from the screen's free area, the daemon told while one is in front for its services' `window_in_front`), the tray (`show_tray_icon`, the app's own `tray` rows above Show, Quit and Quit completely, closing the last window leaving the app in it, `--hidden` starting there), the app's `link_scheme` links opening the window on their page (`route_of_link` to map them its own way; the page follows the `open` event), the login entry, a second launch and `--daemon`; the app's own `desktop_settings` switches sit in Settings → Desktop app beside the base's; `run_preload(app, electron)` puts every bridge on the page. Electron is handed in, so neither imports it. An app with `local_mcp: { default_port }` serves its calls as MCP on 127.0.0.1 from the desktop daemon (`electron/mcp`, page-only calls left out, calls run as `program`), turned on under Settings → MCP server. |
17
- | `app/web/app_page`, `app/web/page` | `render_app({ app, pages, general_settings })`: the page on the web, the desktop or Android in the `Shell`, with sign-in in a browser, Your account, Settings (the app's general sections, each page's own, Connections, Desktop app, Sync and Backups) and `SyncButton`; `page_hooks<Methods>()` gives the app's typed `calls`, `use_data` and `use_settings`. The phone's host (`app/web/android`) loads only on Android. The page API's `on_event(name, listener)` hears the named events the app's services `emit`, on the web and the desktop. A page may have an `icon` (the sidebar then shows icon rows), a `use_badge` hook ("Inbox · 3"), `in_sidebar: false` with `active_as` for a page reached only by its route; `default_page` names the page an empty route opens, and the `use_chrome(parts)` hook gives the `sidebar` content under the rows, header `tools` and a `side_pane`. |
17
+ | `app/web/app_page`, `app/web/page` | `render_app({ app, pages, general_settings })`: the page on the web, the desktop or Android in the `Shell`, with sign-in in a browser, Your account, Settings (the app's general sections, each page's own, Connections, Desktop app, Sync and Backups) and `SyncButton`; `page_hooks<Methods>()` gives the app's typed `calls`, `use_data` and `use_settings`. The phone's host (`app/web/android`) loads only on Android. The page API's `on_event(name, listener)` hears the named events the app's services `emit`, on the web and the desktop. A page may have an `icon` (the sidebar then shows icon rows), a `use_badge` hook ("Inbox · 3"), `in_sidebar: false` with `active_as` for a page reached only by its route; `default_page` names the page an empty route opens, and the `use_chrome(parts)` hook gives the `sidebar` content under the rows, header `tools` and a `side_pane`. `settings_categories(props)` adds the app's own Settings categories after General, for settings no one page owns. |
18
18
  | `config/vite`, `config/electron_vite`, `config/vitest`, `config/tsconfig/*.json` | An X-app's configs as presets: `web_vite_config({ port })` and `android_vite_config()` for the page, `desktop_vite_config()` for electron-vite's window, daemon, preload and page, `vitest_config()` for tests in `tests/` in UTC with coverage of `src/` to the terminal, merged with the app's own floor so `autoUpdate` still raises it, and `base`, `node`, `web` and `tests` tsconfigs to extend. |
19
19
  | `app_new` | The `x-app-new <X-Name>` command: a new X-app's files written once, laid out as the Application Standard asks, on the base app, the presets, X-App's Nix lib and its CI actions, with an example notes feature; `--port`, `--folder`, `--no-desktop` and `--no-android`. |
20
20
  | `durations` | `parse_duration` for settings such as `"2h30m"`, `format_duration` in months down to seconds and "less than a second" below one, `format_age`, and `format_clock` for a playing time such as `"3:07"`, with `{ hours: "always" }` writing `"0:03:07"` so a column of times lines up and `empty` for no time. |
@@ -55,6 +55,7 @@ export interface AppOptions<Features extends readonly Feature[]> {
55
55
  setting_key_example?: string;
56
56
  page_only_refusal?: string;
57
57
  token_prefix?: string;
58
+ history_days?: number;
58
59
  desktop_settings?: Readonly<Record<string, DesktopSettingSpec>>;
59
60
  link_scheme?: string;
60
61
  local_mcp?: {
@@ -108,6 +109,7 @@ export declare function define_app<const Features extends readonly Feature[]>(op
108
109
  setting_key_example?: string;
109
110
  page_only_refusal?: string;
110
111
  token_prefix?: string;
112
+ history_days?: number;
111
113
  desktop_settings?: Readonly<Record<string, DesktopSettingSpec>>;
112
114
  link_scheme?: string;
113
115
  local_mcp?: {
@@ -41,7 +41,8 @@ export function is_backup_schedule(value) {
41
41
  }
42
42
  export function define_app(options) {
43
43
  // ── Settings ─────────────────────────────────────────────────────────
44
- const settings_store = create_settings_store([base_settings, options.settings ?? {}, ...options.features.map((feature) => feature.settings ?? {})], {
44
+ const own_base_settings = options.history_days === undefined ? base_settings : { ...base_settings, history_days: { ...base_settings.history_days, default: options.history_days } };
45
+ const settings_store = create_settings_store([own_base_settings, options.settings ?? {}, ...options.features.map((feature) => feature.settings ?? {})], {
45
46
  app: { id: options.id, name: options.name },
46
47
  ...(options.settings_descriptions ? { descriptions: options.settings_descriptions } : {}),
47
48
  ...(options.setting_key_example ? { key_example: options.setting_key_example } : {}),
@@ -77,6 +78,9 @@ export function define_app(options) {
77
78
  sync_engine.install(database);
78
79
  for (const feature of features)
79
80
  feature.on_open?.(database);
81
+ // What opening changed, such as rows an upgrade moved, is kept as a change made on this device.
82
+ for (const history of histories)
83
+ history.record(database);
80
84
  prune_history(database);
81
85
  }
82
86
  // Versions older than the days set go, each item keeping its newest; 0 keeps them all.
@@ -2,7 +2,7 @@ import { type AutostartOptions } from "../autostart.ts";
2
2
  import { type AppLike, type FocusableWindowLike } from "../electron/app.ts";
3
3
  import type { IpcMainLike } from "../electron/bridge.ts";
4
4
  import type { WindowLike } from "../electron/events.ts";
5
- import { type TrayElectronLike, type TrayRow } from "../electron/tray.ts";
5
+ import { type TrayElectronLike, type TrayLike, type TrayRow } from "../electron/tray.ts";
6
6
  import { type BrowserWindowLike, type BrowserWindowOptionsLike, type NativeThemeLike, type ScreenLike, type ShellLike } from "../electron/window.ts";
7
7
  import { call_daemon, start_daemon } from "../local_daemon.ts";
8
8
  import type { App } from "./define.ts";
@@ -41,9 +41,16 @@ export interface ElectronLike {
41
41
  };
42
42
  };
43
43
  shell: ShellLike;
44
- Tray?: TrayElectronLike<unknown>["Tray"];
44
+ Tray?: new (image: never) => TrayLike;
45
45
  Menu?: TrayElectronLike<unknown>["Menu"];
46
- nativeImage?: TrayElectronLike<unknown>["nativeImage"];
46
+ nativeImage?: {
47
+ createFromPath(path: string): {
48
+ resize(size: {
49
+ width: number;
50
+ height: number;
51
+ }): unknown;
52
+ };
53
+ };
47
54
  }
48
55
  export interface TrayTools {
49
56
  call: (method: string, args?: unknown[]) => Promise<unknown>;
@@ -4,7 +4,7 @@
4
4
  // ── Imports ──────────────────────────────────────────────────────────────────
5
5
  import { unwatchFile, watchFile } from "node:fs";
6
6
  import { hostname } from "node:os";
7
- import { join } from "node:path";
7
+ import { join, resolve } from "node:path";
8
8
  import { launch_command, set_autostart } from "../autostart.js";
9
9
  import { backup_method_names } from "../backups.js";
10
10
  import { certificate_method_names } from "../certificate_protocol.js";
@@ -34,7 +34,7 @@ export function run_desktop(app, electron, options) {
34
34
  const own_profile = env[`${prefix}_USER_DATA`];
35
35
  const is_own_profile = own_profile === undefined;
36
36
  if (!is_own_profile)
37
- electron.app.setPath("userData", join(options.cwd ?? process.cwd(), own_profile));
37
+ electron.app.setPath("userData", resolve(options.cwd ?? process.cwd(), own_profile));
38
38
  const profile = electron.app.getPath("userData");
39
39
  const database_path = join(profile, app.database_file);
40
40
  // Any other profile gets a daemon, socket and log of its own, so a dev or test run never reaches the user's daemon.
@@ -10,6 +10,7 @@ import { fileURLToPath } from "node:url";
10
10
  import fastify, {} from "fastify";
11
11
  import { openapi_document, positional_args } from "../api_spec.js";
12
12
  import { keep_backing_up } from "../backups.js";
13
+ import { backup_method_names } from "../backups.js";
13
14
  import { calls_under, register_accounts } from "../server/account_sign_in.js";
14
15
  import { caller_of } from "../caller.js";
15
16
  import { AccountStore, holds_accounts, move_accounts } from "../server/account_store.js";
@@ -145,6 +146,8 @@ export async function build_server(app, options) {
145
146
  // The server's backups, as the page's Settings reach them.
146
147
  api.post("/backups/:method", async (request, reply) => {
147
148
  const via = request.viewer?.via;
149
+ if (!backup_method_names.includes(request.params.method))
150
+ return send_text(reply, 404, `There is no backup call ${request.params.method}.`);
148
151
  if (user_only_backup_calls.has(request.params.method) && via !== "session" && via !== "proxy")
149
152
  return send_text(reply, 403, app.page_only.refusal);
150
153
  const args = request.body ?? [];
@@ -1,5 +1,5 @@
1
1
  import type { IconGlyph } from "../../web/react/icons.tsx";
2
- import { type SettingsSection } from "../../web/react/layout.tsx";
2
+ import { type SettingsCategory, type SettingsSection } from "../../web/react/layout.tsx";
3
3
  import type { ShellSidePane } from "../../web/react/shell.tsx";
4
4
  import type { App } from "../define.ts";
5
5
  export interface PageSettingsProps {
@@ -25,6 +25,7 @@ export interface AppPages {
25
25
  app: Pick<App, "id" | "name" | "data_name" | "server_example" | "bridges"> & Partial<Pick<App, "desktop_settings">>;
26
26
  pages: readonly AppPage[];
27
27
  general_settings?: (props: PageSettingsProps) => SettingsSection[];
28
+ settings_categories?: (props: PageSettingsProps) => SettingsCategory[];
28
29
  brand_icon?: string;
29
30
  default_page?: string;
30
31
  use_chrome?: (parts: readonly string[]) => AppChrome;
@@ -68,6 +68,7 @@ export function SettingsView({ pages, is_admin = true }) {
68
68
  const general = pages.general_settings?.(props) ?? [];
69
69
  return (_jsx(SettingsPage, { categories: [
70
70
  ...(general.length > 0 ? [{ heading: "General", sections: general }] : []),
71
+ ...(pages.settings_categories?.(props) ?? []).filter((category) => category.sections.length > 0),
71
72
  ...pages.pages
72
73
  .map((each) => ({ heading: each.label, sections: each.settings?.(props) ?? [] }))
73
74
  .filter((category) => category.sections.length > 0),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-tech-laboratories/x-app",
3
- "version": "0.106.0",
3
+ "version": "0.107.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": {