@assemblyline/al-orc 0.0.0-stage → 0.2.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +5 -0
  4. package/README.md +98 -2
  5. package/bin/cli.js +5 -0
  6. package/package.json +59 -4
  7. package/src/cli/_helpers.js +68 -0
  8. package/src/cli/config/add.js +11 -0
  9. package/src/cli/config/current.js +21 -0
  10. package/src/cli/config/index.js +64 -0
  11. package/src/cli/config/list.js +23 -0
  12. package/src/cli/config/remove.js +7 -0
  13. package/src/cli/config/use.js +7 -0
  14. package/src/cli/config-store.js +128 -0
  15. package/src/cli/factory-sessions/index.js +36 -0
  16. package/src/cli/factory-sessions/list.js +94 -0
  17. package/src/cli/factory-sessions/show.js +84 -0
  18. package/src/cli/index.js +62 -0
  19. package/src/cli/lines/index.js +54 -0
  20. package/src/cli/lines/list.js +40 -0
  21. package/src/cli/lines/pull.js +47 -0
  22. package/src/cli/lines/push.js +83 -0
  23. package/src/cli/lines/show.js +37 -0
  24. package/src/cli/shared/edit-tags.js +44 -0
  25. package/src/cli/stations/archive.js +25 -0
  26. package/src/cli/stations/delete.js +9 -0
  27. package/src/cli/stations/edit.js +31 -0
  28. package/src/cli/stations/index.js +105 -0
  29. package/src/cli/stations/list.js +38 -0
  30. package/src/cli/stations/pull.js +74 -0
  31. package/src/cli/stations/push.js +213 -0
  32. package/src/cli/stations/run.js +94 -0
  33. package/src/cli/stations/show.js +75 -0
  34. package/src/cli/status.js +24 -0
  35. package/src/cli/supporting-docs/index.js +22 -0
  36. package/src/cli/supporting-docs/show.js +50 -0
  37. package/src/cli/tags/create.js +22 -0
  38. package/src/cli/tags/delete.js +9 -0
  39. package/src/cli/tags/edit.js +28 -0
  40. package/src/cli/tags/index.js +50 -0
  41. package/src/cli/tags/list.js +25 -0
  42. package/src/cli/utils/format.js +171 -0
  43. package/src/cli/utils/line-files.js +85 -0
  44. package/src/cli/utils/station-files.js +152 -0
  45. package/src/cli/utils/station-labels.js +49 -0
  46. package/src/cli/work-records/cancel.js +25 -0
  47. package/src/cli/work-records/edit.js +23 -0
  48. package/src/cli/work-records/index.js +61 -0
  49. package/src/cli/work-records/list.js +49 -0
  50. package/src/cli/work-records/show.js +104 -0
  51. package/src/http.js +254 -0
  52. package/src/index.js +104 -0
  53. package/src/resources/factory-sessions.js +86 -0
  54. package/src/resources/lines.js +57 -0
  55. package/src/resources/stations.js +90 -0
  56. package/src/resources/supporting-docs.js +37 -0
  57. package/src/resources/tags.js +68 -0
  58. package/src/resources/work-records.js +78 -0
  59. package/src/types/api/Line.types.js +23 -0
  60. package/src/types/api/Station.types.js +36 -0
  61. package/src/types/api/SupportingDoc.types.js +20 -0
  62. package/src/types/api/Tag.types.js +12 -0
  63. package/src/types/api/WorkRecord.types.js +34 -0
  64. package/src/types/general/Credentials.types.js +18 -0
  65. package/src/types/general/Transport.types.js +22 -0
  66. package/src/types/general/index.js +9 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,78 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.2.0] - 2026-10-19
