@jacebenson/jsn 5.4.0 → 5.5.0-dev.155.1
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/package.json +1 -1
- package/src/auth.js +16 -2
- package/src/cli-adapter.js +56 -7
- package/src/commands/flows.js +79 -9
- package/src/commands/store.js +4 -2
- package/src/commands/workflows.js +32 -6
- package/src/errors.js +4 -0
- package/src/flow-create.js +239 -9
- package/src/flow-safe-edit.js +31 -8
- package/src/help.js +96 -0
- package/src/helpers.js +24 -1
- package/src/record-command-profiles.js +2 -2
- package/src/sdk.js +6 -3
- package/src/session-recovery.js +2 -2
- package/src/store.js +5 -3
- package/src/update-set-apply.js +4 -1
- package/src/workflow-graph.js +88 -0
- package/src/workflow-inspection.js +232 -64
- package/src/workflow-steps.js +69 -0
package/package.json
CHANGED
package/src/auth.js
CHANGED
|
@@ -14,6 +14,10 @@ import { savePKCEState, loadPKCEState, removePKCEState, getOAuthClientID, genera
|
|
|
14
14
|
import { parseBrowserSessionInput } from './auth/browser-session.js';
|
|
15
15
|
import { normalizeAuthMethod, normalizeAuthSource, sourceMethod, probeFailure, classifyProbeError, classifyCredentialState } from './auth/credential-state.js';
|
|
16
16
|
|
|
17
|
+
// A profile in one of these credential states can make authenticated calls.
|
|
18
|
+
// `refreshable` refreshes at point of use; see isAuthenticated().
|
|
19
|
+
const AUTHENTICATED_STATES = new Set(['available', 'refreshable']);
|
|
20
|
+
|
|
17
21
|
// Preserve the public auth module API while implementation stays separated.
|
|
18
22
|
export { sanitizeKeyPart } from './auth/credential-store.js';
|
|
19
23
|
export { parseBrowserSessionInput } from './auth/browser-session.js';
|
|
@@ -289,15 +293,25 @@ export class AuthManager {
|
|
|
289
293
|
}
|
|
290
294
|
}
|
|
291
295
|
|
|
296
|
+
/**
|
|
297
|
+
* Credential states that can produce a session count as authenticated.
|
|
298
|
+
*
|
|
299
|
+
* `refreshable` is an expired (or nearly expired) access token WITH a refresh
|
|
300
|
+
* token, which getCredentialsFor() refreshes at point of use — the refresh is
|
|
301
|
+
* already proved by the "expired OAuth refreshes at point of use" contract.
|
|
302
|
+
* Reporting those profiles as unauthenticated made `jsn auth status` disagree
|
|
303
|
+
* with every command that then ran fine, and made requireAuth() refuse a
|
|
304
|
+
* profile the next request would have refreshed.
|
|
305
|
+
*/
|
|
292
306
|
isAuthenticated() {
|
|
293
307
|
const instance = this.identity.getEffectiveInstance();
|
|
294
308
|
if (!instance) return false;
|
|
295
|
-
return this.getAuthState(instance).state
|
|
309
|
+
return AUTHENTICATED_STATES.has(this.getAuthState(instance).state);
|
|
296
310
|
}
|
|
297
311
|
|
|
298
312
|
isAuthenticatedFor(instance, options = {}) {
|
|
299
313
|
if (!instance) return false;
|
|
300
|
-
return this.getAuthState(instance, options).state
|
|
314
|
+
return AUTHENTICATED_STATES.has(this.getAuthState(instance, options).state);
|
|
301
315
|
}
|
|
302
316
|
|
|
303
317
|
async getCredentials() {
|
package/src/cli-adapter.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
2
|
import process from 'node:process';
|
|
3
|
+
import { renderSubcommandHelp } from './help.js';
|
|
3
4
|
|
|
4
5
|
const camel = (name) => name.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
5
6
|
const names = (x) => typeof x === 'string' ? [x] : (x || []);
|
|
@@ -331,18 +332,66 @@ export class LocalCLI {
|
|
|
331
332
|
});
|
|
332
333
|
}
|
|
333
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Usage line for a command page, derived from the node's own declared
|
|
337
|
+
* command. Subcommand pages printed only the path (`Usage: jsn flows`,
|
|
338
|
+
* `Usage: jsn flows show`), which hid the positionals the command accepts and
|
|
339
|
+
* never mentioned options at all.
|
|
340
|
+
*/
|
|
341
|
+
_usageLine(node, path, hasChildren) {
|
|
342
|
+
if (node.usageText) return node.usageText;
|
|
343
|
+
const declared = (node.definition.command || '').trim().split(/\s+/).slice(1)
|
|
344
|
+
.filter((token) => !(hasChildren && /^\[sub-?commands?\]$/i.test(token)));
|
|
345
|
+
const parts = [this.script, ...path, ...(hasChildren ? ['<command>'] : []), ...declared, '[options]'];
|
|
346
|
+
return `Usage: ${parts.join(' ')}`;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
_commandRows(node) {
|
|
350
|
+
return node.children
|
|
351
|
+
.filter((child) => child.name !== this.completionCommand && !child.definition.hidden)
|
|
352
|
+
.map((child) => ({
|
|
353
|
+
label: child.definition.command || child.name,
|
|
354
|
+
description: child.definition.describe || '',
|
|
355
|
+
note: child.aliases.length ? `[aliases: ${child.aliases.join(', ')}]` : '',
|
|
356
|
+
}));
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Option rows carry the alias, type and default a user needs to type the
|
|
361
|
+
* command. The old line dropped all three and printed long aliases with a
|
|
362
|
+
* single dash (`-fields`), which is not a flag.
|
|
363
|
+
*/
|
|
364
|
+
_optionRows(node) {
|
|
365
|
+
const rows = [];
|
|
366
|
+
for (const spec of node.options.values()) {
|
|
367
|
+
const aliases = names(spec.alias).map((alias) => (alias.length === 1 ? `-${alias}` : `--${alias}`));
|
|
368
|
+
const type = isArrayOption(spec) ? 'array' : spec.type;
|
|
369
|
+
const meta = [];
|
|
370
|
+
if (names(spec.choices).length) meta.push(`${type || 'string'}: ${names(spec.choices).join(', ')}`);
|
|
371
|
+
else if (type && type !== 'boolean') meta.push(type);
|
|
372
|
+
if (spec.default !== undefined && spec.default !== false && spec.default !== '') meta.push(`default: ${spec.default}`);
|
|
373
|
+
rows.push({
|
|
374
|
+
label: [`--${spec.name}`, ...aliases].join(', '),
|
|
375
|
+
description: spec.describe || spec.description || '',
|
|
376
|
+
note: meta.map((part) => `[${part}]`).join(' '),
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
return rows;
|
|
380
|
+
}
|
|
381
|
+
|
|
334
382
|
_help(node, path = []) {
|
|
335
383
|
if (!path.length && this.rootHelpRenderer) {
|
|
336
384
|
process.stdout.write(this.rootHelpRenderer() + "\n");
|
|
337
385
|
return;
|
|
338
386
|
}
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
387
|
+
const commands = this._commandRows(node);
|
|
388
|
+
process.stdout.write(renderSubcommandHelp({
|
|
389
|
+
usage: this._usageLine(node, path, commands.length > 0),
|
|
390
|
+
description: node.definition.describe,
|
|
391
|
+
commands,
|
|
392
|
+
options: this._optionRows(node),
|
|
393
|
+
epilogue: node.epilogueText,
|
|
394
|
+
}));
|
|
346
395
|
}
|
|
347
396
|
async parse() {
|
|
348
397
|
if (this.args.includes('--get-yargs-completions')) {
|
package/src/commands/flows.js
CHANGED
|
@@ -5,16 +5,19 @@ import { declareCapabilities } from '../capabilities.js';
|
|
|
5
5
|
import { inspectFlow } from '../flow-inspection.js';
|
|
6
6
|
import { publishFlows, publishFlowLifecycle, publishDoctor, flowStatus } from '../flow-publish.js';
|
|
7
7
|
import { resolveRecord, unwrapSysId } from '../resolve-record.js';
|
|
8
|
-
import { createFlowFromManifest, updateFlowFromManifest, readCurrentUpdateSet } from '../flow-create.js';
|
|
8
|
+
import { createFlowFromManifest, updateFlowFromManifest, readCurrentUpdateSet, readCatalogItemVariables } from '../flow-create.js';
|
|
9
9
|
import { alignUpdateSetCapture } from '../context.js';
|
|
10
10
|
import { EXCLUDED_TRIGGER_TYPES, SUPPORTED_TRIGGER_TYPES, readTriggerCatalog, readTriggerInputDefinitions } from '../flow-triggers.js';
|
|
11
11
|
import { testFlow } from '../flow-test.js';
|
|
12
|
+
import { releaseOwnFlowSafeEdit } from '../flow-safe-edit.js';
|
|
12
13
|
import { errUsage } from '../errors.js';
|
|
13
14
|
import { cancelled, pickDesignerRecord, guidedFlowCreate, guidedFlowEdit, guidedFlowTestRecord, hasDefinitionData, confirmDesignerMutation } from '../flow-designer-interactive.js';
|
|
14
15
|
|
|
15
16
|
const pickFlow = (argv, app, query = '') => pickDesignerRecord(argv, app, argv.action ? 'sys_hub_action_type_definition' : 'sys_hub_flow', argv.action ? 'action' : 'flow', query);
|
|
16
17
|
|
|
17
18
|
const FLOW_COMMANDS = [
|
|
19
|
+
{ name: 'schemas', description: 'Read live trigger catalog and input schemas' },
|
|
20
|
+
{ name: 'catalog-variables [identifier]', description: 'List a catalog item\'s variables for a service_catalog trigger' },
|
|
18
21
|
{ name: 'list', description: 'List flows' },
|
|
19
22
|
{ name: 'executions', description: 'Show flow executions from sys_flow_context' },
|
|
20
23
|
{ name: 'show [identifier]', description: 'Show a flow: structure, inputs, steps and conditions' },
|
|
@@ -24,6 +27,7 @@ const FLOW_COMMANDS = [
|
|
|
24
27
|
{ name: 'create', description: 'Create a draft flow: guided in a terminal, JSON manifest in scripts' },
|
|
25
28
|
{ name: 'update [identifier]', description: 'Update a draft, or a published flow whose definition reports write access (alias: edit)' },
|
|
26
29
|
{ name: 'doctor', description: 'Check whether this instance can publish flows at all' },
|
|
30
|
+
{ name: 'unlock [identifier]', description: 'Release this user\'s stale safe-edit session (orphaned lease) after a failed update' },
|
|
27
31
|
{ name: 'delete [identifier]', description: 'Delete a flow (not implemented: use the Flow Designer UI)' },
|
|
28
32
|
];
|
|
29
33
|
|
|
@@ -46,7 +50,7 @@ function triggerGuidance(trigger) {
|
|
|
46
50
|
};
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
declareCapabilities('flows', { mutationSubcommands: ['create', 'update', 'edit', 'delete', 'publish', 'test'] });
|
|
53
|
+
declareCapabilities('flows', { mutationSubcommands: ['create', 'update', 'edit', 'delete', 'publish', 'test', 'unlock'] });
|
|
50
54
|
|
|
51
55
|
function renderChecks(checks) {
|
|
52
56
|
return checks.map((c) => {
|
|
@@ -66,7 +70,7 @@ export function flowsCmd(wrap) {
|
|
|
66
70
|
return yargs
|
|
67
71
|
.command({
|
|
68
72
|
command: 'schemas',
|
|
69
|
-
describe: 'Read live trigger catalog and
|
|
73
|
+
describe: 'Read live trigger catalog and input schemas',
|
|
70
74
|
handler: wrap(async (_argv, app) => {
|
|
71
75
|
app.requireInstance();
|
|
72
76
|
const catalog = await readTriggerCatalog(app.sdk);
|
|
@@ -83,6 +87,30 @@ export function flowsCmd(wrap) {
|
|
|
83
87
|
app.ok(data, { summary: 'Live Flow trigger schemas' });
|
|
84
88
|
}),
|
|
85
89
|
})
|
|
90
|
+
.command({
|
|
91
|
+
command: 'catalog-variables [identifier]',
|
|
92
|
+
describe: 'List a catalog item\'s variables for a service_catalog trigger input',
|
|
93
|
+
builder: (y) => y
|
|
94
|
+
.option('catalog-item', { type: 'string', describe: 'sc_cat_item sys_id used as the trigger\'s template_catalog_item' })
|
|
95
|
+
.option('scope', { type: 'string', describe: 'Transaction scope sys_id (default: the flow\'s own scope)' }),
|
|
96
|
+
handler: wrap(async (argv, app) => {
|
|
97
|
+
app.requireInstance();
|
|
98
|
+
const catalogItem = argv.catalogItem ?? argv['catalog-item'];
|
|
99
|
+
if (!String(catalogItem || '').trim()) throw errUsage('--catalog-item <sc_cat_item sys_id> is required; it is the trigger\'s template_catalog_item');
|
|
100
|
+
const identifier = await pickFlow(argv, app);
|
|
101
|
+
if (identifier === undefined) return;
|
|
102
|
+
const record = await resolveRecord(app.sdk, { table: 'sys_hub_flow', identifier, matchField: 'name', resource: 'Flow' });
|
|
103
|
+
const flowId = unwrapSysId(record);
|
|
104
|
+
// resolveRecord reads display values; sending `Global` as a
|
|
105
|
+
// transaction scope is not a scope id. Prefer the raw value.
|
|
106
|
+
const rawScope = record?.sys_scope && typeof record.sys_scope === 'object' ? record.sys_scope.value : record?.sys_scope;
|
|
107
|
+
const scope = argv.scope || rawScope || 'global';
|
|
108
|
+
const result = await readCatalogItemVariables(app.sdk, app.getEffectiveInstance(), flowId, catalogItem, { scope });
|
|
109
|
+
app.ok(result, {
|
|
110
|
+
summary: `${result.count} catalog variable(s) on ${catalogItem}; trigger catalog_variables input: ${result.catalog_variables_input || '(none)'}`,
|
|
111
|
+
});
|
|
112
|
+
}),
|
|
113
|
+
})
|
|
86
114
|
.command({
|
|
87
115
|
command: 'list',
|
|
88
116
|
aliases: ['ls'],
|
|
@@ -314,11 +342,13 @@ export function flowsCmd(wrap) {
|
|
|
314
342
|
})
|
|
315
343
|
.command({
|
|
316
344
|
command: 'create',
|
|
317
|
-
describe: 'Create a draft flow from a JSON manifest or guided prompts
|
|
345
|
+
describe: 'Create a draft flow from a JSON manifest or guided prompts',
|
|
318
346
|
builder: (y) => y
|
|
319
347
|
.option('data', { type: 'string', describe: 'Flow manifest as inline JSON' })
|
|
320
348
|
.option('data-file', { type: 'string', describe: 'Read the flow manifest from a JSON file' })
|
|
321
|
-
.option('scope', { type: 'string', describe: 'Transaction scope sys_id or global for the guided picker' })
|
|
349
|
+
.option('scope', { type: 'string', describe: 'Transaction scope sys_id or global for the guided picker' })
|
|
350
|
+
.epilogue('Manifest structure is code-owned. Use `jsn flows schemas` for trigger and input schemas, and\n'
|
|
351
|
+
+ '`jsn actions action-type-schema --id <actionTypeId> --scope <scopeId>` for provider action inputs.'),
|
|
322
352
|
handler: wrap(async (argv, app) => {
|
|
323
353
|
app.requireInstance();
|
|
324
354
|
const dataFile = argv.dataFile ?? argv['data-file'];
|
|
@@ -343,12 +373,21 @@ export function flowsCmd(wrap) {
|
|
|
343
373
|
.command({
|
|
344
374
|
command: 'update [identifier]',
|
|
345
375
|
aliases: ['edit'],
|
|
346
|
-
describe: '
|
|
376
|
+
describe: 'Update a draft, or a published flow that reports write access',
|
|
347
377
|
builder: (y) => y
|
|
348
378
|
.option('data', { type: 'string', describe: 'Update manifest as inline JSON' })
|
|
349
379
|
.option('data-file', { type: 'string', describe: 'Read the update manifest from a JSON file' })
|
|
350
380
|
.option('preview', { type: 'boolean', default: false, describe: 'Validate and show exact before/after input values without saving or versioning' })
|
|
351
|
-
.option('force', { type: 'boolean', default: false, describe: 'Skip confirmation' })
|
|
381
|
+
.option('force', { type: 'boolean', default: false, describe: 'Skip confirmation' })
|
|
382
|
+
.epilogue('Editable: record_create_or_update trigger table/condition, existing action inputs, and stage\n'
|
|
383
|
+
+ 'placement (add a stage, or move flow steps onto one with componentIndexes). A service_catalog\n'
|
|
384
|
+
+ 'trigger is created with its template_catalog_item and catalog_variables inputs. A published flow\n'
|
|
385
|
+
+ 'is edited as its working definition; the published snapshot and runtime pointers must stay\n'
|
|
386
|
+
+ 'unchanged, and the command fails loudly if they do not. A flow without write access is refused\n'
|
|
387
|
+
+ 'before any lock or content write, naming the permission. Flow Logic, flow variables, subflows and\n'
|
|
388
|
+
+ 'error handling still need Flow Designer. Never publishes or executes; omitted values are preserved.\n'
|
|
389
|
+
+ 'Live schemas: `jsn flows schemas` and `jsn actions action-type-schema --id <actionTypeId>\n'
|
|
390
|
+
+ '--scope <scopeId>`.'),
|
|
352
391
|
handler: wrap(async (argv, app) => {
|
|
353
392
|
app.requireInstance();
|
|
354
393
|
const dataFile = argv.dataFile ?? argv['data-file'];
|
|
@@ -383,16 +422,47 @@ export function flowsCmd(wrap) {
|
|
|
383
422
|
});
|
|
384
423
|
}),
|
|
385
424
|
})
|
|
425
|
+
.command({
|
|
426
|
+
command: 'unlock [identifier]',
|
|
427
|
+
describe: 'Release this user\'s stale safe-edit lease after a failed update',
|
|
428
|
+
builder: (y) => y
|
|
429
|
+
.option('force', { type: 'boolean', default: false, describe: 'Skip confirmation' })
|
|
430
|
+
.epilogue('Recovery for an orphaned lease left by a failed update: the provider only releases the calling\n'
|
|
431
|
+
+ 'user\'s own session, the before/after canUserEdit and currentEditor values are printed, and an\n'
|
|
432
|
+
+ 'unconfirmed release fails instead of reporting success. Does not edit content, publish, or touch\n'
|
|
433
|
+
+ 'another user\'s session.'),
|
|
434
|
+
handler: wrap(async (argv, app) => {
|
|
435
|
+
app.requireInstance();
|
|
436
|
+
const identifier = await pickFlow(argv, app);
|
|
437
|
+
if (identifier === undefined) return;
|
|
438
|
+
const sysID = unwrapSysId(await resolveRecord(app.sdk, {
|
|
439
|
+
table: 'sys_hub_flow', identifier, matchField: 'name', resource: 'Flow',
|
|
440
|
+
}));
|
|
441
|
+
await confirmDesignerMutation(argv, app, `Release your Flow Designer safe-edit session on flow ${identifier}? If this flow is open in Flow Designer, that editor's next save will fail.`);
|
|
442
|
+
const result = await releaseOwnFlowSafeEdit(app.sdk, app.getEffectiveInstance(), sysID);
|
|
443
|
+
const state = status => `canUserEdit=${status.canUserEdit}, currentEditor=${JSON.stringify(status.currentEditor ?? null)}`;
|
|
444
|
+
return app.ok({ ...result, flow: { id: sysID, name: identifier } }, {
|
|
445
|
+
summary: result.released
|
|
446
|
+
? `Released this user's safe edit session on flow ${identifier} (${sysID}): ${state(result.before)} -> ${state(result.after)}`
|
|
447
|
+
: `No safe edit session to release on flow ${identifier} (${sysID}): ${state(result.before)}`,
|
|
448
|
+
breadcrumbs: result.released
|
|
449
|
+
? [{ action: 'update', cmd: `jsn flows update ${sysID}`, description: 'Retry the edit' }]
|
|
450
|
+
: [{ action: 'show', cmd: `jsn flows show ${sysID}`, description: 'Inspect the flow' }],
|
|
451
|
+
});
|
|
452
|
+
}),
|
|
453
|
+
})
|
|
386
454
|
.command({
|
|
387
455
|
command: 'delete [identifier]',
|
|
388
|
-
describe: 'Delete a flow (not
|
|
456
|
+
describe: 'Delete a flow (not implemented: use the Flow Designer UI)',
|
|
389
457
|
handler: wrap(async (argv, app) => {
|
|
390
458
|
const identifier = await pickFlow(argv, app);
|
|
391
459
|
if (identifier === undefined) return;
|
|
392
460
|
throw errUsage('Flow deletion requires the Flow Designer GraphQL API - not yet implemented.\n'
|
|
393
461
|
+ 'Use the ServiceNow web UI to delete flows.');
|
|
394
462
|
}),
|
|
395
|
-
})
|
|
463
|
+
})
|
|
464
|
+
.epilogue('Run "jsn flows <command> --help" for details. In a terminal you can omit the target and pick\n'
|
|
465
|
+
+ 'one; scripts use explicit identifiers and manifests.');
|
|
396
466
|
},
|
|
397
467
|
handler: wrap(async (_argv, app) => {
|
|
398
468
|
const summary = 'Manage Flow Designer flows from the sys_hub_flow table. Flow structure comes from the ProcessFlow API, so V1, V2 and subflow definitions all render in full.';
|
package/src/commands/store.js
CHANGED
|
@@ -145,6 +145,10 @@ function emitList(app, argv, page) {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
async function runLifecycle(argv, app, operation) {
|
|
148
|
+
// Validate wait controls before any submission. A usage error after dispatch
|
|
149
|
+
// hides an operation that may already be changing the instance.
|
|
150
|
+
const timeoutMs = argv.wait ? boundedTimeout(argv.timeout) * 1000 : undefined;
|
|
151
|
+
const pollIntervalMs = argv.wait ? boundedPoll(argv.pollInterval) * 1000 : undefined;
|
|
148
152
|
const prepare = operation === 'install' ? prepareInstall : prepareUpdate;
|
|
149
153
|
const plan = await prepare(app.sdk, argv.application, operation === 'install'
|
|
150
154
|
? { version: argv.version, demoData: argv.demoData === true }
|
|
@@ -177,8 +181,6 @@ async function runLifecycle(argv, app, operation) {
|
|
|
177
181
|
});
|
|
178
182
|
return;
|
|
179
183
|
}
|
|
180
|
-
const timeoutMs = boundedTimeout(argv.timeout) * 1000;
|
|
181
|
-
const pollIntervalMs = boundedPoll(argv.pollInterval) * 1000;
|
|
182
184
|
let progress;
|
|
183
185
|
try {
|
|
184
186
|
progress = await waitForOperation(app.sdk, started.tracker_id, { pollIntervalMs, timeoutMs });
|
|
@@ -19,6 +19,27 @@ function defineFormatted(data, formatted) {
|
|
|
19
19
|
Object.defineProperty(data, '_formatted', { value: formatted, enumerable: false, configurable: true });
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export function parseWorkflowStep(value) {
|
|
23
|
+
if (value === undefined) return undefined;
|
|
24
|
+
if (!/^[1-9]\d*$/.test(String(value)) || !Number.isSafeInteger(Number(value))) {
|
|
25
|
+
throw errUsage('--step must be a positive integer.');
|
|
26
|
+
}
|
|
27
|
+
return Number(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function selectWorkflowStep(data, number) {
|
|
31
|
+
if (number === undefined) return data;
|
|
32
|
+
const step = data.steps.find(step => step.number === number);
|
|
33
|
+
if (!step) throw errUsage(`Step ${number} is out of range: ${data.steps.length} steps; valid range ${data.steps.length ? `1–${data.steps.length}` : 'none (0 steps)'}.`);
|
|
34
|
+
return {
|
|
35
|
+
...data,
|
|
36
|
+
activities: data.activities.filter(activity => activity.sys_id === step.sys_id),
|
|
37
|
+
steps: [step],
|
|
38
|
+
transitions: data.transitions.filter(edge => edge.from_id === step.sys_id),
|
|
39
|
+
transitions_by_activity: data.transitions_by_activity.filter(group => group.sys_id === step.sys_id),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
22
43
|
export function workflowsCmd(wrap) {
|
|
23
44
|
return {
|
|
24
45
|
command: 'workflows [subcommand]',
|
|
@@ -67,28 +88,33 @@ export function workflowsCmd(wrap) {
|
|
|
67
88
|
builder: (y) => y
|
|
68
89
|
.positional('identifier', { type: 'string', describe: 'Workflow name, workflow sys_id, or version sys_id' })
|
|
69
90
|
.option('version', { type: 'string', describe: 'Specific wf_workflow_version sys_id (default: published, else newest)' })
|
|
70
|
-
.option('config', { type: 'boolean',
|
|
91
|
+
.option('config', { type: 'boolean', describe: 'Show activity configuration and scripts under each step' })
|
|
92
|
+
.option('step', { type: 'string', describe: 'Inspect one positive step number with full configuration' })
|
|
71
93
|
.option('limit', { alias: 'l', type: 'number', default: 200, describe: 'Maximum activities to read (1–1000)' }),
|
|
72
94
|
handler: wrap(async (argv, app) => {
|
|
73
95
|
app.requireInstance();
|
|
74
96
|
if (typeof argv.identifier !== 'string' || !argv.identifier.trim()) {
|
|
75
97
|
throw errUsage('Provide a legacy workflow name or sys_id.');
|
|
76
98
|
}
|
|
99
|
+
const step = parseWorkflowStep(argv.step);
|
|
77
100
|
const data = await inspectWorkflow(app.sdk, {
|
|
78
101
|
identifier: argv.identifier,
|
|
79
102
|
versionId: argv.version || '',
|
|
80
|
-
|
|
103
|
+
// Keep the existing JSON/read contract; --config controls presentation.
|
|
104
|
+
includeConfiguration: step !== undefined || argv.config !== false,
|
|
81
105
|
limit: argv.limit,
|
|
82
106
|
});
|
|
83
|
-
|
|
107
|
+
const selected = selectWorkflowStep(data, step);
|
|
108
|
+
const formatted = formatWorkflowOutline(data, { includeConfiguration: argv.config === true, step });
|
|
109
|
+
defineFormatted(selected, formatted);
|
|
84
110
|
const versionLabel = data.version
|
|
85
111
|
? `${data.version.name} (${data.selection.reason})`
|
|
86
112
|
: 'no readable version';
|
|
87
|
-
app.ok(
|
|
88
|
-
summary: `Legacy workflow: ${data.workflow.name} — ${versionLabel}, ${
|
|
113
|
+
app.ok(selected, {
|
|
114
|
+
summary: `Legacy workflow: ${data.workflow.name} — ${versionLabel}, ${selected.activities.length} activity(ies)${data.coverage.complete ? '' : ', partial coverage'}`,
|
|
89
115
|
breadcrumbs: [
|
|
90
116
|
{ action: 'list', cmd: 'jsn workflows list', description: 'Back to legacy workflows' },
|
|
91
|
-
...(data.version ? [{ action: 'json', cmd: `jsn workflows show ${data.workflow.
|
|
117
|
+
...(data.version ? [{ action: 'json', cmd: `jsn workflows show ${JSON.stringify(data.workflow.name)} --json`, description: 'Structured definition with IDs' }] : []),
|
|
92
118
|
],
|
|
93
119
|
});
|
|
94
120
|
}),
|
package/src/errors.js
CHANGED
|
@@ -309,6 +309,10 @@ export function renderAppError(err, { app = null, argv = null, identifier = '' }
|
|
|
309
309
|
return { stream: 'stderr', text, exitCode: 2 };
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
if (code === CodeAPI && resolveJsonMode(app, argv) && app) {
|
|
313
|
+
return { stream: 'stdout', text: null, exitCode: 1, appErr: true };
|
|
314
|
+
}
|
|
315
|
+
|
|
312
316
|
if (code === 'system_error') {
|
|
313
317
|
return { stream: 'stderr', text: `Error (system): ${err.message}\n`, exitCode: 3 };
|
|
314
318
|
}
|