@sanity/workflows-cli 0.0.0-main-039-20261113092657
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 +1936 -0
- package/LICENSE +21 -0
- package/README.md +814 -0
- package/bin/run.js +8 -0
- package/dist/command-ids.d.ts +10 -0
- package/dist/command-ids.js +10 -0
- package/dist/commands/workflows/abort.d.ts +29 -0
- package/dist/commands/workflows/abort.js +50 -0
- package/dist/commands/workflows/blueprints/generate.d.ts +12 -0
- package/dist/commands/workflows/blueprints/generate.js +46 -0
- package/dist/commands/workflows/codemod/packages.d.ts +13 -0
- package/dist/commands/workflows/codemod/packages.js +41 -0
- package/dist/commands/workflows/definitions/delete.d.ts +44 -0
- package/dist/commands/workflows/definitions/delete.js +74 -0
- package/dist/commands/workflows/definitions/diff.d.ts +23 -0
- package/dist/commands/workflows/definitions/diff.js +55 -0
- package/dist/commands/workflows/definitions/list.d.ts +51 -0
- package/dist/commands/workflows/definitions/list.js +139 -0
- package/dist/commands/workflows/definitions/show.d.ts +65 -0
- package/dist/commands/workflows/definitions/show.js +129 -0
- package/dist/commands/workflows/definitions/validate.d.ts +14 -0
- package/dist/commands/workflows/definitions/validate.js +50 -0
- package/dist/commands/workflows/deploy.d.ts +117 -0
- package/dist/commands/workflows/deploy.js +266 -0
- package/dist/commands/workflows/diagnose.d.ts +52 -0
- package/dist/commands/workflows/diagnose.js +195 -0
- package/dist/commands/workflows/fire-action.d.ts +53 -0
- package/dist/commands/workflows/fire-action.js +182 -0
- package/dist/commands/workflows/list.d.ts +78 -0
- package/dist/commands/workflows/list.js +248 -0
- package/dist/commands/workflows/nuke.d.ts +73 -0
- package/dist/commands/workflows/nuke.js +176 -0
- package/dist/commands/workflows/reset-activity.d.ts +32 -0
- package/dist/commands/workflows/reset-activity.js +60 -0
- package/dist/commands/workflows/show.d.ts +29 -0
- package/dist/commands/workflows/show.js +156 -0
- package/dist/commands/workflows/start.d.ts +57 -0
- package/dist/commands/workflows/start.js +196 -0
- package/dist/commands/workflows/tail.d.ts +23 -0
- package/dist/commands/workflows/tail.js +83 -0
- package/dist/commands/workflows/whoami.d.ts +15 -0
- package/dist/commands/workflows/whoami.js +53 -0
- package/dist/help.d.ts +13 -0
- package/dist/help.js +50 -0
- package/dist/hooks/finally/telemetry.d.ts +3 -0
- package/dist/hooks/finally/telemetry.js +10 -0
- package/dist/hooks/prerun/telemetry.d.ts +28 -0
- package/dist/hooks/prerun/telemetry.js +37 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/base-command.d.ts +14 -0
- package/dist/lib/base-command.js +41 -0
- package/dist/lib/blueprint-emit.d.ts +56 -0
- package/dist/lib/blueprint-emit.js +233 -0
- package/dist/lib/blueprint-needs.d.ts +5 -0
- package/dist/lib/blueprint-needs.js +231 -0
- package/dist/lib/blueprint-stacks.d.ts +6 -0
- package/dist/lib/blueprint-stacks.js +111 -0
- package/dist/lib/cause-detail.d.ts +9 -0
- package/dist/lib/cause-detail.js +112 -0
- package/dist/lib/client.d.ts +27 -0
- package/dist/lib/client.js +45 -0
- package/dist/lib/codemod/ast.d.ts +17 -0
- package/dist/lib/codemod/ast.js +14 -0
- package/dist/lib/codemod/export-rename.d.ts +17 -0
- package/dist/lib/codemod/export-rename.js +253 -0
- package/dist/lib/codemod/manifest-rewrite.d.ts +14 -0
- package/dist/lib/codemod/manifest-rewrite.js +97 -0
- package/dist/lib/codemod/package-map.d.ts +26 -0
- package/dist/lib/codemod/package-map.js +90 -0
- package/dist/lib/codemod/report.d.ts +4 -0
- package/dist/lib/codemod/report.js +46 -0
- package/dist/lib/codemod/run.d.ts +23 -0
- package/dist/lib/codemod/run.js +106 -0
- package/dist/lib/codemod/source-rewrite.d.ts +20 -0
- package/dist/lib/codemod/source-rewrite.js +149 -0
- package/dist/lib/command-context.d.ts +20 -0
- package/dist/lib/command-context.js +24 -0
- package/dist/lib/command-telemetry.d.ts +54 -0
- package/dist/lib/command-telemetry.js +82 -0
- package/dist/lib/context.d.ts +155 -0
- package/dist/lib/context.js +272 -0
- package/dist/lib/default-partition.d.ts +23 -0
- package/dist/lib/default-partition.js +48 -0
- package/dist/lib/definition-files.d.ts +14 -0
- package/dist/lib/definition-files.js +60 -0
- package/dist/lib/definitions.d.ts +63 -0
- package/dist/lib/definitions.js +84 -0
- package/dist/lib/diff.d.ts +12 -0
- package/dist/lib/diff.js +93 -0
- package/dist/lib/env.d.ts +7 -0
- package/dist/lib/env.js +8 -0
- package/dist/lib/fail.d.ts +36 -0
- package/dist/lib/fail.js +55 -0
- package/dist/lib/failure-kind.d.ts +7 -0
- package/dist/lib/failure-kind.js +66 -0
- package/dist/lib/flags.d.ts +49 -0
- package/dist/lib/flags.js +117 -0
- package/dist/lib/follow-up-command.d.ts +18 -0
- package/dist/lib/follow-up-command.js +12 -0
- package/dist/lib/history-rows.d.ts +3 -0
- package/dist/lib/history-rows.js +44 -0
- package/dist/lib/load-config.d.ts +51 -0
- package/dist/lib/load-config.js +108 -0
- package/dist/lib/nuke.d.ts +124 -0
- package/dist/lib/nuke.js +206 -0
- package/dist/lib/operation-args.d.ts +42 -0
- package/dist/lib/operation-args.js +21 -0
- package/dist/lib/ops-report.d.ts +45 -0
- package/dist/lib/ops-report.js +31 -0
- package/dist/lib/params.d.ts +3 -0
- package/dist/lib/params.js +21 -0
- package/dist/lib/pick-dataset.d.ts +10 -0
- package/dist/lib/pick-dataset.js +30 -0
- package/dist/lib/prompt.d.ts +35 -0
- package/dist/lib/prompt.js +11 -0
- package/dist/lib/read-fanout.d.ts +45 -0
- package/dist/lib/read-fanout.js +44 -0
- package/dist/lib/select-deployment.d.ts +31 -0
- package/dist/lib/select-deployment.js +91 -0
- package/dist/lib/share-definitions.d.ts +101 -0
- package/dist/lib/share-definitions.js +188 -0
- package/dist/lib/telemetry-setup.d.ts +81 -0
- package/dist/lib/telemetry-setup.js +111 -0
- package/dist/lib/telemetry.d.ts +81 -0
- package/dist/lib/telemetry.js +90 -0
- package/dist/lib/ui.d.ts +91 -0
- package/dist/lib/ui.js +116 -0
- package/dist/standalone-argv.d.ts +14 -0
- package/dist/standalone-argv.js +57 -0
- package/oclif.manifest.json +1731 -0
- package/package.json +121 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Diagnosis, type DiagnoseInput, type MissingDocument, type SuggestedRemediation, type WorkflowEvaluation } from '@sanity/workflows';
|
|
2
|
+
import { WorkflowCommand } from '../../lib/base-command.ts';
|
|
3
|
+
/** The `--json` transitions payload: raw derived state (atom GROQ, negation,
|
|
4
|
+
* pivotality, solvable requirement) — structure for scripts, never baked
|
|
5
|
+
* English. Pure so the shape is a testable contract. */
|
|
6
|
+
export declare function rawTransitionProjection(evaluation: WorkflowEvaluation): {
|
|
7
|
+
name: string;
|
|
8
|
+
to: string;
|
|
9
|
+
whenSatisfied: boolean;
|
|
10
|
+
unevaluable: boolean;
|
|
11
|
+
blockedBy: {
|
|
12
|
+
groq: string;
|
|
13
|
+
negated: boolean;
|
|
14
|
+
pivotal: boolean;
|
|
15
|
+
requirement?: import("@sanity/workflows").AtomRequirement;
|
|
16
|
+
}[];
|
|
17
|
+
}[];
|
|
18
|
+
/**
|
|
19
|
+
* The diagnosis body: the verdict line, the current stage's activities +
|
|
20
|
+
* transitions as evidence (for any in-flight state), and the cause block with
|
|
21
|
+
* the engine's suggested fix when stuck. Pure so every verdict permutation is
|
|
22
|
+
* assertable without driving a live evaluation. Takes the engine's
|
|
23
|
+
* {@link SuggestedRemediation}s rather than re-deriving them, so the rendered
|
|
24
|
+
* fix block and the `--json` output stay one computation.
|
|
25
|
+
*/
|
|
26
|
+
export declare function renderDiagnosis({ diagnosis, input, remediations, explanations, allMissingDocuments, }: {
|
|
27
|
+
diagnosis: Diagnosis;
|
|
28
|
+
input: DiagnoseInput;
|
|
29
|
+
remediations: SuggestedRemediation[];
|
|
30
|
+
/** Full evaluation evidence, including references outside the blocking subset. */
|
|
31
|
+
allMissingDocuments?: MissingDocument[] | undefined;
|
|
32
|
+
/** Insight summaries per unsatisfied transition name — rendered under the
|
|
33
|
+
* transition line so "stuck" reads as "stuck until X". */
|
|
34
|
+
explanations?: ReadonlyMap<string, string> | undefined;
|
|
35
|
+
}): string[];
|
|
36
|
+
export default class Diagnose extends WorkflowCommand {
|
|
37
|
+
static description: string;
|
|
38
|
+
static examples: string[];
|
|
39
|
+
static args: {
|
|
40
|
+
instanceId: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
41
|
+
};
|
|
42
|
+
static flags: {
|
|
43
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
44
|
+
'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
45
|
+
dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
46
|
+
'media-library-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
47
|
+
deployment: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
48
|
+
partition: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
49
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
50
|
+
};
|
|
51
|
+
run(): Promise<void>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
|
+
import { Args } from '@oclif/core';
|
|
3
|
+
import { formatDateTime } from '@sanity/cli-core/dates';
|
|
4
|
+
import { diagnoseInputFromEvaluation, workflow, unsatisfiedTransitionSummaries, } from '@sanity/workflows';
|
|
5
|
+
import logSymbols from 'log-symbols';
|
|
6
|
+
import { WorkflowCommand } from '../../lib/base-command.js';
|
|
7
|
+
import { stuckDiagnosisLines, stuckHeadline } from '../../lib/cause-detail.js';
|
|
8
|
+
import { resolveReadInstanceContext } from '../../lib/context.js';
|
|
9
|
+
import { failOn } from '../../lib/fail.js';
|
|
10
|
+
import { instanceFlags, jsonFlags, resourceFlags } from '../../lib/flags.js';
|
|
11
|
+
import { baseEngineArgs } from '../../lib/operation-args.js';
|
|
12
|
+
import { sectionHeader, activityIcon } from '../../lib/ui.js';
|
|
13
|
+
import { instanceHeader } from './show.js';
|
|
14
|
+
function formatAssignee(a) {
|
|
15
|
+
return a.type === 'user' ? `user:${a.id}` : `role:${a.role}`;
|
|
16
|
+
}
|
|
17
|
+
function activityLine(t, assignees) {
|
|
18
|
+
const who = assignees.length > 0
|
|
19
|
+
? styleText('dim', ` assigned → ${assignees.map(formatAssignee).join(', ')}`)
|
|
20
|
+
: '';
|
|
21
|
+
return ` ${activityIcon[t.status]} ${t.activity.name} ${styleText('dim', `[${t.status}]`)}${who}`;
|
|
22
|
+
}
|
|
23
|
+
function transitionLine(tr, explanation) {
|
|
24
|
+
const mark = tr.whenSatisfied ? styleText('green', 'ready') : styleText('red', 'false');
|
|
25
|
+
const line = ` → ${tr.transition.to} ${styleText('dim', tr.transition.when)} ${mark}`;
|
|
26
|
+
return explanation !== undefined ? `${line}\n ${styleText('dim', `↳ ${explanation}`)}` : line;
|
|
27
|
+
}
|
|
28
|
+
function currentStageLines(input, explanations) {
|
|
29
|
+
const lines = [
|
|
30
|
+
`${sectionHeader('Stage')} ${input.instance.currentStage}`,
|
|
31
|
+
sectionHeader('Activities'),
|
|
32
|
+
];
|
|
33
|
+
for (const t of input.activities.filter((a) => !a.scopedOut)) {
|
|
34
|
+
lines.push(activityLine(t, input.assignees[t.activity.name] ?? []));
|
|
35
|
+
}
|
|
36
|
+
if (input.transitions.length > 0) {
|
|
37
|
+
lines.push('', sectionHeader('Exit transitions'));
|
|
38
|
+
for (const tr of input.transitions) {
|
|
39
|
+
lines.push(transitionLine(tr, explanations?.get(tr.transition.name)));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return lines;
|
|
43
|
+
}
|
|
44
|
+
function waitingHeadline(w) {
|
|
45
|
+
const who = w.assignees.length > 0 ? ` on ${w.assignees.map(formatAssignee).join(', ')}` : '';
|
|
46
|
+
if (w.waitingFor === 'automation') {
|
|
47
|
+
return `waiting${who} on automation — a trigger fires on its own when its condition holds`;
|
|
48
|
+
}
|
|
49
|
+
if (w.waitingFor === 'manual-action')
|
|
50
|
+
return `waiting${who} for an eligible caller to act`;
|
|
51
|
+
return `waiting${who} for action: ${w.actions.join(' or ')}`;
|
|
52
|
+
}
|
|
53
|
+
function waitingLines(w) {
|
|
54
|
+
const who = w.assignees.length > 0
|
|
55
|
+
? `assigned to ${w.assignees.map(formatAssignee).join(', ')}`
|
|
56
|
+
: 'unassigned — no holder is selected';
|
|
57
|
+
if (w.waitingFor === 'automation') {
|
|
58
|
+
return [
|
|
59
|
+
`${logSymbols.info} activity '${w.activity}' is active (${who}),`,
|
|
60
|
+
`waiting on automation: its cascade-fired action(s) fire on their own when their`,
|
|
61
|
+
`trigger conditions hold — nothing for a caller to fire.`,
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
if (w.waitingFor === 'manual-action') {
|
|
65
|
+
return [
|
|
66
|
+
`${logSymbols.info} activity '${w.activity}' is active (${who}),`,
|
|
67
|
+
`waiting for a manual action, but none is available to this caller right now.`,
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
return [
|
|
71
|
+
`${logSymbols.info} activity '${w.activity}' is active (${who}),`,
|
|
72
|
+
`waiting for action: ${w.actions.join(' or ')}. This is the normal in-flight`,
|
|
73
|
+
`state — it advances when someone acts.`,
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
function blockedHeadline(b) {
|
|
77
|
+
const who = b.assignees.length > 0 ? ` for ${b.assignees.map(formatAssignee).join(', ')}` : '';
|
|
78
|
+
return `activity '${b.activity}'${who} is not yet ready — unmet requirement(s): ${b.requirements.join(', ')}`;
|
|
79
|
+
}
|
|
80
|
+
function blockedLines(b) {
|
|
81
|
+
const who = b.assignees.length > 0
|
|
82
|
+
? `assigned to ${b.assignees.map(formatAssignee).join(', ')}`
|
|
83
|
+
: 'unassigned';
|
|
84
|
+
return [
|
|
85
|
+
`${logSymbols.info} activity '${b.activity}' is visible but not yet executable (${who}).`,
|
|
86
|
+
`Unmet requirement(s): ${b.requirements.join(', ')}. It can't be acted on until`,
|
|
87
|
+
`those preconditions are met — check what would satisfy them (a prerequisite`,
|
|
88
|
+
`activity completing, required content landing). It will not advance on its own.`,
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
function liveChildrenTail(diagnosis) {
|
|
92
|
+
if (diagnosis.liveChildren === undefined)
|
|
93
|
+
return '';
|
|
94
|
+
return ` ${styleText('yellow', `${diagnosis.liveChildren} spawned child workflow(s) still running.`)}`;
|
|
95
|
+
}
|
|
96
|
+
function statusLine(diagnosis) {
|
|
97
|
+
switch (diagnosis.state) {
|
|
98
|
+
case 'progressing':
|
|
99
|
+
return `${logSymbols.success} ${styleText('green', 'progressing')} — this instance will advance on its own.`;
|
|
100
|
+
case 'waiting':
|
|
101
|
+
return `${logSymbols.info} ${styleText('cyan', 'waiting')} — ${waitingHeadline(diagnosis)}`;
|
|
102
|
+
case 'blocked':
|
|
103
|
+
return `${logSymbols.info} ${styleText('cyan', 'blocked')} — ${blockedHeadline(diagnosis)}`;
|
|
104
|
+
case 'completed':
|
|
105
|
+
return `${logSymbols.success} ${styleText('green', 'completed')} at ${formatDateTime(diagnosis.at)}.${liveChildrenTail(diagnosis)}`;
|
|
106
|
+
case 'aborted': {
|
|
107
|
+
const tail = diagnosis.reason !== undefined ? ` — ${diagnosis.reason}` : '';
|
|
108
|
+
return `${logSymbols.info} ${styleText('dim', 'aborted')} at ${formatDateTime(diagnosis.at)}${tail}.${liveChildrenTail(diagnosis)}`;
|
|
109
|
+
}
|
|
110
|
+
case 'stuck':
|
|
111
|
+
return stuckHeadline(diagnosis.cause);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function rawTransitionProjection(evaluation) {
|
|
115
|
+
return evaluation.currentStage.transitions.map((t) => ({
|
|
116
|
+
name: t.transition.name,
|
|
117
|
+
to: t.transition.to,
|
|
118
|
+
whenSatisfied: t.whenSatisfied,
|
|
119
|
+
unevaluable: t.unevaluable,
|
|
120
|
+
blockedBy: t.insight.blockedBy.map((atom) => ({
|
|
121
|
+
groq: atom.atom.groq,
|
|
122
|
+
negated: atom.atom.negated,
|
|
123
|
+
pivotal: atom.pivotal,
|
|
124
|
+
...(atom.requirement !== undefined ? { requirement: atom.requirement } : {}),
|
|
125
|
+
})),
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
export function renderDiagnosis({ diagnosis, input, remediations, explanations, allMissingDocuments, }) {
|
|
129
|
+
const lines = [statusLine(diagnosis)];
|
|
130
|
+
const inFlight = diagnosis.state === 'progressing' ||
|
|
131
|
+
diagnosis.state === 'waiting' ||
|
|
132
|
+
diagnosis.state === 'blocked' ||
|
|
133
|
+
diagnosis.state === 'stuck';
|
|
134
|
+
if (inFlight) {
|
|
135
|
+
lines.push('', ...currentStageLines(input, explanations));
|
|
136
|
+
}
|
|
137
|
+
if (diagnosis.state === 'waiting') {
|
|
138
|
+
lines.push('', ...waitingLines(diagnosis));
|
|
139
|
+
}
|
|
140
|
+
if (diagnosis.state === 'blocked') {
|
|
141
|
+
lines.push('', ...blockedLines(diagnosis));
|
|
142
|
+
}
|
|
143
|
+
lines.push(...stuckDiagnosisLines({ diagnosis, allMissingDocuments, remediations }));
|
|
144
|
+
return lines;
|
|
145
|
+
}
|
|
146
|
+
export default class Diagnose extends WorkflowCommand {
|
|
147
|
+
static description = "Explain why a workflow instance is or isn't progressing, and what would unstick it.";
|
|
148
|
+
static examples = [
|
|
149
|
+
'<%= config.bin %> workflows diagnose wf-instance.abc123',
|
|
150
|
+
'<%= config.bin %> workflows diagnose wf-instance.abc123 --partition prod',
|
|
151
|
+
'<%= config.bin %> workflows diagnose wf-instance.abc123 --json',
|
|
152
|
+
];
|
|
153
|
+
static args = {
|
|
154
|
+
instanceId: Args.string({ required: true, description: 'Workflow instance id.' }),
|
|
155
|
+
};
|
|
156
|
+
static flags = {
|
|
157
|
+
...instanceFlags,
|
|
158
|
+
...resourceFlags,
|
|
159
|
+
...jsonFlags,
|
|
160
|
+
};
|
|
161
|
+
async run() {
|
|
162
|
+
const { args, flags } = await this.parse(Diagnose);
|
|
163
|
+
const { client, scope } = await resolveReadInstanceContext(flags, args.instanceId);
|
|
164
|
+
const { evaluation, diagnosis, remediations } = await workflow
|
|
165
|
+
.diagnose({
|
|
166
|
+
client,
|
|
167
|
+
...baseEngineArgs(scope),
|
|
168
|
+
instanceId: args.instanceId,
|
|
169
|
+
})
|
|
170
|
+
.catch((error) => failOn(error, 'diagnose failed:'));
|
|
171
|
+
const input = diagnoseInputFromEvaluation(evaluation);
|
|
172
|
+
if (flags.json) {
|
|
173
|
+
this.log(JSON.stringify({
|
|
174
|
+
instanceId: evaluation.instance._id,
|
|
175
|
+
stage: evaluation.instance.currentStage,
|
|
176
|
+
diagnosis,
|
|
177
|
+
remediations,
|
|
178
|
+
transitions: rawTransitionProjection(evaluation),
|
|
179
|
+
}, null, 2));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this.log(instanceHeader(evaluation.instance));
|
|
183
|
+
this.log('');
|
|
184
|
+
const explanations = new Map(unsatisfiedTransitionSummaries(evaluation).map((entry) => [entry.transition, entry.summary]));
|
|
185
|
+
for (const line of renderDiagnosis({
|
|
186
|
+
diagnosis,
|
|
187
|
+
input,
|
|
188
|
+
remediations,
|
|
189
|
+
explanations,
|
|
190
|
+
allMissingDocuments: evaluation.missingDocuments,
|
|
191
|
+
})) {
|
|
192
|
+
this.log(line);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type AvailableAction } from '@sanity/workflows';
|
|
2
|
+
import { WorkflowCommand } from '../../lib/base-command.ts';
|
|
3
|
+
import { type FollowUpContext } from '../../lib/follow-up-command.ts';
|
|
4
|
+
import { type WriteOutcome, type WriteReport } from '../../lib/ops-report.ts';
|
|
5
|
+
/**
|
|
6
|
+
* The list-mode body: every action on the current stage's activities, marked
|
|
7
|
+
* fireable or not (with the disabling reason), plus the command that fires
|
|
8
|
+
* one. Pure so the populated/empty permutations assert without a live
|
|
9
|
+
* evaluation.
|
|
10
|
+
*/
|
|
11
|
+
export declare function renderAvailableActions({ actions, stage, instanceId, followUp, }: {
|
|
12
|
+
actions: AvailableAction[];
|
|
13
|
+
stage: string;
|
|
14
|
+
instanceId: string;
|
|
15
|
+
followUp: FollowUpContext;
|
|
16
|
+
}): string[];
|
|
17
|
+
/** The `--json` payload for a fired action — the structured counterpart of
|
|
18
|
+
* {@link fireActionReport}. Pure so its shape is asserted directly. */
|
|
19
|
+
export declare function fireResultJson(result: WriteOutcome, ids: {
|
|
20
|
+
instanceId: string;
|
|
21
|
+
activity: string;
|
|
22
|
+
action: string;
|
|
23
|
+
}): Record<string, unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Turn a `fireAction` result into the spinner message + ops block. Pure so
|
|
26
|
+
* the fired / no-op / cascaded / ops permutations assert without a live
|
|
27
|
+
* fire.
|
|
28
|
+
*/
|
|
29
|
+
export declare function fireActionReport({ result, activity, action, }: {
|
|
30
|
+
result: WriteOutcome;
|
|
31
|
+
activity: string;
|
|
32
|
+
action: string;
|
|
33
|
+
}): WriteReport;
|
|
34
|
+
export default class FireAction extends WorkflowCommand {
|
|
35
|
+
static description: string;
|
|
36
|
+
static examples: string[];
|
|
37
|
+
static args: {
|
|
38
|
+
instanceId: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
39
|
+
};
|
|
40
|
+
static flags: {
|
|
41
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
42
|
+
deployment: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
43
|
+
partition: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
44
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
45
|
+
activity: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
46
|
+
action: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
47
|
+
param: import("@oclif/core/interfaces").OptionFlag<string[], import("@oclif/core/interfaces").CustomOptions>;
|
|
48
|
+
};
|
|
49
|
+
static telemetry: import("../../lib/command-telemetry.ts").CommandTelemetry;
|
|
50
|
+
run(): Promise<void>;
|
|
51
|
+
private listActions;
|
|
52
|
+
private fireOne;
|
|
53
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
|
+
import { Args, Flags } from '@oclif/core';
|
|
3
|
+
import { actionRendering, actionDisabledDetail, deniedGuardLabels, workflow, } from '@sanity/workflows';
|
|
4
|
+
import logSymbols from 'log-symbols';
|
|
5
|
+
import { WorkflowCommand } from '../../lib/base-command.js';
|
|
6
|
+
import { defineCommandTelemetry } from '../../lib/command-telemetry.js';
|
|
7
|
+
import { resolveInstanceContext } from '../../lib/context.js';
|
|
8
|
+
import { fail, failOn, failOnThrow } from '../../lib/fail.js';
|
|
9
|
+
import { instanceFlags, jsonFlags } from '../../lib/flags.js';
|
|
10
|
+
import { followUpCommand } from '../../lib/follow-up-command.js';
|
|
11
|
+
import { baseEngineArgs, cliEngine } from '../../lib/operation-args.js';
|
|
12
|
+
import { cascadeTail, opsAppliedLines, runWriteVerb, } from '../../lib/ops-report.js';
|
|
13
|
+
import { parseParams } from '../../lib/params.js';
|
|
14
|
+
import { instanceHeader } from './show.js';
|
|
15
|
+
function reasonText(reason) {
|
|
16
|
+
if (reason.kind === 'mutation-guard-denied') {
|
|
17
|
+
return `blocked by mutation guard(s) ${deniedGuardLabels(reason.denied).join(', ')}`;
|
|
18
|
+
}
|
|
19
|
+
return actionDisabledDetail(reason);
|
|
20
|
+
}
|
|
21
|
+
function paramLabel(p) {
|
|
22
|
+
return `${p.name}${p.required === true ? '' : '?'}:${p.type}`;
|
|
23
|
+
}
|
|
24
|
+
function actionLines(a) {
|
|
25
|
+
const title = a.title !== undefined ? styleText('dim', ` (${a.title})`) : '';
|
|
26
|
+
const rendering = actionRendering(a);
|
|
27
|
+
if (rendering === 'absent')
|
|
28
|
+
return [];
|
|
29
|
+
if (rendering === 'automation') {
|
|
30
|
+
return [
|
|
31
|
+
` ${styleText('cyan', '⚡')} ${a.activity} → ${a.action}${title} ${styleText('dim', '[automation]')}`,
|
|
32
|
+
...(a.disabledReason?.kind === 'cascade-fired'
|
|
33
|
+
? [styleText('dim', ` ${actionDisabledDetail(a.disabledReason)}`)]
|
|
34
|
+
: []),
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
const mark = a.allowed ? logSymbols.success : logSymbols.error;
|
|
38
|
+
const lines = [
|
|
39
|
+
` ${mark} ${a.activity} → ${a.action}${title} ${styleText('dim', `[activity ${a.activityStatus}]`)}`,
|
|
40
|
+
];
|
|
41
|
+
if (a.params.length > 0) {
|
|
42
|
+
lines.push(styleText('dim', ` params: ${a.params.map(paramLabel).join(', ')}`));
|
|
43
|
+
}
|
|
44
|
+
if (!a.allowed && a.disabledReason !== undefined) {
|
|
45
|
+
lines.push(styleText('dim', ` disabled: ${reasonText(a.disabledReason)}`));
|
|
46
|
+
}
|
|
47
|
+
return lines;
|
|
48
|
+
}
|
|
49
|
+
export function renderAvailableActions({ actions, stage, instanceId, followUp, }) {
|
|
50
|
+
if (actions.length === 0) {
|
|
51
|
+
return [`No actions on the activities of the current stage ('${stage}').`];
|
|
52
|
+
}
|
|
53
|
+
const lines = [styleText('bold', `Actions on stage '${stage}':`), ''];
|
|
54
|
+
for (const a of actions) {
|
|
55
|
+
lines.push(...actionLines(a));
|
|
56
|
+
}
|
|
57
|
+
lines.push('', styleText('dim', 'Fire one with:'), styleText('dim', ` ${followUpCommand(followUp, 'fire-action', instanceId, '--activity', '<activity>', '--action', '<action>')}`));
|
|
58
|
+
return lines;
|
|
59
|
+
}
|
|
60
|
+
export function fireResultJson(result, ids) {
|
|
61
|
+
return {
|
|
62
|
+
instanceId: ids.instanceId,
|
|
63
|
+
activity: ids.activity,
|
|
64
|
+
action: ids.action,
|
|
65
|
+
changed: result.changed,
|
|
66
|
+
cascaded: result.cascaded,
|
|
67
|
+
currentStage: result.instance.currentStage,
|
|
68
|
+
...(result.ranOps !== undefined ? { ranOps: result.ranOps } : {}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function fireActionReport({ result, activity, action, }) {
|
|
72
|
+
const stage = styleText('bold', result.instance.currentStage);
|
|
73
|
+
if (!result.changed) {
|
|
74
|
+
return {
|
|
75
|
+
changed: false,
|
|
76
|
+
message: `fireAction returned without firing — activity '${activity}' is no longer active`,
|
|
77
|
+
opsLines: [],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
changed: true,
|
|
82
|
+
message: `Fired ${styleText('bold', action)} on ${styleText('bold', activity)} — now at ${stage}${cascadeTail(result.cascaded)}`,
|
|
83
|
+
opsLines: opsAppliedLines(result.ranOps),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const flags = {
|
|
87
|
+
...instanceFlags,
|
|
88
|
+
activity: Flags.string({
|
|
89
|
+
description: 'Activity the action belongs to. Required to fire; omit --action to list.',
|
|
90
|
+
}),
|
|
91
|
+
action: Flags.string({
|
|
92
|
+
description: 'Action to fire. Omit to list the actions available on the instance.',
|
|
93
|
+
}),
|
|
94
|
+
param: Flags.string({
|
|
95
|
+
description: 'Action param as key=value (repeatable). Values are JSON-parsed, falling back to a string.',
|
|
96
|
+
multiple: true,
|
|
97
|
+
default: [],
|
|
98
|
+
}),
|
|
99
|
+
...jsonFlags,
|
|
100
|
+
};
|
|
101
|
+
export default class FireAction extends WorkflowCommand {
|
|
102
|
+
static description = 'Fire an action on an instance to unstick a waiting activity — the write acts as the configured token. Omit --action to list what can be fired.';
|
|
103
|
+
static examples = [
|
|
104
|
+
'<%= config.bin %> workflows fire-action wf-instance.abc123',
|
|
105
|
+
'<%= config.bin %> workflows fire-action wf-instance.abc123 --activity approve --action approve',
|
|
106
|
+
'<%= config.bin %> workflows fire-action wf-instance.abc123 --activity publish --action publish --param note=shipping',
|
|
107
|
+
];
|
|
108
|
+
static args = {
|
|
109
|
+
instanceId: Args.string({ required: true, description: 'Workflow instance id.' }),
|
|
110
|
+
};
|
|
111
|
+
static flags = flags;
|
|
112
|
+
static telemetry = defineCommandTelemetry(flags, { redact: ['param'] });
|
|
113
|
+
async run() {
|
|
114
|
+
const { args, flags } = await this.parse(FireAction);
|
|
115
|
+
const { client, scope } = await resolveInstanceContext(flags, args.instanceId);
|
|
116
|
+
if (flags.action === undefined) {
|
|
117
|
+
await this.listActions({
|
|
118
|
+
client,
|
|
119
|
+
scope,
|
|
120
|
+
instanceId: args.instanceId,
|
|
121
|
+
json: flags.json,
|
|
122
|
+
followUp: {
|
|
123
|
+
bin: this.config.bin,
|
|
124
|
+
selection: { deployment: flags.deployment, partition: flags.partition },
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (flags.activity === undefined) {
|
|
130
|
+
fail('fire-action usage error:', 'specify --activity for the action (or omit --action to list what can be fired)');
|
|
131
|
+
}
|
|
132
|
+
await this.fireOne({
|
|
133
|
+
client,
|
|
134
|
+
scope,
|
|
135
|
+
instanceId: args.instanceId,
|
|
136
|
+
activity: flags.activity,
|
|
137
|
+
action: flags.action,
|
|
138
|
+
params: flags.param,
|
|
139
|
+
json: flags.json,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
async listActions({ client, scope, instanceId, json, followUp, }) {
|
|
143
|
+
const { evaluation, actions } = await workflow
|
|
144
|
+
.availableActions({
|
|
145
|
+
client,
|
|
146
|
+
...baseEngineArgs(scope),
|
|
147
|
+
instanceId,
|
|
148
|
+
})
|
|
149
|
+
.catch((error) => failOn(error, 'fire-action failed:'));
|
|
150
|
+
const stage = evaluation.instance.currentStage;
|
|
151
|
+
if (json) {
|
|
152
|
+
this.log(JSON.stringify({ instanceId, stage, actions }, null, 2));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
this.log(instanceHeader(evaluation.instance));
|
|
156
|
+
this.log('');
|
|
157
|
+
for (const line of renderAvailableActions({ actions, stage, instanceId, followUp })) {
|
|
158
|
+
this.log(line);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async fireOne(opts) {
|
|
162
|
+
const { client, scope, instanceId, activity, action, json } = opts;
|
|
163
|
+
const params = failOnThrow('Invalid --param:', () => parseParams(opts.params));
|
|
164
|
+
const engine = cliEngine(client, scope);
|
|
165
|
+
const fireArgs = { instanceId, activity, action, params };
|
|
166
|
+
if (json) {
|
|
167
|
+
const result = await engine
|
|
168
|
+
.fireAction(fireArgs)
|
|
169
|
+
.catch((error) => failOn(error, 'fire-action error:'));
|
|
170
|
+
this.log(JSON.stringify(fireResultJson(result, { instanceId, activity, action }), null, 2));
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
await runWriteVerb({
|
|
174
|
+
startLabel: `Firing ${action} on ${activity}…`,
|
|
175
|
+
failLabel: 'Action rejected',
|
|
176
|
+
failHeadline: 'fire-action error:',
|
|
177
|
+
run: () => engine.fireAction(fireArgs),
|
|
178
|
+
report: (result) => fireActionReport({ result, activity, action }),
|
|
179
|
+
log: (line) => this.log(line),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type AssignmentIdentity, type AssignmentStateCounts, type GdrUri, type StageEntry, type TerminalState } from '@sanity/workflows';
|
|
2
|
+
import { WorkflowCommand } from '../../lib/base-command.ts';
|
|
3
|
+
interface InstanceRow {
|
|
4
|
+
_id: string;
|
|
5
|
+
definition: string;
|
|
6
|
+
tag: string;
|
|
7
|
+
currentStage: string;
|
|
8
|
+
completedAt?: string | null;
|
|
9
|
+
abortedAt?: string | null;
|
|
10
|
+
lastChangedAt: string;
|
|
11
|
+
modelVersion?: number | null;
|
|
12
|
+
minReaderModel?: number | null;
|
|
13
|
+
stages?: StageEntry[];
|
|
14
|
+
}
|
|
15
|
+
interface ListFlags {
|
|
16
|
+
'include-completed': boolean;
|
|
17
|
+
failed: boolean;
|
|
18
|
+
definition?: string | undefined;
|
|
19
|
+
document?: string | undefined;
|
|
20
|
+
'assignment-user'?: string | undefined;
|
|
21
|
+
'assignment-role'?: string[] | undefined;
|
|
22
|
+
'assignment-state'?: string[] | undefined;
|
|
23
|
+
partition?: string | undefined;
|
|
24
|
+
limit: number;
|
|
25
|
+
}
|
|
26
|
+
interface ListQueryClient {
|
|
27
|
+
fetch<T>(groq: string, params: Record<string, unknown>, options: {
|
|
28
|
+
tag: string;
|
|
29
|
+
}): Promise<T>;
|
|
30
|
+
}
|
|
31
|
+
export declare function buildListQuery(flags: ListFlags): {
|
|
32
|
+
groq: string;
|
|
33
|
+
params: Record<string, unknown>;
|
|
34
|
+
};
|
|
35
|
+
/** Map a queried instance to its display row (derives the status column). */
|
|
36
|
+
export declare function instanceRow(r: InstanceRow, identity?: AssignmentIdentity): {
|
|
37
|
+
_id: string;
|
|
38
|
+
definition: string;
|
|
39
|
+
partition: string;
|
|
40
|
+
currentStage: string;
|
|
41
|
+
status: TerminalState;
|
|
42
|
+
lastChangedAt: string;
|
|
43
|
+
assignment?: AssignmentStateCounts;
|
|
44
|
+
};
|
|
45
|
+
export default class List extends WorkflowCommand {
|
|
46
|
+
static description: string;
|
|
47
|
+
static examples: string[];
|
|
48
|
+
static flags: {
|
|
49
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
50
|
+
'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
51
|
+
dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
52
|
+
'media-library-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
53
|
+
deployment: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
54
|
+
partition: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
55
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
56
|
+
'include-completed': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
57
|
+
failed: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
58
|
+
definition: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
59
|
+
document: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
60
|
+
'assignment-user': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
61
|
+
'assignment-role': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
62
|
+
'assignment-state': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
63
|
+
limit: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
64
|
+
};
|
|
65
|
+
run(): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/** Fetch one target's projected rows, defensively rechecking document refs. */
|
|
68
|
+
export declare function fetchRows({ client, groq, params, document, limit, }: {
|
|
69
|
+
client: ListQueryClient;
|
|
70
|
+
groq: string;
|
|
71
|
+
params: Record<string, unknown>;
|
|
72
|
+
document: GdrUri | undefined;
|
|
73
|
+
limit: number;
|
|
74
|
+
}): Promise<{
|
|
75
|
+
rows: InstanceRow[];
|
|
76
|
+
hasMore: boolean;
|
|
77
|
+
}>;
|
|
78
|
+
export {};
|