@zalosai/zalos-cli 0.2.20 → 0.2.21

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/PUBLISHING.md CHANGED
@@ -59,6 +59,12 @@ Do not publish with uncommitted package changes or reuse an existing version.
59
59
 
60
60
  ## Central developer access release
61
61
 
62
+ Version 0.2.21 adds `workflow view --published` and `workflow export --published`
63
+ for reading client-facing workflow definitions through the existing API. These
64
+ reads omit draft update checksums and reject protected workflows that resolve to
65
+ an unpublished version. Team-scoped `export --all --published` is supported;
66
+ cross-team `--all-teams --published` is not.
67
+
62
68
  Version 0.2.20 adds `zl workflow eval` for evaluation suites, cases, results,
63
69
  incidents, evidence, captured-execution scoring, case launches and thread
64
70
  consolidation. Writes preview by default and require `--apply`. Deploy the
package/README.md CHANGED
@@ -196,6 +196,20 @@ whether runs use that version and names the live version when they do not. Use
196
196
  keeps stdout as reusable workflow JSON and writes a structured stderr warning when the
197
197
  exported draft differs from the version used by runs.
198
198
 
199
+ Use `workflow view <id> --published` or `workflow export <id> --published` to read
200
+ the definition clients run, without publishing or changing the draft:
201
+
202
+ ```bash
203
+ zl --environment us-prod workflow export <workflow-id> --published --pretty --output /tmp/published.json
204
+ zl --environment us-prod workflow export --all --published --output /tmp/team-live-workflows.json
205
+ ```
206
+
207
+ Protected workflows return their published content; unprotected workflows return
208
+ their current definition. A protected workflow that falls back to a draft is
209
+ rejected. Published reads omit update checksums: export the current draft before
210
+ editing it. `--published` cannot be combined with `--all-teams`; select the owning
211
+ team and use an ID or `--all`.
212
+
199
213
  `workflow list --all-teams` and `workflow export --all-teams` read every workflow in
200
214
  the selected regional database. They require an internal Zalos human CLI token with
201
215
  `workflows:read`; external users and automation tokens are rejected. `workflow export --all`
@@ -2,11 +2,23 @@ import { writeFile, stat } from 'node:fs/promises';
2
2
  import { resolve, join } from 'node:path';
3
3
  import { client } from '../client.js';
4
4
  import { readWorkflowFile, serializeWorkflow } from '../workflow-file.js';
5
- import { ValidationError } from '../utils/errors.js';
5
+ import { ApiError, ValidationError } from '../utils/errors.js';
6
6
  import { filterSingle, printJson } from '../utils/output.js';
7
7
  import { action, dataRow, dataRows, fields, isRow, printPage, resourceId, } from '../utils/product-api.js';
8
8
  import { parseJson } from '../utils/validate.js';
9
9
  import { registerWorkflowEvalCommand } from './workflow-eval.js';
10
+ async function readWorkflow(id, options) {
11
+ const workflow = dataRow(await client.get(`/workflows/${resourceId(id)}${options.published ? '?resolvePublished=true' : ''}`));
12
+ if (!options.published)
13
+ return workflow;
14
+ if (workflow.publishedVersionId && workflow.versionId !== workflow.publishedVersionId) {
15
+ throw new ApiError(502, 'The API did not resolve the published workflow version; refusing to export a draft');
16
+ }
17
+ // The client-facing API retains the current draft's checksum when resolving
18
+ // published content. Never let that token authorize an update with old content.
19
+ const { checksum: _checksum, expectedChecksum: _expectedChecksum, ...snapshot } = workflow;
20
+ return snapshot;
21
+ }
10
22
  function publicationStatus(workflow, publishedNow = false) {
11
23
  const draftVersionId = typeof workflow.versionId === 'string' ? workflow.versionId : undefined;
12
24
  const publishedVersionId = typeof workflow.publishedVersionId === 'string' ? workflow.publishedVersionId : undefined;
@@ -48,12 +60,14 @@ export async function listWorkflowsAction(options) {
48
60
  printPage(dataRows(await client.get(path)), options);
49
61
  }
50
62
  export async function viewWorkflowAction(id, options) {
51
- printJson(filterSingle(dataRow(await client.get(`/workflows/${resourceId(id)}`)), options.fields));
63
+ printJson(filterSingle(await readWorkflow(id, options), options.fields));
52
64
  }
53
65
  export async function exportWorkflowAction(id, options) {
54
66
  const selections = [Boolean(id), Boolean(options.all), Boolean(options.allTeams)].filter(Boolean).length;
55
67
  if (selections !== 1)
56
68
  throw new ValidationError('id', 'Choose a workflow ID, --all, or --all-teams');
69
+ if (options.published && options.allTeams)
70
+ throw new ValidationError('published', '--published cannot be combined with --all-teams; select the owning team and use an ID or --all');
57
71
  if (id)
58
72
  resourceId(id);
59
73
  const output = options.output ? resolve(options.output) : undefined;
@@ -80,7 +94,7 @@ export async function exportWorkflowAction(id, options) {
80
94
  });
81
95
  rows = [];
82
96
  for (const workflowId of ids)
83
- rows.push(filterSingle(dataRow(await client.get(`/workflows/${workflowId}`)), options.fields));
97
+ rows.push(filterSingle(await readWorkflow(workflowId, options), options.fields));
84
98
  }
85
99
  rows.forEach(warnIfWorkflowDraftIsUnpublished);
86
100
  if (options.separate && output) {
@@ -200,11 +214,13 @@ export function registerWorkflowCommand(program) {
200
214
  .action(async (o) => action(() => listWorkflowsAction({ ...o, ...fields(program) })));
201
215
  cmd
202
216
  .command('view <id>')
203
- .action(async (id) => action(() => viewWorkflowAction(id, fields(program))));
217
+ .option('--published', 'Read the definition clients run (current when unprotected)')
218
+ .action(async (id, o) => action(() => viewWorkflowAction(id, { ...o, ...fields(program) })));
204
219
  cmd
205
220
  .command('export [id]')
206
221
  .option('--all', 'Export every accessible workflow')
207
222
  .option('--all-teams', 'Export workflows across every team in the selected region')
223
+ .option('--published', 'Export the definition clients run (current when unprotected); omits update checksum')
208
224
  .option('--output <path>', 'Output file (must not exist)')
209
225
  .option('--pretty', 'Indent JSON')
210
226
  .option('--separate', 'Write ID-named JSON in output directory')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zalosai/zalos-cli",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "API-only product command-line interface for Zalos",
5
5
  "repository": {
6
6
  "type": "git",