@sanity/workflow-cli 0.8.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +485 -0
- package/README.md +145 -63
- package/bin/run.js +0 -4
- package/dist/commands/abort.d.ts +8 -12
- package/dist/commands/abort.js +24 -34
- package/dist/commands/definition/delete.d.ts +6 -6
- package/dist/commands/definition/delete.js +17 -33
- package/dist/commands/definition/diff.d.ts +10 -3
- package/dist/commands/definition/diff.js +21 -29
- package/dist/commands/definition/list.d.ts +5 -6
- package/dist/commands/definition/list.js +44 -50
- package/dist/commands/definition/show.d.ts +22 -13
- package/dist/commands/definition/show.js +25 -36
- package/dist/commands/deploy.d.ts +67 -8
- package/dist/commands/deploy.js +136 -32
- package/dist/commands/diagnose.d.ts +22 -4
- package/dist/commands/diagnose.js +45 -61
- package/dist/commands/fire-action.d.ts +7 -30
- package/dist/commands/fire-action.js +42 -115
- package/dist/commands/list.d.ts +9 -10
- package/dist/commands/list.js +49 -62
- package/dist/commands/{retry-activity.d.ts → reset-activity.d.ts} +1 -1
- package/dist/commands/{retry-activity.js → reset-activity.js} +2 -3
- package/dist/commands/set-stage.d.ts +27 -3
- package/dist/commands/set-stage.js +63 -12
- package/dist/commands/show.d.ts +3 -2
- package/dist/commands/show.js +15 -21
- package/dist/commands/start.d.ts +56 -0
- package/dist/commands/start.js +133 -0
- package/dist/commands/tail.d.ts +5 -2
- package/dist/commands/tail.js +25 -26
- package/dist/hooks/finally/telemetry.d.ts +8 -0
- package/dist/hooks/finally/telemetry.js +13 -0
- package/dist/hooks/prerun/telemetry.d.ts +5 -0
- package/dist/hooks/prerun/telemetry.js +5 -0
- package/dist/index.js +0 -3
- package/dist/lib/base-command.d.ts +14 -0
- package/dist/lib/base-command.js +10 -0
- package/dist/lib/client.d.ts +11 -14
- package/dist/lib/client.js +29 -34
- package/dist/lib/context.d.ts +98 -0
- package/dist/lib/context.js +83 -0
- package/dist/lib/definitions.d.ts +38 -29
- package/dist/lib/definitions.js +34 -93
- package/dist/lib/diff.d.ts +5 -2
- package/dist/lib/diff.js +62 -20
- package/dist/lib/env.d.ts +4 -6
- package/dist/lib/env.js +4 -9
- package/dist/lib/fail.d.ts +12 -0
- package/dist/lib/fail.js +25 -16
- package/dist/lib/flags.d.ts +7 -2
- package/dist/lib/flags.js +7 -3
- package/dist/lib/load-config.d.ts +15 -0
- package/dist/lib/load-config.js +89 -0
- package/dist/lib/operation-args.d.ts +20 -15
- package/dist/lib/operation-args.js +9 -40
- package/dist/lib/ops-report.d.ts +29 -13
- package/dist/lib/ops-report.js +20 -17
- package/dist/lib/params.d.ts +7 -0
- package/dist/lib/params.js +18 -0
- package/dist/lib/read-fanout.d.ts +22 -0
- package/dist/lib/read-fanout.js +28 -0
- package/dist/lib/select-deployment.d.ts +31 -0
- package/dist/lib/select-deployment.js +37 -0
- package/dist/lib/share-definitions.d.ts +86 -0
- package/dist/lib/share-definitions.js +106 -0
- package/dist/lib/stub.js +0 -7
- package/dist/lib/telemetry-setup.d.ts +66 -0
- package/dist/lib/telemetry-setup.js +92 -0
- package/dist/lib/telemetry.d.ts +100 -0
- package/dist/lib/telemetry.js +89 -0
- package/dist/lib/ui.d.ts +33 -1
- package/dist/lib/ui.js +32 -21
- package/oclif.manifest.json +133 -113
- package/package.json +16 -8
- package/dist/commands/move-stage.d.ts +0 -52
- package/dist/commands/move-stage.js +0 -86
- package/dist/lib/config.d.ts +0 -18
- package/dist/lib/config.js +0 -50
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { styleText } from 'node:util';
|
|
2
|
-
import { Args, Command, Flags } from '@oclif/core';
|
|
3
|
-
import { workflow } from '@sanity/workflow-engine';
|
|
4
|
-
import ora from 'ora';
|
|
5
|
-
import { loadClient } from "../lib/client.js";
|
|
6
|
-
import { loadWorkflowConfig } from "../lib/config.js";
|
|
7
|
-
import { fail } from "../lib/fail.js";
|
|
8
|
-
import { tagFlags } from "../lib/flags.js";
|
|
9
|
-
import { buildOperationArgs } from "../lib/operation-args.js";
|
|
10
|
-
import { emitWriteReport, opsAppliedLines } from "../lib/ops-report.js";
|
|
11
|
-
export default class MoveStage extends Command {
|
|
12
|
-
static description = 'Move an instance to a new stage. Guards + transition effects run as if the transition fired normally.';
|
|
13
|
-
static examples = [
|
|
14
|
-
'<%= config.bin %> move-stage wf-instance.abc123 --to ready',
|
|
15
|
-
"<%= config.bin %> move-stage wf-instance.abc123 --to ready --reason 'unblock for demo'",
|
|
16
|
-
];
|
|
17
|
-
static args = {
|
|
18
|
-
instanceId: Args.string({
|
|
19
|
-
required: true,
|
|
20
|
-
description: 'Workflow instance id to move.',
|
|
21
|
-
}),
|
|
22
|
-
};
|
|
23
|
-
static flags = {
|
|
24
|
-
...tagFlags,
|
|
25
|
-
to: Flags.string({
|
|
26
|
-
required: true,
|
|
27
|
-
description: 'Target stage name.',
|
|
28
|
-
}),
|
|
29
|
-
reason: Flags.string({
|
|
30
|
-
description: 'Free-text reason — recorded on the history entry for audit.',
|
|
31
|
-
}),
|
|
32
|
-
};
|
|
33
|
-
async run() {
|
|
34
|
-
const { args, flags } = await this.parse(MoveStage);
|
|
35
|
-
const config = loadWorkflowConfig(flags.tag);
|
|
36
|
-
const client = loadClient();
|
|
37
|
-
const spinner = ora(`Moving ${args.instanceId} → ${flags.to}…`).start();
|
|
38
|
-
try {
|
|
39
|
-
const result = await workflow.setStage({
|
|
40
|
-
client,
|
|
41
|
-
...buildSetStageArgs({
|
|
42
|
-
config,
|
|
43
|
-
instanceId: args.instanceId,
|
|
44
|
-
targetStage: flags.to,
|
|
45
|
-
reason: flags.reason,
|
|
46
|
-
}),
|
|
47
|
-
});
|
|
48
|
-
emitWriteReport({
|
|
49
|
-
spinner,
|
|
50
|
-
report: moveStageReport(result, flags.to),
|
|
51
|
-
log: (line) => this.log(line),
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
spinner.fail('Move rejected');
|
|
56
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
57
|
-
fail('setStage error:', message);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/** The shared operation args ({@link buildOperationArgs}) plus the
|
|
62
|
-
* setStage-specific target. */
|
|
63
|
-
export function buildSetStageArgs({ config, instanceId, targetStage, reason, }) {
|
|
64
|
-
return { ...buildOperationArgs({ config, instanceId, reason }), targetStage };
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Turn a `setStage` result into the spinner message + ops block. Pure so
|
|
68
|
-
* the fired / not-fired / cascaded / ops permutations can be asserted
|
|
69
|
-
* without driving a real transition.
|
|
70
|
-
*/
|
|
71
|
-
export function moveStageReport(result, to) {
|
|
72
|
-
const stage = styleText('bold', result.instance.currentStage);
|
|
73
|
-
if (!result.fired) {
|
|
74
|
-
return {
|
|
75
|
-
fired: false,
|
|
76
|
-
message: `setStage returned without firing — instance is already at ${stage}`,
|
|
77
|
-
opsLines: [],
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
const tail = result.cascaded > 0 ? `, then cascaded ${result.cascaded} auto-transition(s)` : '';
|
|
81
|
-
return {
|
|
82
|
-
fired: true,
|
|
83
|
-
message: `Now at ${stage} (was → ${to}${tail})`,
|
|
84
|
-
opsLines: opsAppliedLines(result.ranOps),
|
|
85
|
-
};
|
|
86
|
-
}
|
package/dist/lib/config.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { WorkflowResource } from '@sanity/workflow-engine';
|
|
2
|
-
export interface WorkflowConfig {
|
|
3
|
-
workflowResource: WorkflowResource;
|
|
4
|
-
tag: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* {@link readWorkflowConfig} but funnel a thrown env-validation error
|
|
8
|
-
* through the standard {@link fail} path so commands don't each have to wrap.
|
|
9
|
-
*/
|
|
10
|
-
export declare function loadWorkflowConfig(tagOverride?: string): WorkflowConfig;
|
|
11
|
-
/**
|
|
12
|
-
* Resolve the `deploy` command's definitions source — a module specifier
|
|
13
|
-
* (a path like `./src/workflows.ts`, or a package name) whose
|
|
14
|
-
* `allDefinitions` export holds the batch to deploy. Required and with no
|
|
15
|
-
* default: the CLI is agnostic about *which* definitions it ships, so an
|
|
16
|
-
* unset source is an error rather than a silent fall back to a built-in set.
|
|
17
|
-
*/
|
|
18
|
-
export declare function loadDefinitionsSource(): string;
|
package/dist/lib/config.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { ENV } from "./env.js";
|
|
2
|
-
import { fail, failOnThrow } from "./fail.js";
|
|
3
|
-
const VALID_RESOURCE_TYPES = ['dataset', 'canvas', 'media-library', 'dashboard'];
|
|
4
|
-
function isResourceType(value) {
|
|
5
|
-
return VALID_RESOURCE_TYPES.includes(value);
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Resolve the engine's `workflowResource` + tag from env vars (and an
|
|
9
|
-
* optional `tagOverride`, e.g. the `--tag` flag).
|
|
10
|
-
*
|
|
11
|
-
* - `WORKFLOW_RESOURCE_TYPE` — one of "dataset" / "canvas" / "media-library" /
|
|
12
|
-
* "dashboard". Defaults to "dataset".
|
|
13
|
-
* - `WORKFLOW_RESOURCE_ID` — the resource id (e.g. "test.test" for a
|
|
14
|
-
* dataset). Defaults to "test.test".
|
|
15
|
-
* - `WORKFLOW_TAG` — the single environment tag (e.g. "prod"). Required;
|
|
16
|
-
* `tagOverride` takes precedence when supplied.
|
|
17
|
-
*/
|
|
18
|
-
function readWorkflowConfig(tagOverride) {
|
|
19
|
-
const rawType = process.env[ENV.WORKFLOW_RESOURCE_TYPE] ?? 'dataset';
|
|
20
|
-
if (!isResourceType(rawType)) {
|
|
21
|
-
throw new Error(`WORKFLOW_RESOURCE_TYPE must be one of: ${VALID_RESOURCE_TYPES.join(', ')} (got "${rawType}")`);
|
|
22
|
-
}
|
|
23
|
-
const id = process.env[ENV.WORKFLOW_RESOURCE_ID] ?? 'test.test';
|
|
24
|
-
const tag = (tagOverride ?? process.env[ENV.WORKFLOW_TAG] ?? '').trim();
|
|
25
|
-
if (!tag) {
|
|
26
|
-
throw new Error('Workflow tag is required - pass --tag or set WORKFLOW_TAG (e.g. prod)');
|
|
27
|
-
}
|
|
28
|
-
return { workflowResource: { type: rawType, id }, tag };
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* {@link readWorkflowConfig} but funnel a thrown env-validation error
|
|
32
|
-
* through the standard {@link fail} path so commands don't each have to wrap.
|
|
33
|
-
*/
|
|
34
|
-
export function loadWorkflowConfig(tagOverride) {
|
|
35
|
-
return failOnThrow('Invalid workflow config:', () => readWorkflowConfig(tagOverride));
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Resolve the `deploy` command's definitions source — a module specifier
|
|
39
|
-
* (a path like `./src/workflows.ts`, or a package name) whose
|
|
40
|
-
* `allDefinitions` export holds the batch to deploy. Required and with no
|
|
41
|
-
* default: the CLI is agnostic about *which* definitions it ships, so an
|
|
42
|
-
* unset source is an error rather than a silent fall back to a built-in set.
|
|
43
|
-
*/
|
|
44
|
-
export function loadDefinitionsSource() {
|
|
45
|
-
const source = process.env[ENV.WORKFLOW_DEFS]?.trim();
|
|
46
|
-
if (source === undefined || source === '') {
|
|
47
|
-
fail('No definitions source configured.', 'Set WORKFLOW_DEFS to a module that exports `allDefinitions` — a path like ./src/workflows.ts, or a package name.');
|
|
48
|
-
}
|
|
49
|
-
return source;
|
|
50
|
-
}
|