11
+
12
+ ### Fixed
13
+ - `stations run <id> --key=value` passes extra flags as step overrides again; strict
14
+ argument checking rejected them (broken since fob-orc 2026-07-26). Kebab-case flags become
15
+ snake_case keys (`--max-files=3` → `max_files`), and yargs' camelCase copies are no longer
16
+ sent. Every other command still rejects unknown flags.
17
+ - `work-records list --page <n>` works, as its "use --page" hint says.
18
+ - `lines list` and `stations list` honour `--page` and `--limit` instead of always returning the
19
+ first 100, and print the same next-page hint.
20
+
21
+ ### Removed
22
+ - **BREAKING (library):** the `location` credential and its `X-Location` header. Only the
23
+ factory protocol (`/api/factory/*`) reads it, and al-orc never calls that.
24
+ - `formatCsv`, `formatCurrency` and `formatAmount` from `format.js`, unused since the fork.
25
+
26
+ ### Changed
27
+ - Every source file is `// @ts-check`ed, and the API types now cover the fields the CLI reads
28
+ (work-record timings and errors, supporting-document metadata, tag usage).
29
+ - `stations delete --cascade` and the code no longer say server support is pending; the
30
+ orchestrator supports it.
31
+
32
+ ## [0.1.1] - 2026-10-19
33
+
34
+ ### Fixed
35
+ - `config profiles add` no longer requires `--api-url`; it defaults to
36
+ `https://orchestrator.assemblyline.sh`, as the README's quick start assumes.
37
+
38
+ ## [0.1.0] - 2026-10-19
39
+
40
+ First release as `@assemblyline/al-orc`, forked from `@finopsbricks/fob-orc` 0.2.0. Entries
41
+ below 0.1.0 are the history of `fob-orc`.
42
+
43
+ ### Changed
44
+ - **BREAKING:** package `@assemblyline/al-orc`, binary `al-orc`, client factory `alOrc()`.
45
+ - **BREAKING:** default API URL `https://orchestrator.assemblyline.sh`.
46
+ - **BREAKING:** profiles live in `~/.assemblyline/al-orc/config.yml`; override with
47
+ `AL_ORC_CONFIG_DIR`. `AL_DEBUG=1` prints stacks.
48
+ - **BREAKING:** station routes are `/api/v1/stations/*`; work records filter by `?station=`
49
+ and carry the station id in `station`.
50
+ - **BREAKING:** `worker-sessions` is `factory-sessions` (`orc.factorySessions`,
51
+ `/api/v1/factory-sessions`); fields `factory_name` and `factory_version`.
52
+ - `status` / `checkConnection()` read `GET /api/v1/me` and print the org and key. The old
53
+ probe used the session poll, which could claim a pending step.
54
+
55
+ ### Added
56
+ - `orc.me()`: the org and API key the credentials belong to.
57
+
58
+ ### Removed
59
+ - **BREAKING:** `stations run --item` and the `item` option of `orc.stations.run()`.
60
+
61
+ ## [0.2.0] - 2026-09-05
62
+
63
+ ### Added
64
+ - `orc.lines` namespace (`list`, `getAll`, `get`, `create`, `update`, `delete`) against `/api/v1/lines`; `id` arguments accept a line code or id.
65
+ - `fob-orc lines list|show|pull|push`. Local files live at `.orchestrator/lines/<CODE>.json` with `id`, `code`, `name`, `description`, `location`. A line owns the worker location; stations name their line by code and inherit it (orchestrator D3).
66
+ - `stations list --line` now filters server-side (code or id).
67
+
68
+ ### Changed
69
+ - **BREAKING:** `stations pull --all` pulls lines first, then stations. Station files no longer carry `location`.
70
+ - **BREAKING:** `stations push --all` pushes line files before station files, so a new station's `line` code exists server-side. `stations push` strips a stale per-station `location` with a notice, and refuses a station file with no `line`.
71
+
72
+ ### Migration
73
+ - In every worker repo: `fob-orc lines pull --all && fob-orc stations pull --all`, commit.
74
+
75
+ ## [0.1.1] - 2026-07-29
76
+
77
+ ### Changed
78
+ - Help output: each command's own options now render under `Options:` above a dedicated `Global Options:` group (`--profile`/`--org`, `--help`, `--version`), instead of being interleaved. Help text only — no behavior change.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Assembly Line
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ al-orc
2
+ Copyright 2026 Assembly Line
3
+
4
+ This product includes software developed at Assembly Line, forked from fob-orc
5
+ (Copyright 2026 FinOpsBricks, Apache-2.0).
package/README.md CHANGED
@@ -1,3 +1,99 @@
1
- # Temporary Holding Version
1
+ # @assemblyline/al-orc
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The [Assembly Line](https://assemblyline.sh) Orchestrator's client + `al-orc` CLI — a **2-in-1**:
4
+ import the client in code, or use the CLI to push lines and stations, run them, and read work
5
+ records.
6
+
7
+ ```bash
8
+ npm install -g @assemblyline/al-orc
9
+ al-orc config profiles add acme --api-key <key> --api-secret <secret>
10
+ al-orc status # org and key the profile belongs to
11
+ al-orc lines push --all && al-orc stations push --all # from a factory repo root
12
+ al-orc stations run EX0
13
+ al-orc work-records list --station EX0
14
+ ```
15
+
16
+ Profiles live in `~/.assemblyline/al-orc/config.yml` (mode 0600; override the folder with
17
+ `AL_ORC_CONFIG_DIR`). The CLI never reads `.env`.
18
+
19
+ ## Library
20
+
21
+ ```js
22
+ import { alOrc } from '@assemblyline/al-orc';
23
+
24
+ const orc = alOrc({ api_key, api_secret }); // api_url optional (defaults to the hosted origin)
25
+ const { data: stations } = await orc.stations.list({ tag: 'daily' });
26
+ const station = await orc.stations.get(id); // unwrapped record
27
+ const { work_record_id } = await orc.stations.run(id, { overrides: { dry_run: true } });
28
+ await orc.workRecords.cancel(wrId);
29
+ ```
30
+
31
+ Credentials are **explicit** — the client never reads `process.env`. Code serving several orgs constructs one client per org: `alOrc(orgACreds)`.
32
+
33
+ ## Namespaces
34
+
35
+ | Namespace | Methods |
36
+ |---|---|
37
+ | `orc.lines` | `list · getAll · get · create · update · delete` — a line owns the location its stations run at |
38
+ | `orc.stations` | `list · getAll · get · create · update · delete · archive · unarchive · run · getTags · setTags` |
39
+ | `orc.workRecords` | `list · getAll · get · activity · cancel · getTags · setTags` |
40
+ | `orc.tags` | `list · create · update · delete · resolveNames · ensure` |
41
+ | `orc.supportingDocs` | `get · downloadStream` |
42
+ | `orc.factorySessions` | `list · getAll · get` — one row per factory session start |
43
+ | `orc.me()` | the org and API key the credentials belong to |
44
+ | `orc.checkConnection()` | credentials check via `me`; never throws and never claims work |
45
+
46
+ Return shapes: single-record ops return the unwrapped record; `list` returns `{ data, page_context }`;
47
+ `getAll` returns a flat array.
48
+
49
+ ## Endpoint contract
50
+
51
+ Station routes live under `/api/v1/stations/*`; work records filter by `?station=`. Every endpoint is defined exactly once, in `src/resources/` — the CLI and the library both
52
+ call it, so they can't drift.
53
+
54
+ ## Output conventions
55
+
56
+ Every command's terminal output follows these. They were implicit for a long time and drifted —
57
+ `format.js` is copy-pasted across six sibling CLIs and each copy diverged — so they are written down
58
+ 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-control` agreeing.
60
+
61
+ **Timestamps** — always `formatDate()`, never `toISOString()` or a raw `Date`. Output is the
62
+ operator's **local** timezone, because everything these get compared against (`pm2 logs`, file mtimes,
63
+ `al-control` output) is local. The orchestrator returns UTC, so printing it verbatim silently misread
64
+ every timestamp by the local offset. Name the zone **once** per table or block via `localTzLabel()` in
65
+ the column header — `CREATED (${localTzLabel()})` — never per row. Durations use `formatDuration()`.
66
+
67
+ **Empty values** — the em-dash `'—'`, never `'-'`, `'N/A'` or blank. `formatDate`, `formatDuration`
68
+ and `truncate` already return it, so `|| '—'` is only needed for plain fields.
69
+
70
+ **Free text** — `truncate(value, max)` for anything unbounded (errors, titles, descriptions). It
71
+ collapses whitespace first: a newline inside an error would otherwise break the table's alignment.
72
+
73
+ **Tables** — `formatTable(headers, rows)`; pass no options object. Headers are UPPERCASE. Prefer the
74
+ columns an operator needs to act (what failed, how long, who triggered it) over the minimum that
75
+ identifies a row.
76
+
77
+ **Lists** — print the table, a blank line, then `Total: N <things>`. Follow it with
78
+ `formatPaginationHint(page_context)`, which is silent on a single page: `Total:` counts the rows
79
+ *returned*, so without the hint a truncated page reads as the whole set. Empty results print
80
+ `No <things> found` (no trailing period) and return early. `--json` prints the raw array, before the
81
+ empty check, and is never decorated.
82
+
83
+ **Detail views** — `formatHeader`/`formatSection` for structure, `formatField(label, value, 14)` for
84
+ fields; 14 is the shared label width. Order: identity, then timestamps, then nested sections. A nested
85
+ section's own empty case *does* take a period (`No tasks.`), unlike a top-level list.
86
+
87
+ **Advisory lines** — prefix `! ` and indent continuations by three spaces, after a blank line. Say
88
+ what to do about it, not just what is wrong.
89
+
90
+ ## Scripts
91
+
92
+ ```bash
93
+ npm test # jest (mocked fetch)
94
+ npm run typecheck # tsc -p jsconfig.json → 0 errors
95
+ ```
96
+
97
+ ## License
98
+
99
+ Apache-2.0
package/bin/cli.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { hideBin } from 'yargs/helpers';
3
+ import { run } from '../src/cli/index.js';
4
+
5
+ run(hideBin(process.argv));
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@assemblyline/al-orc",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Assembly Line Orchestrator client + al-orc CLI (2-in-1): push lines and stations, run them, read work records.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/assemblyline-sh/al-orc.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/assemblyline-sh/al-orc/issues"
11
+ },
12
+ "type": "module",
13
+ "main": "src/index.js",
14
+ "exports": {
15
+ ".": "./src/index.js",
16
+ "./package.json": "./package.json"
17
+ },
18
+ "bin": {
19
+ "al-orc": "./bin/cli.js"
20
+ },
21
+ "scripts": {
22
+ "start": "node bin/cli.js",
23
+ "test": "node --experimental-vm-modules node_modules/.bin/jest",
24
+ "typecheck": "tsc -p jsconfig.json",
25
+ "typecheck:watch": "tsc -p jsconfig.json --watch"
26
+ },
27
+ "keywords": [
28
+ "orchestrator",
29
+ "api-client",
30
+ "cli",
31
+ "assembly-line"
32
+ ],
33
+ "license": "Apache-2.0",
34
+ "files": [
35
+ "bin",
36
+ "src",
37
+ "README.md",
38
+ "CHANGELOG.md",
39
+ "LICENSE",
40
+ "NOTICE"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "dependencies": {
46
+ "@inquirer/prompts": "^7.10.1",
47
+ "js-yaml": "^4.1.0",
48
+ "yargs": "^17.7.2"
49
+ },
50
+ "devDependencies": {
51
+ "@jest/globals": "^29.7.0",
52
+ "@types/node": "^22.20.1",
53
+ "jest": "^29.7.0",
54
+ "typescript": "^5.8.3"
55
+ },
56
+ "engines": {
57
+ "node": ">=18.0.0"
58
+ },
59
+ "homepage": "https://assemblyline.sh",
60
+ "author": "Assembly Line"
61
+ }
@@ -0,0 +1,68 @@
1
+ // @ts-check
2
+ /**
3
+ * Shared yargs helpers.
4
+ */
5
+
6
+ import { resolveCredentials } from './config-store.js';
7
+ import { alOrc } from '../index.js';
8
+
9
+ /**
10
+ * Wrap a handler so unexpected exceptions exit cleanly without a stack trace.
11
+ * Set AL_DEBUG=1 to see the full stack.
12
+ */
13
+ export function safe(handler) {
14
+ return async (argv) => {
15
+ try {
16
+ await handler(argv);
17
+ } catch (err) {
18
+ console.error(`Error: ${err.message}`);
19
+ if (process.env.AL_DEBUG) console.error(err.stack);
20
+ process.exit(1);
21
+ }
22
+ };
23
+ }
24
+
25
+ /**
26
+ * Register a command's own "Options:" group so it renders *above* the inherited
27
+ * "Global Options:". yargs merges an instance's groups before the preserved
28
+ * global ones, and otherwise materialises the default "Options:" group last — so
29
+ * pre-creating it on the command instance is what fixes the order. Call at the
30
+ * start of a command's builder; ungrouped options then fall into this group.
31
+ */
32
+ export function localOptions(yargs) {
33
+ return yargs.group([], 'Options:');
34
+ }
35
+
36
+ /** Standard pagination + JSON output options for list commands. */
37
+ export function paginationOptions(yargs) {
38
+ return localOptions(yargs)
39
+ .option('page', { describe: 'Page number', type: 'number', default: 1 })
40
+ .option('limit', { describe: 'Page size (max 500)', type: 'number', default: 100 })
41
+ .option('json', { describe: 'Output raw JSON', type: 'boolean' });
42
+ }
43
+
44
+ // Print the credential-source hint at most once per invocation.
45
+ let hintPrinted = false;
46
+
47
+ /**
48
+ * Resolve the current command's credentials from the CLI config, printing a
49
+ * one-time hint to stderr about which identity is in use. Handlers pass the
50
+ * returned object to alOrc() as the `credentials`.
51
+ */
52
+ export function requireCreds() {
53
+ const creds = resolveCredentials();
54
+ if (!hintPrinted) {
55
+ console.error(`(using orchestrator credentials from ${creds.source})`);
56
+ hintPrinted = true;
57
+ }
58
+ return creds;
59
+ }
60
+
61
+ /**
62
+ * Build a credential-bound `alOrc` client for the current command — the same
63
+ * client factories construct, so a handler exercises the exact library path.
64
+ * Prints the one-time credential-source hint via requireCreds().
65
+ */
66
+ export function clientFor() {
67
+ return alOrc(requireCreds());
68
+ }
@@ -0,0 +1,11 @@
1
+ // @ts-check
2
+ import { addOrg } from '../config-store.js';
3
+
4
+ export async function addConfigHandler(argv) {
5
+ addOrg(argv.name, {
6
+ api_url: argv.apiUrl,
7
+ api_key: argv.apiKey,
8
+ api_secret: argv.apiSecret,
9
+ });
10
+ console.log(`Saved orchestrator credentials for profile '${argv.name}'.`);
11
+ }
@@ -0,0 +1,21 @@
1
+ // @ts-check
2
+ import { describeCurrent } from '../config-store.js';
3
+
4
+ export async function currentConfigHandler(argv) {
5
+ const cur = describeCurrent();
6
+
7
+ if (argv.json) {
8
+ console.log(JSON.stringify(cur, null, 2));
9
+ return;
10
+ }
11
+
12
+ if (!cur) {
13
+ console.log('(no active profile — run `al-orc config profiles add <name>`)');
14
+ return;
15
+ }
16
+
17
+ const lines = [`Source: ${cur.source}`];
18
+ if (cur.name) lines.push(`Profile: ${cur.name}`);
19
+ lines.push(`API URL: ${cur.api_url}`);
20
+ console.log(lines.join('\n'));
21
+ }
@@ -0,0 +1,64 @@
1
+ // @ts-check
2
+ import { safe, localOptions } from '../_helpers.js';
3
+ import { DEFAULT_API_URL } from '../../http.js';
4
+ import { addConfigHandler } from './add.js';
5
+ import { listConfigHandler } from './list.js';
6
+ import { useConfigHandler } from './use.js';
7
+ import { removeConfigHandler } from './remove.js';
8
+ import { currentConfigHandler } from './current.js';
9
+
10
+ /**
11
+ * The multi-tenant object is a "profile" — a named set of credentials. al-orc's
12
+ * profiles map 1:1 to orchestrator orgs, so `orgs` is offered as an alias.
13
+ * `config` is a namespace, not the object: `al-orc config profiles <action>`.
14
+ */
15
+ function buildProfilesSubcommands(yargs) {
16
+ return yargs
17
+ .usage('$0 config profiles <action> [options]')
18
+ .command(
19
+ 'list',
20
+ 'List profiles (current marked with *)',
21
+ (y) => localOptions(y).option('json', { describe: 'Output raw JSON', type: 'boolean' }),
22
+ safe(listConfigHandler),
23
+ )
24
+ .command(
25
+ ['current', 'whoami'],
26
+ 'Show the active profile + resolution source',
27
+ (y) => localOptions(y).option('json', { describe: 'Output raw JSON', type: 'boolean' }),
28
+ safe(currentConfigHandler),
29
+ )
30
+ .command(
31
+ 'add <name>',
32
+ "Add or update a profile's orchestrator credentials",
33
+ (y) =>
34
+ localOptions(y.positional('name', { describe: 'Profile name', type: 'string' }))
35
+ .option('api-url', { describe: 'API base URL (origin only)', type: 'string', default: DEFAULT_API_URL })
36
+ .option('api-key', { describe: 'API key', type: 'string', demandOption: true })
37
+ .option('api-secret', { describe: 'API secret', type: 'string', demandOption: true }),
38
+ safe(addConfigHandler),
39
+ )
40
+ .command(
41
+ 'use <name>',
42
+ 'Set the current profile',
43
+ (y) => y.positional('name', { describe: 'Profile name', type: 'string' }),
44
+ safe(useConfigHandler),
45
+ )
46
+ .command(
47
+ ['remove <name>', 'rm <name>'],
48
+ 'Remove a profile',
49
+ (y) => y.positional('name', { describe: 'Profile name', type: 'string' }),
50
+ safe(removeConfigHandler),
51
+ )
52
+ .demandCommand(1, 'Specify an action: list, current, add, use, remove');
53
+ }
54
+
55
+ export function buildConfigSubcommands(yargs) {
56
+ return yargs
57
+ .usage('$0 config <resource> <action> [options]')
58
+ .command(
59
+ ['profiles', 'orgs'],
60
+ 'Manage credential profiles (alias: orgs)',
61
+ buildProfilesSubcommands,
62
+ )
63
+ .demandCommand(1, 'Specify a resource: profiles (alias: orgs)');
64
+ }
@@ -0,0 +1,23 @@
1
+ // @ts-check
2
+ import { listProfiles } from '../config-store.js';
3
+ import { formatTable } from '../utils/format.js';
4
+
5
+ export async function listConfigHandler(argv) {
6
+ const { current, path, profiles } = listProfiles();
7
+
8
+ if (argv.json) {
9
+ console.log(JSON.stringify({ current, profiles }, null, 2));
10
+ return;
11
+ }
12
+
13
+ if (profiles.length === 0) {
14
+ console.log('(no profiles configured — run `al-orc config profiles add <name>`)');
15
+ return;
16
+ }
17
+
18
+ const headers = ['', 'NAME', 'API URL'];
19
+ const rows = profiles.map((p) => [p.current ? '*' : ' ', p.name, p.api_url ?? '']);
20
+
21
+ console.log(formatTable(headers, rows));
22
+ console.log(`\n(* = current) config: ${path}`);
23
+ }
@@ -0,0 +1,7 @@
1
+ // @ts-check
2
+ import { removeOrg } from '../config-store.js';
3
+
4
+ export async function removeConfigHandler(argv) {
5
+ removeOrg(argv.name);
6
+ console.log(`Removed profile '${argv.name}'.`);
7
+ }
@@ -0,0 +1,7 @@
1
+ // @ts-check
2
+ import { useOrg } from '../config-store.js';
3
+
4
+ export async function useConfigHandler(argv) {
5
+ useOrg(argv.name);
6
+ console.log(`Current profile set to '${argv.name}'.`);
7
+ }