@assemblyline/al-orc 0.1.1 → 0.3.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/CHANGELOG.md +31 -0
- package/README.md +8 -3
- package/package.json +1 -1
- package/src/cli/_helpers.js +4 -3
- package/src/cli/config/add.js +1 -0
- package/src/cli/config/current.js +1 -0
- package/src/cli/config/index.js +1 -0
- package/src/cli/config/list.js +1 -0
- package/src/cli/config/remove.js +1 -0
- package/src/cli/config/use.js +1 -0
- package/src/cli/config-store.js +8 -7
- package/src/cli/factory-sessions/index.js +1 -0
- package/src/cli/factory-sessions/list.js +1 -0
- package/src/cli/factory-sessions/show.js +1 -0
- package/src/cli/index.js +15 -3
- package/src/cli/lines/index.js +1 -0
- package/src/cli/lines/list.js +9 -5
- package/src/cli/lines/pull.js +1 -0
- package/src/cli/lines/push.js +1 -0
- package/src/cli/lines/show.js +1 -0
- package/src/cli/login.js +96 -0
- package/src/cli/shared/edit-tags.js +10 -9
- package/src/cli/stations/archive.js +1 -0
- package/src/cli/stations/delete.js +1 -0
- package/src/cli/stations/edit.js +11 -10
- package/src/cli/stations/index.js +6 -5
- package/src/cli/stations/list.js +10 -6
- package/src/cli/stations/pull.js +10 -9
- package/src/cli/stations/push.js +9 -8
- package/src/cli/stations/run.js +12 -5
- package/src/cli/stations/show.js +1 -0
- package/src/cli/status.js +1 -0
- package/src/cli/supporting-docs/index.js +1 -0
- package/src/cli/supporting-docs/show.js +1 -0
- package/src/cli/tags/create.js +1 -0
- package/src/cli/tags/delete.js +1 -0
- package/src/cli/tags/edit.js +1 -0
- package/src/cli/tags/index.js +1 -0
- package/src/cli/tags/list.js +1 -0
- package/src/cli/utils/format.js +3 -38
- package/src/cli/utils/line-files.js +1 -0
- package/src/cli/utils/station-files.js +2 -1
- package/src/cli/utils/station-labels.js +1 -0
- package/src/cli/work-records/cancel.js +1 -0
- package/src/cli/work-records/edit.js +1 -0
- package/src/cli/work-records/index.js +2 -0
- package/src/cli/work-records/list.js +3 -2
- package/src/cli/work-records/show.js +1 -0
- package/src/http.js +7 -8
- package/src/index.js +2 -2
- package/src/resources/lines.js +1 -1
- package/src/resources/stations.js +2 -2
- package/src/resources/work-records.js +4 -3
- package/src/types/api/Line.types.js +1 -0
- package/src/types/api/Station.types.js +3 -1
- package/src/types/api/SupportingDoc.types.js +6 -0
- package/src/types/api/Tag.types.js +2 -0
- package/src/types/api/WorkRecord.types.js +7 -0
- package/src/types/general/Credentials.types.js +1 -1
- package/src/types/general/Transport.types.js +1 -0
- package/src/types/general/index.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-10-26
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `al-orc login`: sign in through the browser instead of pasting a key and secret. Opens
|
|
14
|
+
the Orchestrator's approve page (`--no-browser` only prints the URL, e.g. over SSH), where
|
|
15
|
+
you pick one or more orgs; saves one profile per org, named after it (an existing name gets
|
|
16
|
+
the org id appended). Orgs you already have a profile for show as connected. The current
|
|
17
|
+
profile changes only when there was none.
|
|
18
|
+
|
|
19
|
+
## [0.2.0] - 2026-10-19
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
- `stations run <id> --key=value` passes extra flags as step overrides again; strict
|
|
23
|
+
argument checking rejected them (broken since fob-orc 2026-07-26). Kebab-case flags become
|
|
24
|
+
snake_case keys (`--max-files=3` → `max_files`), and yargs' camelCase copies are no longer
|
|
25
|
+
sent. Every other command still rejects unknown flags.
|
|
26
|
+
- `work-records list --page <n>` works, as its "use --page" hint says.
|
|
27
|
+
- `lines list` and `stations list` honour `--page` and `--limit` instead of always returning the
|
|
28
|
+
first 100, and print the same next-page hint.
|
|
29
|
+
|
|
30
|
+
### Removed
|
|
31
|
+
- **BREAKING (library):** the `location` credential and its `X-Location` header. Only the
|
|
32
|
+
factory protocol (`/api/factory/*`) reads it, and al-orc never calls that.
|
|
33
|
+
- `formatCsv`, `formatCurrency` and `formatAmount` from `format.js`, unused since the fork.
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
- Every source file is `// @ts-check`ed, and the API types now cover the fields the CLI reads
|
|
37
|
+
(work-record timings and errors, supporting-document metadata, tag usage).
|
|
38
|
+
- `stations delete --cascade` and the code no longer say server support is pending; the
|
|
39
|
+
orchestrator supports it.
|
|
40
|
+
|
|
10
41
|
## [0.1.1] - 2026-10-19
|
|
11
42
|
|
|
12
43
|
### Fixed
|
package/README.md
CHANGED
|
@@ -6,13 +6,18 @@ records.
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install -g @assemblyline/al-orc
|
|
9
|
-
al-orc
|
|
9
|
+
al-orc login # pick orgs in the browser; one profile per org
|
|
10
10
|
al-orc status # org and key the profile belongs to
|
|
11
11
|
al-orc lines push --all && al-orc stations push --all # from a factory repo root
|
|
12
12
|
al-orc stations run EX0
|
|
13
13
|
al-orc work-records list --station EX0
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
`al-orc login` opens the Orchestrator's approve page (over SSH, add `--no-browser` and open the
|
|
17
|
+
printed link on any device). Orgs you already have a profile for show as connected; the current
|
|
18
|
+
profile changes only when there was none. To add a key by hand instead:
|
|
19
|
+
`al-orc config profiles add acme --api-key <key> --api-secret <secret>`.
|
|
20
|
+
|
|
16
21
|
Profiles live in `~/.assemblyline/al-orc/config.yml` (mode 0600; override the folder with
|
|
17
22
|
`AL_ORC_CONFIG_DIR`). The CLI never reads `.env`.
|
|
18
23
|
|
|
@@ -56,11 +61,11 @@ call it, so they can't drift.
|
|
|
56
61
|
Every command's terminal output follows these. They were implicit for a long time and drifted —
|
|
57
62
|
`format.js` is copy-pasted across six sibling CLIs and each copy diverged — so they are written down
|
|
58
63
|
here and covered by `tests/cli/format.test.js`. Use the `src/cli/utils/format.js` helpers rather than
|
|
59
|
-
formatting inline; that is what keeps `al-orc` and `al-
|
|
64
|
+
formatting inline; that is what keeps `al-orc` and `al-control` agreeing.
|
|
60
65
|
|
|
61
66
|
**Timestamps** — always `formatDate()`, never `toISOString()` or a raw `Date`. Output is the
|
|
62
67
|
operator's **local** timezone, because everything these get compared against (`pm2 logs`, file mtimes,
|
|
63
|
-
`al-
|
|
68
|
+
`al-control` output) is local. The orchestrator returns UTC, so printing it verbatim silently misread
|
|
64
69
|
every timestamp by the local offset. Name the zone **once** per table or block via `localTzLabel()` in
|
|
65
70
|
the column header — `CREATED (${localTzLabel()})` — never per row. Durations use `formatDuration()`.
|
|
66
71
|
|
package/package.json
CHANGED
package/src/cli/_helpers.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* Shared yargs helpers.
|
|
3
4
|
*/
|
|
@@ -41,7 +42,7 @@ export function paginationOptions(yargs) {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
// Print the credential-source hint at most once per invocation.
|
|
44
|
-
let
|
|
45
|
+
let is_hint_printed = false;
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
48
|
* Resolve the current command's credentials from the CLI config, printing a
|
|
@@ -50,9 +51,9 @@ let hintPrinted = false;
|
|
|
50
51
|
*/
|
|
51
52
|
export function requireCreds() {
|
|
52
53
|
const creds = resolveCredentials();
|
|
53
|
-
if (!
|
|
54
|
+
if (!is_hint_printed) {
|
|
54
55
|
console.error(`(using orchestrator credentials from ${creds.source})`);
|
|
55
|
-
|
|
56
|
+
is_hint_printed = true;
|
|
56
57
|
}
|
|
57
58
|
return creds;
|
|
58
59
|
}
|
package/src/cli/config/add.js
CHANGED
package/src/cli/config/index.js
CHANGED
package/src/cli/config/list.js
CHANGED
package/src/cli/config/remove.js
CHANGED
package/src/cli/config/use.js
CHANGED
package/src/cli/config-store.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* CLI credential store — reads/writes ~/.assemblyline/al-orc/config.yml (mode 0600) and
|
|
3
4
|
* resolves which credentials the current command uses.
|
|
@@ -19,11 +20,11 @@ import yaml from 'js-yaml';
|
|
|
19
20
|
const CONFIG_DIR = process.env.AL_ORC_CONFIG_DIR || join(homedir(), '.assemblyline', 'al-orc');
|
|
20
21
|
const CONFIG_PATH = join(CONFIG_DIR, 'config.yml');
|
|
21
22
|
|
|
22
|
-
let
|
|
23
|
+
let org_override = null;
|
|
23
24
|
|
|
24
25
|
/** Set by the `--profile <name>` global flag (alias `--org`; yargs middleware). Beats current_org. */
|
|
25
26
|
export function setOrgOverride(name) {
|
|
26
|
-
|
|
27
|
+
org_override = name;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export function loadConfig() {
|
|
@@ -89,15 +90,15 @@ export function listProfiles() {
|
|
|
89
90
|
* Precedence: `--profile`/`--org` override > config `current_org`. The CLI's
|
|
90
91
|
* credential model is profiles (config.yml); it does not read env — an env var
|
|
91
92
|
* that silently overrode the active profile would be a footgun.
|
|
92
|
-
* @returns {{ api_url: string, api_key: string, api_secret: string, source: string }}
|
|
93
|
+
* @returns {{ api_url: string, api_key: string, api_secret: string, name: string, source: string }}
|
|
93
94
|
*/
|
|
94
95
|
export function resolveCredentials() {
|
|
95
96
|
const cfg = loadConfig();
|
|
96
97
|
|
|
97
|
-
if (
|
|
98
|
-
const org = cfg.orgs[
|
|
99
|
-
if (!org) throw new Error(`Profile '${
|
|
100
|
-
return { ...org, name:
|
|
98
|
+
if (org_override) {
|
|
99
|
+
const org = cfg.orgs[org_override];
|
|
100
|
+
if (!org) throw new Error(`Profile '${org_override}' is not configured. Run \`al-orc config profiles add ${org_override}\`.`);
|
|
101
|
+
return { ...org, name: org_override, source: `profile '${org_override}'` };
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
if (cfg.current_org && cfg.orgs[cfg.current_org]) {
|
package/src/cli/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* CLI entry point — three-level command tree:
|
|
3
4
|
*
|
|
4
5
|
* al-orc <resource> <action> [target] [options]
|
|
5
6
|
*
|
|
6
|
-
* The orchestrator control plane (canonical station
|
|
7
|
+
* The orchestrator control plane (canonical line and station definitions, work
|
|
7
8
|
* records, tags, supporting docs). Credentials come from ~/.assemblyline/al-orc/config.yml;
|
|
8
|
-
* `config` manages them. (
|
|
9
|
-
*
|
|
9
|
+
* `config` manages them. (Bins and pm2 live in `al-control`; running a step
|
|
10
|
+
* is lib-factory's `factory` command. Not here.)
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
import yargs from 'yargs';
|
|
@@ -21,6 +22,8 @@ import { buildSupportingDocsSubcommands } from './supporting-docs/index.js';
|
|
|
21
22
|
import { buildFactorySessionsSubcommands } from './factory-sessions/index.js';
|
|
22
23
|
import { safe, localOptions } from './_helpers.js';
|
|
23
24
|
import { statusHandler } from './status.js';
|
|
25
|
+
import { loginHandler } from './login.js';
|
|
26
|
+
import { DEFAULT_API_URL } from '../http.js';
|
|
24
27
|
|
|
25
28
|
export function run(argv) {
|
|
26
29
|
return yargs(argv)
|
|
@@ -34,6 +37,15 @@ export function run(argv) {
|
|
|
34
37
|
.middleware((argv) => {
|
|
35
38
|
if (argv.profile) setOrgOverride(argv.profile);
|
|
36
39
|
})
|
|
40
|
+
.command(
|
|
41
|
+
'login',
|
|
42
|
+
'Sign in through the browser, pick orgs, and save one profile per org',
|
|
43
|
+
(y) =>
|
|
44
|
+
localOptions(y)
|
|
45
|
+
.option('api-url', { describe: 'Orchestrator URL (origin only)', type: 'string', default: DEFAULT_API_URL })
|
|
46
|
+
.option('browser', { describe: 'Open the approve page; --no-browser only prints its URL', type: 'boolean', default: true }),
|
|
47
|
+
safe(loginHandler),
|
|
48
|
+
)
|
|
37
49
|
.command('config <resource>', 'Manage credential profiles (alias: orgs)', buildConfigSubcommands)
|
|
38
50
|
.command('lines <action>', 'Manage lines (a line owns the location its stations run at)', buildLinesSubcommands)
|
|
39
51
|
.command('stations <action>', 'Query and run stations (orchestrator definitions)', buildStationsSubcommands)
|
package/src/cli/lines/index.js
CHANGED
package/src/cli/lines/list.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { clientFor } from '../_helpers.js';
|
|
2
|
-
import { formatTable } from '../utils/format.js';
|
|
3
|
+
import { formatTable, formatPaginationHint } from '../utils/format.js';
|
|
3
4
|
|
|
4
5
|
/** `al-orc lines list` — lines from the orchestrator, with their station codes. */
|
|
5
6
|
export async function listLinesHandler(argv) {
|
|
6
|
-
const { location, json, includeArchived } = argv || {};
|
|
7
|
+
const { location, json, includeArchived: include_archived, page, limit } = argv || {};
|
|
7
8
|
|
|
8
9
|
const orc = clientFor();
|
|
9
|
-
const { data } = await orc.lines.list({ location, include_archived
|
|
10
|
+
const { data, page_context } = await orc.lines.list({ location, include_archived, page, limit });
|
|
10
11
|
const lines = data || [];
|
|
11
12
|
|
|
12
13
|
if (json) {
|
|
@@ -25,12 +26,15 @@ export async function listLinesHandler(argv) {
|
|
|
25
26
|
l.location || '—',
|
|
26
27
|
String(l.stations?.length ?? 0),
|
|
27
28
|
(l.stations || []).map((s) => s.short_code || s.id).join(', ') || '—',
|
|
28
|
-
...(
|
|
29
|
+
...(include_archived ? [l.archived_at ? 'yes' : '—'] : []),
|
|
29
30
|
]);
|
|
30
|
-
const headers = ['CODE', 'NAME', 'LOCATION', 'STATIONS', 'MEMBERS', ...(
|
|
31
|
+
const headers = ['CODE', 'NAME', 'LOCATION', 'STATIONS', 'MEMBERS', ...(include_archived ? ['ARCHIVED'] : [])];
|
|
31
32
|
|
|
32
33
|
console.log(formatTable(headers, rows));
|
|
33
34
|
console.log('');
|
|
34
35
|
const station_total = lines.reduce((n, l) => n + (l.stations?.length ?? 0), 0);
|
|
35
36
|
console.log(`Total: ${lines.length} lines, ${station_total} stations`);
|
|
37
|
+
|
|
38
|
+
const hint = formatPaginationHint(page_context);
|
|
39
|
+
if (hint) console.log(hint);
|
|
36
40
|
}
|
package/src/cli/lines/pull.js
CHANGED
package/src/cli/lines/push.js
CHANGED
package/src/cli/lines/show.js
CHANGED
package/src/cli/login.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* `al-orc login` — get API keys without copying them from the settings page. Starts a login
|
|
4
|
+
* request on the Orchestrator (sending the key ids of the existing profiles, so the approve
|
|
5
|
+
* page shows those orgs as already connected), opens the approve page in the browser (or
|
|
6
|
+
* prints its URL), polls until the user picks orgs and approves, then saves one profile per
|
|
7
|
+
* org. The current profile changes only when there was none.
|
|
8
|
+
*/
|
|
9
|
+
import { hostname } from 'node:os';
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
import { addOrg, loadConfig } from './config-store.js';
|
|
12
|
+
|
|
13
|
+
const POLL_INTERVAL_MS = 2000;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} url
|
|
17
|
+
* @param {Object} body
|
|
18
|
+
*/
|
|
19
|
+
async function postJson(url, body) {
|
|
20
|
+
const res = await fetch(url, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: { 'Content-Type': 'application/json' },
|
|
23
|
+
body: JSON.stringify(body),
|
|
24
|
+
});
|
|
25
|
+
const json = await res.json().catch(() => ({}));
|
|
26
|
+
return { status: res.status, data: json.data, error: json.error };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Best effort: the URL is always printed too, for SSH sessions and headless machines. */
|
|
30
|
+
function openBrowser(url) {
|
|
31
|
+
const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'explorer' : 'xdg-open';
|
|
32
|
+
try {
|
|
33
|
+
spawn(cmd, [url], { stdio: 'ignore', detached: true }).on('error', () => {}).unref();
|
|
34
|
+
} catch {
|
|
35
|
+
// printed URL is the fallback
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Poll /api/cli/token until the request is approved or expires.
|
|
41
|
+
* @param {{ api_url: string, device_code: string, expires_in: number, interval_ms?: number }} args
|
|
42
|
+
* @returns {Promise<{ keys: Array<{ org: { id: string, name: string }, api_key: string, api_secret: string }> }>}
|
|
43
|
+
*/
|
|
44
|
+
export async function pollForKey({ api_url, device_code, expires_in, interval_ms = POLL_INTERVAL_MS }) {
|
|
45
|
+
const deadline = Date.now() + expires_in * 1000;
|
|
46
|
+
while (Date.now() < deadline) {
|
|
47
|
+
const { status, data, error } = await postJson(`${api_url}/api/cli/token`, { device_code });
|
|
48
|
+
if (status === 200 && data?.status === 'approved') return data;
|
|
49
|
+
if (status !== 200) throw new Error(error?.message || `Login failed (HTTP ${status}). Run \`al-orc login\` again.`);
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, interval_ms));
|
|
51
|
+
}
|
|
52
|
+
throw new Error('Login request expired. Run `al-orc login` again.');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Profile name from the org name ("Alex's org" → "alex-s-org"). A name already used by a profile
|
|
57
|
+
* gets the org id appended, so an existing profile is never overwritten.
|
|
58
|
+
* @param {{ id: string, name: string }} org
|
|
59
|
+
* @param {Set<string>} taken
|
|
60
|
+
*/
|
|
61
|
+
export function profileName(org, taken) {
|
|
62
|
+
const base = (org.name || '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || org.id;
|
|
63
|
+
return taken.has(base) ? `${base}-${org.id}` : base;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function loginHandler(argv) {
|
|
67
|
+
const api_url = argv.apiUrl.replace(/\/+$/, '');
|
|
68
|
+
const cfg = loadConfig();
|
|
69
|
+
const known_keys = Object.values(cfg.orgs).map((o) => o.api_key).filter(Boolean);
|
|
70
|
+
const start = await postJson(`${api_url}/api/cli/login`, { name: `al-orc on ${hostname()}`, known_keys });
|
|
71
|
+
if (start.status !== 201) {
|
|
72
|
+
throw new Error(start.error?.message || `Could not start a login on ${api_url} (HTTP ${start.status}).`);
|
|
73
|
+
}
|
|
74
|
+
const { device_code, verification_url, expires_in } = start.data;
|
|
75
|
+
|
|
76
|
+
console.log('Pick the orgs to add and approve in your browser:');
|
|
77
|
+
console.log(` ${verification_url}`);
|
|
78
|
+
if (argv.browser) openBrowser(verification_url);
|
|
79
|
+
console.log('Waiting for approval…');
|
|
80
|
+
|
|
81
|
+
const { keys } = await pollForKey({ api_url, device_code, expires_in });
|
|
82
|
+
const taken = new Set(Object.keys(cfg.orgs));
|
|
83
|
+
for (const { org, api_key, api_secret } of keys) {
|
|
84
|
+
const name = profileName(org, taken);
|
|
85
|
+
taken.add(name);
|
|
86
|
+
addOrg(name, { api_url, api_key, api_secret });
|
|
87
|
+
console.log(`Added profile '${name}' for ${org.name}.`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const { current_org } = loadConfig();
|
|
91
|
+
if (cfg.current_org) {
|
|
92
|
+
console.log(`Current profile is still '${current_org}'. Switch with \`al-orc config profiles use <name>\`.`);
|
|
93
|
+
} else {
|
|
94
|
+
console.log(`Current profile: '${current_org}'.`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* Shared --add-tag / --remove-tag flow for taggable entities (stations,
|
|
3
4
|
* work-records). Works against a resource namespace that exposes getTags/setTags
|
|
@@ -6,15 +7,15 @@
|
|
|
6
7
|
* @param {{ getTags: (id: string) => Promise<any[]>, setTags: (id: string, tagIds: string[]) => Promise<any> }} ns
|
|
7
8
|
* @param {{ ensure: (name: string) => Promise<{id: string, name: string}>, resolveNames: (names: string[]) => Promise<string[]> }} tags
|
|
8
9
|
* @param {string} id
|
|
9
|
-
* @param {string[]}
|
|
10
|
-
* @param {string[]}
|
|
10
|
+
* @param {string[]} add_tags
|
|
11
|
+
* @param {string[]} remove_tags
|
|
11
12
|
*/
|
|
12
|
-
export async function editEntityTags(ns, tags, id,
|
|
13
|
+
export async function editEntityTags(ns, tags, id, add_tags, remove_tags) {
|
|
13
14
|
const current = await ns.getTags(id);
|
|
14
15
|
let ids = current.map((t) => t.id);
|
|
15
16
|
const changes = [];
|
|
16
17
|
|
|
17
|
-
for (const name of
|
|
18
|
+
for (const name of add_tags) {
|
|
18
19
|
const tag = await tags.ensure(name);
|
|
19
20
|
if (!ids.includes(tag.id)) {
|
|
20
21
|
ids.push(tag.id);
|
|
@@ -24,14 +25,14 @@ export async function editEntityTags(ns, tags, id, addTags, removeTags) {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
for (const name of
|
|
28
|
-
const [
|
|
29
|
-
if (!
|
|
28
|
+
for (const name of remove_tags) {
|
|
29
|
+
const [resolved_id] = await tags.resolveNames([name]).catch(() => [null]);
|
|
30
|
+
if (!resolved_id) {
|
|
30
31
|
console.error(` Warning: tag "${name}" not found, skipping removal`);
|
|
31
32
|
continue;
|
|
32
33
|
}
|
|
33
|
-
if (ids.includes(
|
|
34
|
-
ids = ids.filter((x) => x !==
|
|
34
|
+
if (ids.includes(resolved_id)) {
|
|
35
|
+
ids = ids.filter((x) => x !== resolved_id);
|
|
35
36
|
changes.push(` - ${name}`);
|
|
36
37
|
} else {
|
|
37
38
|
changes.push(` ${name} (not present)`);
|
package/src/cli/stations/edit.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { clientFor } from '../_helpers.js';
|
|
2
3
|
import { editEntityTags } from '../shared/edit-tags.js';
|
|
3
4
|
|
|
4
5
|
/** `al-orc stations edit <id>` — set short_code and/or add/remove tags. */
|
|
5
6
|
export async function editStationHandler(argv) {
|
|
6
|
-
const { id, shortCode, addTag, removeTag } = argv;
|
|
7
|
+
const { id, shortCode: short_code, addTag: add_tag, removeTag: remove_tag } = argv;
|
|
7
8
|
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const add_tags = add_tag ? [].concat(add_tag) : [];
|
|
10
|
+
const remove_tags = remove_tag ? [].concat(remove_tag) : [];
|
|
11
|
+
const has_tag_changes = add_tags.length > 0 || remove_tags.length > 0;
|
|
11
12
|
|
|
12
|
-
if (!
|
|
13
|
+
if (!has_tag_changes && short_code === undefined) {
|
|
13
14
|
console.error('Usage: al-orc stations edit <id|short_code> --short-code P1 --add-tag <name> [--remove-tag <name>]');
|
|
14
15
|
console.error('At least one of --short-code, --add-tag, or --remove-tag is required');
|
|
15
16
|
process.exit(1);
|
|
@@ -18,13 +19,13 @@ export async function editStationHandler(argv) {
|
|
|
18
19
|
console.log(`Station: ${id}`);
|
|
19
20
|
const orc = clientFor();
|
|
20
21
|
|
|
21
|
-
if (
|
|
22
|
-
await orc.stations.update(id, { short_code:
|
|
23
|
-
console.log(`Short code set: ${
|
|
22
|
+
if (short_code !== undefined) {
|
|
23
|
+
await orc.stations.update(id, { short_code: short_code || null });
|
|
24
|
+
console.log(`Short code set: ${short_code || '(cleared)'}`);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
if (
|
|
27
|
-
await editEntityTags(orc.stations, orc.tags, id,
|
|
27
|
+
if (has_tag_changes) {
|
|
28
|
+
await editEntityTags(orc.stations, orc.tags, id, add_tags, remove_tags);
|
|
28
29
|
console.log('Tags updated');
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* Subtree builder for `al-orc stations <action>`.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
* the CLI vocabulary is "station". These are the CANONICAL definitions from the
|
|
6
|
-
* orchestrator (contrast `al-factory stations status`, which is local run-state).
|
|
5
|
+
* These are the CANONICAL definitions from the orchestrator (contrast `al-control stations status`, which reads the bins).
|
|
7
6
|
*/
|
|
8
7
|
|
|
9
8
|
import { safe, paginationOptions, localOptions } from '../_helpers.js';
|
|
@@ -46,7 +45,9 @@ export function buildStationsSubcommands(yargs) {
|
|
|
46
45
|
(y) =>
|
|
47
46
|
localOptions(y.positional('id', { describe: 'Station ID or short_code', type: 'string' }))
|
|
48
47
|
.option('scenario', { describe: 'Apply a local station scenario (.orchestrator/scenarios/stations/<code>/)', type: 'string' })
|
|
49
|
-
.option('json', { describe: 'Output raw JSON', type: 'boolean' })
|
|
48
|
+
.option('json', { describe: 'Output raw JSON', type: 'boolean' })
|
|
49
|
+
// Any other --key=value is a step override, so unknown flags are the point here.
|
|
50
|
+
.strict(false),
|
|
50
51
|
safe(runStationHandler),
|
|
51
52
|
)
|
|
52
53
|
.command(
|
|
@@ -97,7 +98,7 @@ export function buildStationsSubcommands(yargs) {
|
|
|
97
98
|
'Permanently delete a station',
|
|
98
99
|
(y) =>
|
|
99
100
|
localOptions(y.positional('id', { describe: 'Station ID', type: 'string' }))
|
|
100
|
-
.option('cascade', { describe: 'Also delete
|
|
101
|
+
.option('cascade', { describe: 'Also delete its work records (otherwise refused while any exist)', type: 'boolean' }),
|
|
101
102
|
safe(deleteStationHandler),
|
|
102
103
|
)
|
|
103
104
|
.demandCommand(1, 'Specify an action: list, show, run, edit, pull, push, archive, unarchive, delete');
|
package/src/cli/stations/list.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { clientFor } from '../_helpers.js';
|
|
2
|
-
import { formatTable } from '../utils/format.js';
|
|
3
|
+
import { formatTable, formatPaginationHint } from '../utils/format.js';
|
|
3
4
|
|
|
4
5
|
/** `al-orc stations list` — canonical station definitions from the orchestrator. */
|
|
5
6
|
export async function listStationsHandler(argv) {
|
|
6
|
-
const { tag, line, json, includeArchived } = argv || {};
|
|
7
|
+
const { tag, line, json, includeArchived: include_archived, page, limit } = argv || {};
|
|
7
8
|
|
|
8
9
|
const orc = clientFor();
|
|
9
|
-
const { data } = await orc.stations.list({ tag, line, include_archived
|
|
10
|
+
const { data, page_context } = await orc.stations.list({ tag, line, include_archived, page, limit });
|
|
10
11
|
const stations = data || [];
|
|
11
12
|
|
|
12
13
|
if (json) {
|
|
@@ -24,11 +25,14 @@ export async function listStationsHandler(argv) {
|
|
|
24
25
|
s.id,
|
|
25
26
|
s.name || '—',
|
|
26
27
|
String(s.steps ? s.steps.length : 0),
|
|
27
|
-
...(
|
|
28
|
+
...(include_archived ? [s.archived || s.archived_at ? 'yes' : '—'] : []),
|
|
28
29
|
]);
|
|
29
|
-
const headers = ['CODE', 'ID', 'NAME', 'STEPS', ...(
|
|
30
|
+
const headers = ['CODE', 'ID', 'NAME', 'STEPS', ...(include_archived ? ['ARCHIVED'] : [])];
|
|
30
31
|
|
|
31
32
|
console.log(formatTable(headers, rows));
|
|
32
33
|
console.log('');
|
|
33
|
-
console.log(`Total: ${stations.length} stations${
|
|
34
|
+
console.log(`Total: ${stations.length} stations${include_archived ? ' (including archived)' : ''}`);
|
|
35
|
+
|
|
36
|
+
const hint = formatPaginationHint(page_context);
|
|
37
|
+
if (hint) console.log(hint);
|
|
34
38
|
}
|
package/src/cli/stations/pull.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { clientFor } from '../_helpers.js';
|
|
2
3
|
import { saveStation, getStationsDir } from '../utils/station-files.js';
|
|
3
4
|
import { pullAllLines } from '../lines/pull.js';
|
|
@@ -7,15 +8,15 @@ import { getLinesDir } from '../utils/line-files.js';
|
|
|
7
8
|
* Convert dependency IDs to short_codes using an id→short_code map.
|
|
8
9
|
* Values without a match pass through unchanged.
|
|
9
10
|
*/
|
|
10
|
-
function dependenciesToShortCodes(dependencies,
|
|
11
|
+
function dependenciesToShortCodes(dependencies, id_to_short_code) {
|
|
11
12
|
if (!dependencies?.length) return dependencies;
|
|
12
|
-
return dependencies.map((dep) =>
|
|
13
|
+
return dependencies.map((dep) => id_to_short_code.get(dep) || dep);
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
/** Normalize a fetched station for local storage: tags → names, deps → short_codes. */
|
|
16
|
-
function normalizeForLocal(station,
|
|
17
|
+
function normalizeForLocal(station, id_to_short_code) {
|
|
17
18
|
if (station.tags) station.tags = station.tags.map((t) => (typeof t === 'string' ? t : t.name));
|
|
18
|
-
station.dependencies = dependenciesToShortCodes(station.dependencies,
|
|
19
|
+
station.dependencies = dependenciesToShortCodes(station.dependencies, id_to_short_code);
|
|
19
20
|
return station;
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -36,13 +37,13 @@ export async function pullStationsHandler(argv) {
|
|
|
36
37
|
if (id) {
|
|
37
38
|
console.log(`Saving to: ${getStationsDir()}/`);
|
|
38
39
|
// Single station — also fetch the list for dependency resolution.
|
|
39
|
-
const [station,
|
|
40
|
+
const [station, all_stations] =await Promise.all([orc.stations.get(id), orc.stations.getAll()]);
|
|
40
41
|
if (!station) {
|
|
41
42
|
console.error(`Station not found: ${id}`);
|
|
42
43
|
process.exit(1);
|
|
43
44
|
}
|
|
44
|
-
const
|
|
45
|
-
const filepath = saveStation(normalizeForLocal(station,
|
|
45
|
+
const id_to_short_code = new Map(all_stations.filter((s) => s.short_code).map((s) => [s.id, s.short_code]));
|
|
46
|
+
const filepath = saveStation(normalizeForLocal(station, id_to_short_code));
|
|
46
47
|
console.log(`Saved: ${filepath}`);
|
|
47
48
|
return;
|
|
48
49
|
}
|
|
@@ -60,12 +61,12 @@ export async function pullStationsHandler(argv) {
|
|
|
60
61
|
console.log('No stations found');
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
|
-
const
|
|
64
|
+
const id_to_short_code = new Map(stations.filter((s) => s.short_code).map((s) => [s.id, s.short_code]));
|
|
64
65
|
|
|
65
66
|
for (const summary of stations) {
|
|
66
67
|
// Fetch full details (the list may omit fields).
|
|
67
68
|
const full = await orc.stations.get(summary.id);
|
|
68
|
-
const filepath = saveStation(normalizeForLocal(full,
|
|
69
|
+
const filepath = saveStation(normalizeForLocal(full, id_to_short_code));
|
|
69
70
|
console.log(`Saved: ${filepath}`);
|
|
70
71
|
}
|
|
71
72
|
console.log('');
|
package/src/cli/stations/push.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { clientFor } from '../_helpers.js';
|
|
2
3
|
import {
|
|
3
4
|
loadStation,
|
|
@@ -46,15 +47,15 @@ async function resolveDependencies(orc, cache, dependencies) {
|
|
|
46
47
|
/** Map tag names → ids, creating any that don't exist. Returns { ids, created }. */
|
|
47
48
|
async function resolveTagNamesCreating(orc, names) {
|
|
48
49
|
const { data = [] } = await orc.tags.list();
|
|
49
|
-
const
|
|
50
|
+
const by_name = new Map(data.map((t) => [t.name, t.id]));
|
|
50
51
|
const ids = [];
|
|
51
52
|
const created = [];
|
|
52
53
|
for (const name of names) {
|
|
53
|
-
let id =
|
|
54
|
+
let id = by_name.get(name);
|
|
54
55
|
if (!id) {
|
|
55
56
|
const tag = await orc.tags.create({ name });
|
|
56
57
|
id = tag.id;
|
|
57
|
-
|
|
58
|
+
by_name.set(name, id);
|
|
58
59
|
created.push(name);
|
|
59
60
|
}
|
|
60
61
|
ids.push(id);
|
|
@@ -66,15 +67,15 @@ async function resolveTagNamesCreating(orc, names) {
|
|
|
66
67
|
* Sync tags after push. `undefined` = leave untouched; `[]` = clear all;
|
|
67
68
|
* otherwise resolve (auto-creating missing) and replace.
|
|
68
69
|
*/
|
|
69
|
-
async function syncTags(orc,
|
|
70
|
+
async function syncTags(orc, station_id, tags) {
|
|
70
71
|
if (tags === undefined) return;
|
|
71
72
|
if (tags.length === 0) {
|
|
72
|
-
await orc.stations.setTags(
|
|
73
|
+
await orc.stations.setTags(station_id, []);
|
|
73
74
|
console.log(' Tags cleared');
|
|
74
75
|
return;
|
|
75
76
|
}
|
|
76
77
|
const { ids, created } = await resolveTagNamesCreating(orc, tags);
|
|
77
|
-
await orc.stations.setTags(
|
|
78
|
+
await orc.stations.setTags(station_id, ids);
|
|
78
79
|
if (created.length > 0) console.log(` Auto-created tags: ${created.join(', ')}`);
|
|
79
80
|
console.log(` Tags synced: ${tags.join(', ')}`);
|
|
80
81
|
}
|
|
@@ -198,9 +199,9 @@ export async function pushStationsHandler(argv) {
|
|
|
198
199
|
let updatedCount = 0;
|
|
199
200
|
let createdCount = 0;
|
|
200
201
|
for (const filepath of allPaths) {
|
|
201
|
-
const
|
|
202
|
+
const has_id =!!loadStationByFilename(filepath).id;
|
|
202
203
|
await pushByFilename(orc, cache, filepath, { force });
|
|
203
|
-
if (
|
|
204
|
+
if (has_id)updatedCount++;
|
|
204
205
|
else createdCount++;
|
|
205
206
|
}
|
|
206
207
|
|
package/src/cli/stations/run.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { clientFor } from '../_helpers.js';
|
|
2
3
|
import { loadStation, loadStationScenario, listStationScenarios } from '../utils/station-files.js';
|
|
3
4
|
|
|
@@ -12,7 +13,7 @@ const COMMAND_KEYS = new Set(['id', 'scenario', 'json']);
|
|
|
12
13
|
* reserved/known key becomes a per-run override, shallow-merged into every
|
|
13
14
|
* step's config server-side.
|
|
14
15
|
*/
|
|
15
|
-
function buildStepOverrides(argv, station) {
|
|
16
|
+
export function buildStepOverrides(argv, station) {
|
|
16
17
|
const overrides = {};
|
|
17
18
|
const fromScenario = [];
|
|
18
19
|
const fromCli = [];
|
|
@@ -33,11 +34,17 @@ function buildStepOverrides(argv, station) {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
// yargs adds a camelCase copy of every kebab-case flag (--max-files → maxFiles).
|
|
38
|
+
// Step configs are snake_case, so a kebab flag becomes max_files and its
|
|
39
|
+
// camelCase copy is dropped.
|
|
40
|
+
const camel_copies = new Set(
|
|
41
|
+
Object.keys(argv).filter((k) => k.includes('-')).map((k) => k.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase())),
|
|
42
|
+
);
|
|
36
43
|
for (const [k, v] of Object.entries(argv)) {
|
|
37
|
-
if (YARGS_KEYS.has(k) || COMMAND_KEYS.has(k)) continue;
|
|
38
|
-
|
|
39
|
-
overrides[
|
|
40
|
-
fromCli.push(
|
|
44
|
+
if (YARGS_KEYS.has(k) || COMMAND_KEYS.has(k) || camel_copies.has(k)) continue;
|
|
45
|
+
const key = k.replace(/-/g, '_');
|
|
46
|
+
overrides[key] = v;
|
|
47
|
+
fromCli.push(key);
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
return { overrides, fromScenario, fromCli };
|
package/src/cli/stations/show.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { clientFor } from '../_helpers.js';
|
|
2
3
|
import { buildStationLabelMap, stationLabel } from '../utils/station-labels.js';
|
|
3
4
|
import { formatHeader, formatField, formatTable, formatSection, formatDate, formatDuration, localTzLabel, truncate } from '../utils/format.js';
|
package/src/cli/status.js
CHANGED
package/src/cli/tags/create.js
CHANGED
package/src/cli/tags/delete.js
CHANGED
package/src/cli/tags/edit.js
CHANGED
package/src/cli/tags/index.js
CHANGED
package/src/cli/tags/list.js
CHANGED
package/src/cli/utils/format.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* Shared formatting helpers for CLI output.
|
|
3
4
|
* Structured text readable by both humans and LLMs.
|
|
@@ -41,42 +42,6 @@ export function formatTable(headers, rows, options = {}) {
|
|
|
41
42
|
return [headerLine, separator, ...dataLines].join('\n');
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
/**
|
|
45
|
-
* Format rows as RFC-4180 CSV.
|
|
46
|
-
* Cells containing commas, quotes, or newlines are double-quoted, and embedded
|
|
47
|
-
* quotes are doubled. `null` / `undefined` become empty.
|
|
48
|
-
*/
|
|
49
|
-
export function formatCsv(headers, rows) {
|
|
50
|
-
const escape = (value) => {
|
|
51
|
-
if (value == null) return '';
|
|
52
|
-
const s = String(value);
|
|
53
|
-
return /[",\n\r]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s;
|
|
54
|
-
};
|
|
55
|
-
const lines = [headers.map(escape).join(',')];
|
|
56
|
-
for (const row of rows) lines.push(row.map(escape).join(','));
|
|
57
|
-
return lines.join('\r\n');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Format a decimal currency value with thousands separators and 2 decimals.
|
|
62
|
-
* Returns '' for null / undefined / 0.
|
|
63
|
-
*/
|
|
64
|
-
export function formatCurrency(value) {
|
|
65
|
-
if (value == null || value === '' || Number(value) === 0) return '';
|
|
66
|
-
return Number(value).toLocaleString('en-US', {
|
|
67
|
-
minimumFractionDigits: 2,
|
|
68
|
-
maximumFractionDigits: 2,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Format a monetary value stored as integer milli-units (× 1000).
|
|
74
|
-
*/
|
|
75
|
-
export function formatAmount(milliUnits) {
|
|
76
|
-
if (milliUnits == null || milliUnits === '' || Number(milliUnits) === 0) return '';
|
|
77
|
-
return formatCurrency(Number(milliUnits) / 1000);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
45
|
/**
|
|
81
46
|
* Format a byte count as a human-readable size. Returns '' for null/undefined.
|
|
82
47
|
* "812 B", "1.5 KB", "3.2 MB".
|
|
@@ -96,7 +61,7 @@ export function formatBytes(bytes) {
|
|
|
96
61
|
*/
|
|
97
62
|
export function formatDuration(start, end) {
|
|
98
63
|
if (!start || !end) return '—';
|
|
99
|
-
const ms = new Date(end) - new Date(start);
|
|
64
|
+
const ms = new Date(end).getTime() - new Date(start).getTime();
|
|
100
65
|
if (ms < 0) return '—';
|
|
101
66
|
const seconds = Math.floor(ms / 1000);
|
|
102
67
|
if (seconds < 60) return `${seconds}s`;
|
|
@@ -146,7 +111,7 @@ export function localTzLabel() {
|
|
|
146
111
|
* print `toISOString()` verbatim — so an operator in IST read every timestamp
|
|
147
112
|
* 5.5 hours early with nothing on screen saying so. That quietly breaks the
|
|
148
113
|
* main thing these timestamps are for: correlating against `pm2 logs`, file
|
|
149
|
-
* mtimes and `al-
|
|
114
|
+
* mtimes and `al-control` output, all of which are local.
|
|
150
115
|
*
|
|
151
116
|
* Pair with `localTzLabel()` in the surrounding header so the zone is stated
|
|
152
117
|
* once. sv-SE is used because its locale format is already `YYYY-MM-DD HH:MM:SS`.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* Local station + station-scenario file cache — the bridge between the
|
|
3
4
|
* orchestrator (remote truth) and the working tree.
|
|
@@ -7,7 +8,7 @@
|
|
|
7
8
|
*
|
|
8
9
|
* Line membership is encoded by the `line` field inside each JSON, not by folder
|
|
9
10
|
* hierarchy. (Ported from cli-fob for the al-orc pull/push/run bridges; the
|
|
10
|
-
* step
|
|
11
|
+
* step scenarios live in lib-factory's `factory` command.)
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
import fs from 'node:fs';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* Subtree builder for `al-orc work-records <action>`.
|
|
3
4
|
*/
|
|
@@ -17,6 +18,7 @@ export function buildWorkRecordsSubcommands(yargs) {
|
|
|
17
18
|
'List work records',
|
|
18
19
|
(y) =>
|
|
19
20
|
localOptions(y)
|
|
21
|
+
.option('page', { describe: 'Page number', type: 'number' })
|
|
20
22
|
.option('limit', { describe: 'Max records', type: 'number' })
|
|
21
23
|
.option('status', { describe: 'Filter by status', type: 'string' })
|
|
22
24
|
.option('station', { describe: 'Filter by station ID or short_code (e.g. EM0)', type: 'string' })
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { clientFor } from '../_helpers.js';
|
|
2
3
|
import { formatTable, formatDate, formatDuration, localTzLabel, formatPaginationHint, truncate } from '../utils/format.js';
|
|
3
4
|
import { buildStationLabelMap, stationLabel } from '../utils/station-labels.js';
|
|
4
5
|
|
|
5
6
|
/** `al-orc work-records list` — work records from the orchestrator, filterable. */
|
|
6
7
|
export async function listWorkRecordsHandler(argv) {
|
|
7
|
-
const { limit, status, station, line, tag, json } = argv;
|
|
8
|
+
const { page, limit, status, station, line, tag, json } = argv;
|
|
8
9
|
|
|
9
10
|
const orc = clientFor();
|
|
10
|
-
const { data, page_context } = await orc.workRecords.list({ limit, status, station, line, tag });
|
|
11
|
+
const { data, page_context } = await orc.workRecords.list({ page, limit, status, station, line, tag });
|
|
11
12
|
const records = data || [];
|
|
12
13
|
|
|
13
14
|
if (json) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { clientFor } from '../_helpers.js';
|
|
2
3
|
import { formatHeader, formatField, formatTable, formatSection, formatDate, formatDuration, localTzLabel } from '../utils/format.js';
|
|
3
4
|
import { buildStationLabelMap, stationLabel } from '../utils/station-labels.js';
|
package/src/http.js
CHANGED
|
@@ -44,9 +44,9 @@ export const DEFAULT_API_URL = 'https://orchestrator.assemblyline.sh';
|
|
|
44
44
|
* Resolve credentials from the explicit argument only — this module never reads
|
|
45
45
|
* `process.env`. Callers
|
|
46
46
|
* pass `{ api_key, api_secret }` (required) and optionally `api_url` (defaults to
|
|
47
|
-
* the hosted origin)
|
|
47
|
+
* the hosted origin).
|
|
48
48
|
* @param {Credentials} credentials
|
|
49
|
-
* @returns {{ api_url: string, api_key: string, api_secret: string
|
|
49
|
+
* @returns {{ api_url: string, api_key: string, api_secret: string }}
|
|
50
50
|
*/
|
|
51
51
|
function resolveCreds(credentials) {
|
|
52
52
|
const api_url = credentials?.api_url ?? DEFAULT_API_URL;
|
|
@@ -59,10 +59,10 @@ function resolveCreds(credentials) {
|
|
|
59
59
|
{ code: 'NO_CREDENTIALS' },
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
|
-
return { api_url, api_key, api_secret
|
|
62
|
+
return { api_url, api_key, api_secret };
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
/** @param {{ api_key: string, api_secret: string
|
|
65
|
+
/** @param {{ api_key: string, api_secret: string }} creds */
|
|
66
66
|
function authHeaders(creds) {
|
|
67
67
|
/** @type {Record<string, string>} */
|
|
68
68
|
const headers = {
|
|
@@ -70,7 +70,6 @@ function authHeaders(creds) {
|
|
|
70
70
|
'api-secret': creds.api_secret,
|
|
71
71
|
accept: 'application/json',
|
|
72
72
|
};
|
|
73
|
-
if (creds.location) headers['X-Location'] = creds.location;
|
|
74
73
|
return headers;
|
|
75
74
|
}
|
|
76
75
|
|
|
@@ -208,7 +207,7 @@ export async function apiGetAll(path, options = {}, { maxRows = MAX_ALL_ROWS, pa
|
|
|
208
207
|
const all = [];
|
|
209
208
|
let page = 1;
|
|
210
209
|
let pageContext = null;
|
|
211
|
-
let
|
|
210
|
+
let is_truncated = false;
|
|
212
211
|
|
|
213
212
|
while (true) {
|
|
214
213
|
const result = await apiGet(path, {
|
|
@@ -220,7 +219,7 @@ export async function apiGetAll(path, options = {}, { maxRows = MAX_ALL_ROWS, pa
|
|
|
220
219
|
|
|
221
220
|
if (all.length + rows.length > maxRows) {
|
|
222
221
|
all.push(...rows.slice(0, maxRows - all.length));
|
|
223
|
-
|
|
222
|
+
is_truncated = true;
|
|
224
223
|
break;
|
|
225
224
|
}
|
|
226
225
|
all.push(...rows);
|
|
@@ -229,7 +228,7 @@ export async function apiGetAll(path, options = {}, { maxRows = MAX_ALL_ROWS, pa
|
|
|
229
228
|
page++;
|
|
230
229
|
}
|
|
231
230
|
|
|
232
|
-
return { data: all, page_context: pageContext, truncated };
|
|
231
|
+
return { data: all, page_context: pageContext, truncated: is_truncated };
|
|
233
232
|
}
|
|
234
233
|
|
|
235
234
|
/**
|
package/src/index.js
CHANGED
|
@@ -59,8 +59,8 @@ import { buildFactorySessions } from './resources/factory-sessions.js';
|
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* @param {Credentials} credentials Required: `{ api_key, api_secret }`. Optional
|
|
62
|
-
* `api_url` (origin-only) overrides the default hosted endpoint
|
|
63
|
-
*
|
|
62
|
+
* `api_url` (origin-only) overrides the default hosted endpoint. The library
|
|
63
|
+
* never reads these from the
|
|
64
64
|
* environment — inject them explicitly.
|
|
65
65
|
* @returns {OrcClient}
|
|
66
66
|
*/
|
package/src/resources/lines.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @typedef {Object} LinesApi
|
|
20
|
-
* @property {(params?: { location?: string, include_archived?: boolean }) => Promise<{ data: Line[], page_context: object|null }>} list
|
|
20
|
+
* @property {(params?: { location?: string, include_archived?: boolean, page?: number, limit?: number }) => Promise<{ data: Line[], page_context: object|null }>} list
|
|
21
21
|
* @property {(params?: { location?: string, include_archived?: boolean }) => Promise<Line[]>} getAll
|
|
22
22
|
* @property {(id: string) => Promise<Line|null>} get
|
|
23
23
|
* @property {(data: object) => Promise<Line|null>} create
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* The station client surface. Explicit (not inferred) so callers get real
|
|
20
20
|
* checking; `buildStations`'s `@returns` binds it, so `tsc` verifies the impl.
|
|
21
21
|
* @typedef {Object} StationsApi
|
|
22
|
-
* @property {(params?: { tag?: string, line?: string, include_archived?: boolean }) => Promise<{ data: Station[], page_context: object|null }>} list
|
|
22
|
+
* @property {(params?: { tag?: string, line?: string, include_archived?: boolean, page?: number, limit?: number }) => Promise<{ data: Station[], page_context: object|null }>} list
|
|
23
23
|
* @property {(params?: { tag?: string, line?: string, include_archived?: boolean }) => Promise<Station[]>} getAll
|
|
24
24
|
* @property {(id: string) => Promise<Station|null>} get
|
|
25
25
|
* @property {(data: object) => Promise<Station|null>} create
|
|
@@ -61,7 +61,7 @@ export function buildStations(ctx) {
|
|
|
61
61
|
/** Update station fields (PUT). Returns the updated record. */
|
|
62
62
|
update: (id, data) => ctx.put(`/api/v1/stations/${enc(id)}`, data).then(unwrap),
|
|
63
63
|
|
|
64
|
-
/** Delete a station.
|
|
64
|
+
/** Delete a station. Refused while it has work records, unless `cascade` (which deletes them too). */
|
|
65
65
|
delete: (id, { cascade } = {}) =>
|
|
66
66
|
ctx.delete(`/api/v1/stations/${enc(id)}`, cascade ? { searchParams: { cascade: true } } : undefined).then(unwrap),
|
|
67
67
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @typedef {Object} WorkRecordsApi
|
|
17
|
-
* @property {(params?: { limit?: number, status?: string, station?: string, line?: string, tag?: string }) => Promise<{ data: WorkRecord[], page_context: object|null }>} list
|
|
17
|
+
* @property {(params?: { page?: number, limit?: number, status?: string, station?: string, line?: string, tag?: string }) => Promise<{ data: WorkRecord[], page_context: object|null }>} list
|
|
18
18
|
* @property {(params?: { status?: string, station?: string, line?: string, tag?: string }) => Promise<WorkRecord[]>} getAll
|
|
19
19
|
* @property {(id: string, opts?: { include?: string[] }) => Promise<WorkRecord|null>} get
|
|
20
20
|
* @property {(id: string) => Promise<WorkRecordActivity[]>} activity
|
|
@@ -31,10 +31,11 @@ const enc = (s) => encodeURIComponent(s);
|
|
|
31
31
|
/** Map caller params → API search params.
|
|
32
32
|
* `station` accepts an id or a short_code; the API resolves either. `line` is
|
|
33
33
|
* passed through as-is and matches every station on that line.
|
|
34
|
-
* @param {{ limit?: number, status?: string, station?: string, line?: string, tag?: string }} [params] */
|
|
35
|
-
function toSearchParams({ limit, status, station, line, tag } = {}) {
|
|
34
|
+
* @param {{ page?: number, limit?: number, status?: string, station?: string, line?: string, tag?: string }} [params] */
|
|
35
|
+
function toSearchParams({ page, limit, status, station, line, tag } = {}) {
|
|
36
36
|
/** @type {Record<string, any>} */
|
|
37
37
|
const sp = {};
|
|
38
|
+
if (page) sp.page = page;
|
|
38
39
|
if (limit) sp.limit = limit;
|
|
39
40
|
if (status) sp.status = status;
|
|
40
41
|
if (station) sp.station = station;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* A station, as returned by `/api/v1/stations`.
|
|
3
4
|
* @typedef {Object} Station
|
|
@@ -7,10 +8,11 @@
|
|
|
7
8
|
* @property {string} line Line code. The line owns the location; a station has none of its own.
|
|
8
9
|
* @property {string} [description]
|
|
9
10
|
* @property {StationStep[]} [steps]
|
|
10
|
-
* @property {string[]} [dependencies] Station ids or short_codes this one depends on.
|
|
11
|
+
* @property {(string|{ id: string, short_code?: string })[]} [dependencies] Station ids or short_codes this one depends on (or station objects).
|
|
11
12
|
* @property {(string|Tag)[]} [tags]
|
|
12
13
|
* @property {string} [applies_to]
|
|
13
14
|
* @property {boolean} [archived]
|
|
15
|
+
* @property {string|null} [archived_at]
|
|
14
16
|
* @property {string} [created_at]
|
|
15
17
|
*/
|
|
16
18
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* A supporting document, as returned by `/api/v1/supporting-docs/{id}`
|
|
3
4
|
* (metadata; `content` present for markdown docs).
|
|
@@ -8,6 +9,11 @@
|
|
|
8
9
|
* @property {string} [mime_type]
|
|
9
10
|
* @property {string} [content]
|
|
10
11
|
* @property {string} [url]
|
|
12
|
+
* @property {string} [title]
|
|
13
|
+
* @property {string} [filename]
|
|
14
|
+
* @property {number} [size_bytes]
|
|
15
|
+
* @property {string} [step_slug] The step that produced it.
|
|
16
|
+
* @property {string} [work_record_id]
|
|
11
17
|
* @property {string} [created_at]
|
|
12
18
|
*/
|
|
13
19
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* A tag, as returned by `/api/v1/tags`.
|
|
3
4
|
* @typedef {Object} Tag
|
|
@@ -5,6 +6,7 @@
|
|
|
5
6
|
* @property {string} name
|
|
6
7
|
* @property {string} [color]
|
|
7
8
|
* @property {string} [description]
|
|
9
|
+
* @property {{ total?: number }} [usage] How many records carry the tag.
|
|
8
10
|
*/
|
|
9
11
|
|
|
10
12
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* A work record — one run of a station, as returned by
|
|
3
4
|
* `/api/v1/work-records`.
|
|
@@ -10,6 +11,12 @@
|
|
|
10
11
|
* @property {Record<string, any>[]} [step_outputs]
|
|
11
12
|
* @property {string} [created_at]
|
|
12
13
|
* @property {string} [updated_at]
|
|
14
|
+
* @property {string|null} [started_at]
|
|
15
|
+
* @property {string|null} [completed_at]
|
|
16
|
+
* @property {string|null} [performed_by] Who or what ran it (a factory session, or a user).
|
|
17
|
+
* @property {string|null} [error]
|
|
18
|
+
* @property {WorkRecordActivity[]} [activity] With `show --activity`.
|
|
19
|
+
* @property {import('./SupportingDoc.types.js').SupportingDoc[]} [supporting_docs] With `show --supporting-docs`.
|
|
13
20
|
*/
|
|
14
21
|
|
|
15
22
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* Orchestrator API credentials, passed explicitly to `alOrc(...)`. The library
|
|
3
4
|
* never reads these from the environment — the caller injects them.
|
|
@@ -5,7 +6,6 @@
|
|
|
5
6
|
* @property {string} api_key
|
|
6
7
|
* @property {string} api_secret
|
|
7
8
|
* @property {string} [api_url] Origin-only base URL (no /api/v1). Defaults to https://orchestrator.assemblyline.sh.
|
|
8
|
-
* @property {string} [location] Optional location, sent as `X-Location`.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
/**
|