@x-tech-laboratories/x-app 0.116.0 → 0.117.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 +2 -2
- package/dist/app_android_key.d.ts +3 -0
- package/dist/app_android_key.js +34 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
|
|
|
55
55
|
| `sync_engine`, `sync_peer`, `sync_protocol`, `sync_seal`, `server/sync_peer_routes`, `sync_peer_discovery`, `sync_peer_listening` | SQLite kept alike on every device with no server: `create_sync_engine` stamps each value of the tables it is given through triggers, so the app's own writes need no change, and the newest write of each value wins, each key of a table's `map_columns` (JSON objects such as ids from many sources) counting as a value of its own so two devices adding different keys keep both. Every copy is a peer: `create_sync_peer` pairs with another device through a one-time code (`create_pairing_code`, `pair_device`), the two copies merging with nothing asked, then sends each paired device its changes within seconds, takes theirs in the same round trip, holds a waiting call open to hear of theirs at once, and passes on what it took from the others, so devices that never reach each other still end up alike; the group's list of devices travels too, so a new device is introduced to the rest and a removed one (`remove_device`) is refused by all. Each call is sealed with both devices' keys on tweetnacl's box (`sync_seal`), chosen over TLS with pinned certificates because it runs alike on Node and in a phone's page; calls still travel over https only. After a restore (`forget_history`) each peer is made to match the restored copy once, keeping a copy of its own first. `register_sync_peer_routes` answers other devices at `sync/peer` under a daemon's prefix, `listen_for_peers` opens a desktop daemon's own port for them, `discover_peers` finds paired devices on the local network by mDNS, on bonjour-service, and `keep_listening_for_peers` (`sync_peer_listening`) is a desktop daemon's "Let other devices connect" setting, kept in a file beside the database, which answers over https with a self-signed certificate made once (`peer_certificate`, on selfsigned, chosen because it makes one with Node's own crypto) and whose `PeerListeningMethods`, its fingerprint included, the page shows with `PeerListeningSettings`; `SyncSettings` given `certificates` asks to review and trust that certificate when pairing fails over it, and pairs again. |
|
|
56
56
|
| `sync_files`, `node_file_store`, `electron/file_protocol` | Files that sync beside the rows that name them, such as covers or photos, so a large picture never travels with every change: each is named by the sha256 of its bytes (`hash_bytes`, `put_file`, `is_file_name`) and kept in a `SyncFileStore`, a folder on Node (`folder_file_store`, written through a rename) or IndexedDB on a phone (`indexed_db_files`); given `files: { store, referenced }`, the sync peer sends each paired device the named files it lacks and fetches those this device lacks after each exchange, a few at a time, trying a file neither has yet again next round, and keeps the ones it is sent, refusing bytes that do not match their name; `register_file_scheme` and `serve_files` show them in a desktop page as `<scheme>://<name>`. |
|
|
57
57
|
| `app_android` | `x-app-android [app folder]`: the app's Capacitor project in `android/`, made from Capacitor's template when it is missing, given X-App's `config/android/release.gradle` and, where it has none of its own, a network rule allowing plain http only to the phone itself (`network_security_config`), for `adb reverse` while testing, (the version CI hands each build, and signing when the release key is in the environment), its launcher icons from `x-app-icons`, then `cap sync android`. Run after the Android page is built; the app keeps `android/` out of git. |
|
|
58
|
-
| `app_android_key` | `x-app-android-key [app folder]
|
|
58
|
+
| `app_android_key` | `x-app-android-key [app folder] [key folder]` or `x-app-android-key --org <org> [key folder]`: an Android release key, made once with keytool in `~/.local/share/<name>/signing` (or the given folder) and never replaced, and stored with gh as the `ANDROID_KEYSTORE_BASE64`, `ANDROID_KEYSTORE_PASSWORD` and `ANDROID_KEY_ALIAS` secrets `app-android` signs with, handed over on stdin so nothing prints it. `--org` makes one key for every app, kept as organization secrets every repository reads; a repository's own secrets of those names win. Run it in the app's Android shell. |
|
|
59
59
|
| `app_icons` | `x-app-icons [app folder]`: every icon an app ships generated from its `resources/icon.svg`, as the Design Guidelines ask: `resources/icon.png` for the desktop, the Android launcher icons at each density with an adaptive icon on white when there is an `android/` project, and `icon.svg`, `icon-192.png` and `icon-512.png` in `src/web/public` when there is one. Drawn with `@resvg/resvg-js`, an optional peer the app installs as a dev dependency. |
|
|
60
60
|
| `change_checks`, `change_checks_git`, `change_checks_cli` | Checks on a change that any repository's CI runs, as `x-app-check` (see [Change checks](#change-checks)): `commits` (Conventional Commits, the `Assisted-by` trailer in the organisation's repositories and nowhere else, no AI mention outside it), `secrets` (keys and tokens in added lines, commit messages and added `.env` files, naming only the kind and place, never the value), `leftovers` (console logging, `debugger`, code commented out, a TODO without an issue), `comments` (a comment longer than one line, but for a file's overview), `coverage` (a floor lowered or code newly left out), `x-libs` (an import of a library X-App wraps) and `dependencies` (each new one named with its licence, failing a licence not allowed, read as SPDX by `spdx-satisfies`); each a pure function on a described `Change` giving `{ gate, outcome, findings }` with file:line, reading only the code around strings and regular expressions; `create_check_registry` for an app's own checks, `x_tech_options` the defaults, and `read_change` reading a change from git, its `base` resolved to a commit; `run_check_command` runs the command for an app with its own checks, defaults and name. |
|
|
61
61
|
| `certificates`, `certificate_protocol`, `electron/certificates` | Servers whose https certificate the device refuses, such as a home server's self-signed one: `check_certificate` reads the certificate and what is wrong with it (self-signed, unknown authority, wrong name, expired, not yet valid), `create_certificate_trust` keeps the ones the user trusts in a JSON file, each for its own host and exact fingerprint, re-checked before it is saved, and its `methods` are the page's calls; `trust_in_session` makes Chromium accept them in a session, the window's from the next start, and `trusting_fetch` sends the main process's requests, such as the sync client's, through a Chromium session made fresh each time the list changes, so a new choice holds at once; `use_in_node` also hands them to Node's own https, which then accepts a self-signed server whose name matches. |
|
|
@@ -249,7 +249,7 @@ The rest of an app's files are short calls into X-App too:
|
|
|
249
249
|
and open the app on it, never on a connected phone.
|
|
250
250
|
- **Android**: `npm run build:android` builds the phone's page and runs `x-app-android`, which makes or updates the
|
|
251
251
|
Capacitor project in `android/`, so the app keeps only `capacitor.config.json` and leaves `android/` out of git.
|
|
252
|
-
`x-app-android-key
|
|
252
|
+
`x-app-android-key --org <org>` makes the organization's release key once and stores it as organization secrets every app signs with (without `--org`, one app's key as its repository's secrets).
|
|
253
253
|
- **CI**: the app's `ci` job runs `x-tech-laboratories/X-App/.github/actions/app-ci@main`, its `nix` job
|
|
254
254
|
`app-nix@main` with the targets to build, and its Dependabot workflow `app-dependabot-auto-merge@main`. Every push to
|
|
255
255
|
`main` is a release: an Android app's `android` job runs `app-android@main` with `release: push` and the release key's
|
|
@@ -5,6 +5,9 @@ export interface KeyPlan {
|
|
|
5
5
|
keystore: string;
|
|
6
6
|
password_file: string;
|
|
7
7
|
alias: string;
|
|
8
|
+
org?: string;
|
|
8
9
|
}
|
|
9
10
|
export declare function key_plan(app_folder: string, folder?: string, home?: string): KeyPlan;
|
|
11
|
+
export declare function org_key_plan(org: string, folder?: string, home?: string): KeyPlan;
|
|
10
12
|
export declare function make_release_key(plan: KeyPlan, run?: RunProgram): void;
|
|
13
|
+
export declare function plan_of_args(args: readonly string[]): KeyPlan;
|
package/dist/app_android_key.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// The `x-app-android-key [app folder]`
|
|
3
|
-
// secrets
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// The `x-app-android-key [app folder] [key folder]` and `x-app-android-key --org <org> [key folder]` commands: an
|
|
3
|
+
// Android release key, made once and stored as the secrets X-App's `app-android` action signs with, without ever
|
|
4
|
+
// printing it. With --org the key is the organization's, one for every app, stored as organization secrets every
|
|
5
|
+
// repository reads; a repository's own secrets of the same names still win. The key lives in ~/.local/share/<name>/signing
|
|
6
|
+
// unless a folder is given, and is never replaced, since Android installs an update only when it carries the same key.
|
|
7
|
+
// Run it where keytool is (the app's Android shell), with gh signed in.
|
|
6
8
|
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
7
9
|
import { spawnSync } from "node:child_process";
|
|
8
10
|
import { randomBytes } from "node:crypto";
|
|
@@ -16,12 +18,24 @@ const run_program = (program, args, input) => {
|
|
|
16
18
|
if (result.status !== 0)
|
|
17
19
|
throw new Error(`${program} ${args[0] ?? ""} failed`);
|
|
18
20
|
};
|
|
19
|
-
// Where
|
|
20
|
-
|
|
21
|
-
const { name } = JSON.parse(readFileSync(join(app_folder, "package.json"), "utf8"));
|
|
21
|
+
// Where a key named after `name` goes: the user's data folder, unless a folder is given.
|
|
22
|
+
function plan_for(name, folder, home) {
|
|
22
23
|
const signing = folder ?? join(home, ".local", "share", name, "signing");
|
|
23
24
|
return { folder: signing, keystore: join(signing, `${name}-release.p12`), password_file: join(signing, "keystore-password.txt"), alias: name };
|
|
24
25
|
}
|
|
26
|
+
// Where the app's key goes: named after its package.
|
|
27
|
+
export function key_plan(app_folder, folder, home = homedir()) {
|
|
28
|
+
const { name } = JSON.parse(readFileSync(join(app_folder, "package.json"), "utf8"));
|
|
29
|
+
return plan_for(name, folder, home);
|
|
30
|
+
}
|
|
31
|
+
// Where an organization's key goes: named after the organization, its secrets the organization's.
|
|
32
|
+
export function org_key_plan(org, folder, home = homedir()) {
|
|
33
|
+
return { ...plan_for(org, folder, home), org };
|
|
34
|
+
}
|
|
35
|
+
// Where gh stores a secret: the organization's, read by every repository, or the current repository's.
|
|
36
|
+
function secret_args(plan, name) {
|
|
37
|
+
return plan.org ? ["secret", "set", name, "--org", plan.org, "--visibility", "all"] : ["secret", "set", name];
|
|
38
|
+
}
|
|
25
39
|
// Makes the key with one random password for the keystore and the key, then sets the three secrets with gh; refuses a
|
|
26
40
|
// key already there, which is the app's for good.
|
|
27
41
|
export function make_release_key(plan, run = run_program) {
|
|
@@ -35,13 +49,22 @@ export function make_release_key(plan, run = run_program) {
|
|
|
35
49
|
"-dname", "CN=X-Tech Laboratories, O=X-Tech Laboratories",
|
|
36
50
|
"-storepass:file", plan.password_file, "-keypass:file", plan.password_file,
|
|
37
51
|
]);
|
|
38
|
-
run("gh",
|
|
39
|
-
run("gh",
|
|
40
|
-
run("gh",
|
|
52
|
+
run("gh", secret_args(plan, "ANDROID_KEYSTORE_BASE64"), readFileSync(plan.keystore).toString("base64"));
|
|
53
|
+
run("gh", secret_args(plan, "ANDROID_KEYSTORE_PASSWORD"), readFileSync(plan.password_file));
|
|
54
|
+
run("gh", secret_args(plan, "ANDROID_KEY_ALIAS"), plan.alias);
|
|
55
|
+
}
|
|
56
|
+
// The plan the command line asks for: `--org <org> [folder]`, or `[app folder] [folder]`.
|
|
57
|
+
export function plan_of_args(args) {
|
|
58
|
+
if (args[0] === "--org") {
|
|
59
|
+
if (!args[1])
|
|
60
|
+
throw new Error("--org needs the organization's name");
|
|
61
|
+
return org_key_plan(args[1], args[2]);
|
|
62
|
+
}
|
|
63
|
+
return key_plan(resolve(args[0] ?? "."), args[1]);
|
|
41
64
|
}
|
|
42
65
|
if (import.meta.main) {
|
|
43
66
|
try {
|
|
44
|
-
const plan =
|
|
67
|
+
const plan = plan_of_args(process.argv.slice(2));
|
|
45
68
|
make_release_key(plan);
|
|
46
69
|
console.info(`Saved the key in ${plan.folder} and uploaded it to GitHub.`);
|
|
47
70
|
console.info("Back up both files in that folder; losing them means no later build can install over this app.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-tech-laboratories/x-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.117.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": {
|