@sanity/workflows-cli 0.0.0-pr-744-20261109125055
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 +1848 -0
- package/LICENSE +21 -0
- package/README.md +798 -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 +9 -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 +34 -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 +205 -0
- package/dist/lib/blueprint-stacks.d.ts +6 -0
- package/dist/lib/blueprint-stacks.js +88 -0
- package/dist/lib/cause-detail.d.ts +9 -0
- package/dist/lib/cause-detail.js +112 -0
- package/dist/lib/client.d.ts +24 -0
- package/dist/lib/client.js +40 -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 +22 -0
- package/dist/lib/codemod/package-map.js +72 -0
- package/dist/lib/codemod/report.d.ts +5 -0
- package/dist/lib/codemod/report.js +43 -0
- package/dist/lib/codemod/run.d.ts +23 -0
- package/dist/lib/codemod/run.js +103 -0
- package/dist/lib/codemod/source-rewrite.d.ts +18 -0
- package/dist/lib/codemod/source-rewrite.js +155 -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 +268 -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 +11 -0
- package/dist/lib/definition-files.js +58 -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 +29 -0
- package/dist/lib/fail.js +46 -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 +46 -0
- package/dist/lib/load-config.js +110 -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 +47 -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 +78 -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,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render a user-facing error to stderr with no oclif framing or Node stack,
|
|
3
|
+
* and exit non-zero.
|
|
4
|
+
*
|
|
5
|
+
* Exits via oclif's `Errors.exit`, never `process.exit`: a raw `process.exit`
|
|
6
|
+
* would skip the command's `finally` hook, dropping the trace and any
|
|
7
|
+
* batched telemetry that hasn't flushed yet.
|
|
8
|
+
*/
|
|
9
|
+
export declare function fail(headline: string, detail?: string): never;
|
|
10
|
+
export declare function warnOnStderr(message: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Run `fn`, funnelling a thrown env/validation error through {@link fail}
|
|
13
|
+
* so an expected, user-fixable failure (missing input, bad value) reads
|
|
14
|
+
* clean instead of as an oclif stack trace. Keeps the throwing `read*`
|
|
15
|
+
* helpers pure and unit-testable while giving callers one clean boundary.
|
|
16
|
+
*/
|
|
17
|
+
export declare function failOnThrow<T>(headline: string, fn: () => T): T;
|
|
18
|
+
/** An API rejection of the auth token itself — as opposed to a 403, where
|
|
19
|
+
* the identity is valid but lacks the role for the operation. Walks the
|
|
20
|
+
* `cause` chain because the 401 often arrives wrapped: the engine's
|
|
21
|
+
* `/users/me` actor resolution rethrows it inside its own `Error`. */
|
|
22
|
+
export declare function isAuthRejection(err: unknown): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The detail block for a command failure: the error's message, plus the
|
|
25
|
+
* auth recovery hint when the API rejected the token. Every site that
|
|
26
|
+
* renders a caught command error should build its detail here, so the
|
|
27
|
+
* hint reaches the user no matter which call the token died at.
|
|
28
|
+
*/
|
|
29
|
+
export declare function failureDetail(err: unknown): string;
|
package/dist/lib/fail.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
|
+
import { Errors } from '@oclif/core';
|
|
3
|
+
import { ClientError } from '@sanity/client';
|
|
4
|
+
import { errorMessage } from '@sanity/workflows';
|
|
5
|
+
import logSymbols from 'log-symbols';
|
|
6
|
+
import { envAuthToken } from './env.js';
|
|
7
|
+
export function fail(headline, detail) {
|
|
8
|
+
process.stderr.write(`${styleText('red', `${logSymbols.error} ${headline}`)}\n`);
|
|
9
|
+
if (detail !== undefined && detail !== '') {
|
|
10
|
+
for (const line of detail.split('\n')) {
|
|
11
|
+
process.stderr.write(` ${line}\n`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return Errors.exit(1);
|
|
15
|
+
}
|
|
16
|
+
export function warnOnStderr(message) {
|
|
17
|
+
process.stderr.write(`${styleText('yellow', `${logSymbols.warning} ${message}`)}\n`);
|
|
18
|
+
}
|
|
19
|
+
export function failOnThrow(headline, fn) {
|
|
20
|
+
try {
|
|
21
|
+
return fn();
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
fail(headline, errorMessage(err));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function isAuthRejection(err) {
|
|
28
|
+
let current = err;
|
|
29
|
+
for (let depth = 0; depth < 5 && current !== undefined; depth++) {
|
|
30
|
+
if (current instanceof ClientError && current.statusCode === 401) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
current = current instanceof Error ? current.cause : undefined;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
function authRecoveryHint() {
|
|
38
|
+
if (envAuthToken() !== undefined) {
|
|
39
|
+
return 'The SANITY_AUTH_TOKEN token was rejected — check it is valid and has access to this project.';
|
|
40
|
+
}
|
|
41
|
+
return 'Your `sanity login` session may have expired — run `sanity login` and retry.';
|
|
42
|
+
}
|
|
43
|
+
export function failureDetail(err) {
|
|
44
|
+
const message = errorMessage(err);
|
|
45
|
+
return isAuthRejection(err) ? `${message}\n${authRecoveryHint()}` : message;
|
|
46
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export declare function flagTokens(argv: string[]): string[];
|
|
2
|
+
export declare function isLongFlag(token: string, name: string): boolean;
|
|
3
|
+
/** The last value of a flag read straight off argv, by its long name or its
|
|
4
|
+
* `char` short form, for code that runs before oclif parses flags. */
|
|
5
|
+
export declare function rawFlagValue(argv: string[], flag: {
|
|
6
|
+
name: string;
|
|
7
|
+
char?: string | undefined;
|
|
8
|
+
}): string | undefined;
|
|
9
|
+
export declare function partitionFlag(options: {
|
|
10
|
+
description: string;
|
|
11
|
+
exclusive?: string[];
|
|
12
|
+
}): import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
/** For every command that reads `sanity.workflow.ts`. */
|
|
14
|
+
export declare const configFlags: {
|
|
15
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
};
|
|
17
|
+
/** Name one resource for a read command to inspect, the way the Sanity CLI's
|
|
18
|
+
* `--project-id` / `--dataset` and `--media-library-id` name one. Write commands
|
|
19
|
+
* never spread these: they act through a deployment from `sanity.workflow.ts`. */
|
|
20
|
+
export declare const resourceFlags: {
|
|
21
|
+
'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
22
|
+
dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
23
|
+
'media-library-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
24
|
+
};
|
|
25
|
+
/** Selectors for commands that list or show what is deployed. */
|
|
26
|
+
export declare const readFlags: {
|
|
27
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
28
|
+
deployment: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
29
|
+
partition: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
30
|
+
};
|
|
31
|
+
export declare const instanceFlags: {
|
|
32
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
33
|
+
deployment: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
34
|
+
partition: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
35
|
+
};
|
|
36
|
+
/** Deploy overrides the partition flag to select every matching deployment. */
|
|
37
|
+
export declare const deploymentFlags: {
|
|
38
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
39
|
+
deployment: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
40
|
+
partition: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
41
|
+
};
|
|
42
|
+
/** Structured stdout instead of the rendered view. One payload convention:
|
|
43
|
+
* verb commands emit their operation envelope (`instanceId` carries the doc
|
|
44
|
+
* `_id`); read commands emit document-shaped data — `show` commands print
|
|
45
|
+
* the fetched document as stored, list commands print the table's row view
|
|
46
|
+
* (plus each row's `resource`) under a `truncated` flag. */
|
|
47
|
+
export declare const jsonFlags: {
|
|
48
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
49
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
const instancePartitionDescription = "Workflow environment partition (e.g. prod, test) — narrows which resources are searched for the instance; the instance's stored partition is what the command uses.";
|
|
3
|
+
const partitionAsFilterDescription = 'Workflow environment partition (e.g. prod, test) — an optional query filter that also narrows which resources are searched; omit to span them all.';
|
|
4
|
+
export function flagTokens(argv) {
|
|
5
|
+
const terminator = argv.indexOf('--');
|
|
6
|
+
return terminator === -1 ? argv : argv.slice(0, terminator);
|
|
7
|
+
}
|
|
8
|
+
export function isLongFlag(token, name) {
|
|
9
|
+
return token === `--${name}` || token.startsWith(`--${name}=`);
|
|
10
|
+
}
|
|
11
|
+
function isShortFlag(token, char) {
|
|
12
|
+
return char !== undefined && token.startsWith(`-${char}`) && !token.startsWith('--');
|
|
13
|
+
}
|
|
14
|
+
function inlineValue(token, name) {
|
|
15
|
+
if (token.startsWith(`--${name}=`)) {
|
|
16
|
+
return token.slice(`--${name}=`.length);
|
|
17
|
+
}
|
|
18
|
+
if (token.startsWith('--') || token.length < 3) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return token.slice(token[2] === '=' ? 3 : 2);
|
|
22
|
+
}
|
|
23
|
+
export function rawFlagValue(argv, flag) {
|
|
24
|
+
const tokens = flagTokens(argv);
|
|
25
|
+
const index = tokens.findLastIndex((token) => isLongFlag(token, flag.name) || isShortFlag(token, flag.char));
|
|
26
|
+
const token = tokens[index];
|
|
27
|
+
if (token === undefined) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return inlineValue(token, flag.name) ?? tokens[index + 1];
|
|
31
|
+
}
|
|
32
|
+
export function partitionFlag(options) {
|
|
33
|
+
return Flags.string({ aliases: ['tag'], ...options });
|
|
34
|
+
}
|
|
35
|
+
export const configFlags = {
|
|
36
|
+
path: Flags.string({
|
|
37
|
+
description: 'Path to a sanity.workflow file, or a directory to search from upward through its parents. Defaults to the current directory.',
|
|
38
|
+
helpValue: '<file|dir>',
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
const OVERRIDES_CONFIG = ' (overrides sanity.workflow.ts)';
|
|
42
|
+
const CONFIG_SELECTORS = ['path', 'deployment'];
|
|
43
|
+
function nonEmpty(name) {
|
|
44
|
+
return async (input) => {
|
|
45
|
+
const trimmed = input.trim();
|
|
46
|
+
if (trimmed === '') {
|
|
47
|
+
throw new Error(`\`--${name}\` cannot be empty if provided`);
|
|
48
|
+
}
|
|
49
|
+
return trimmed;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export const resourceFlags = {
|
|
53
|
+
'project-id': Flags.string({
|
|
54
|
+
char: 'p',
|
|
55
|
+
description: `Project ID of the dataset to read${OVERRIDES_CONFIG}`,
|
|
56
|
+
helpGroup: 'OVERRIDE',
|
|
57
|
+
helpValue: '<id>',
|
|
58
|
+
dependsOn: ['dataset'],
|
|
59
|
+
exclusive: ['media-library-id', ...CONFIG_SELECTORS],
|
|
60
|
+
parse: nonEmpty('project-id'),
|
|
61
|
+
}),
|
|
62
|
+
dataset: Flags.string({
|
|
63
|
+
char: 'd',
|
|
64
|
+
description: `Dataset to read${OVERRIDES_CONFIG}`,
|
|
65
|
+
helpGroup: 'OVERRIDE',
|
|
66
|
+
helpValue: '<name>',
|
|
67
|
+
dependsOn: ['project-id'],
|
|
68
|
+
exclusive: ['media-library-id', ...CONFIG_SELECTORS],
|
|
69
|
+
parse: nonEmpty('dataset'),
|
|
70
|
+
}),
|
|
71
|
+
'media-library-id': Flags.string({
|
|
72
|
+
description: `Media library to read${OVERRIDES_CONFIG}`,
|
|
73
|
+
helpGroup: 'OVERRIDE',
|
|
74
|
+
helpValue: '<id>',
|
|
75
|
+
exclusive: ['project-id', 'dataset', ...CONFIG_SELECTORS],
|
|
76
|
+
parse: nonEmpty('media-library-id'),
|
|
77
|
+
}),
|
|
78
|
+
};
|
|
79
|
+
export const readFlags = {
|
|
80
|
+
...configFlags,
|
|
81
|
+
deployment: Flags.string({
|
|
82
|
+
description: 'Deployment name — read only the resource and partition that deployment targets.',
|
|
83
|
+
exclusive: ['partition'],
|
|
84
|
+
}),
|
|
85
|
+
partition: partitionFlag({
|
|
86
|
+
description: partitionAsFilterDescription,
|
|
87
|
+
exclusive: ['deployment'],
|
|
88
|
+
}),
|
|
89
|
+
};
|
|
90
|
+
export const instanceFlags = {
|
|
91
|
+
...configFlags,
|
|
92
|
+
deployment: Flags.string({
|
|
93
|
+
description: 'Deployment name — narrow the instance search to the resource that deployment targets; the partition still comes from the loaded instance.',
|
|
94
|
+
exclusive: ['partition'],
|
|
95
|
+
}),
|
|
96
|
+
partition: partitionFlag({
|
|
97
|
+
description: instancePartitionDescription,
|
|
98
|
+
exclusive: ['deployment'],
|
|
99
|
+
}),
|
|
100
|
+
};
|
|
101
|
+
export const deploymentFlags = {
|
|
102
|
+
...configFlags,
|
|
103
|
+
deployment: Flags.string({
|
|
104
|
+
description: 'Deployment name — the unique identity of one deployment in the config.',
|
|
105
|
+
exclusive: ['partition'],
|
|
106
|
+
}),
|
|
107
|
+
partition: partitionFlag({
|
|
108
|
+
description: 'Workflow environment partition (e.g. prod, test) — selects the deployment to act on while the partition names exactly one; pass --deployment when it spans several.',
|
|
109
|
+
exclusive: ['deployment'],
|
|
110
|
+
}),
|
|
111
|
+
};
|
|
112
|
+
export const jsonFlags = {
|
|
113
|
+
json: Flags.boolean({
|
|
114
|
+
description: 'Emit structured JSON instead of rendered output.',
|
|
115
|
+
default: false,
|
|
116
|
+
}),
|
|
117
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The deployment selection a run was given, repeated on every command it suggests. */
|
|
2
|
+
export interface CommandSelection {
|
|
3
|
+
deployment?: string | undefined;
|
|
4
|
+
partition?: string | undefined;
|
|
5
|
+
allPartitions?: boolean | undefined;
|
|
6
|
+
}
|
|
7
|
+
/** What a suggested command needs from the current run. */
|
|
8
|
+
export interface FollowUpContext {
|
|
9
|
+
/** `this.config.bin`: the standalone binary, or the host CLI mounting it. */
|
|
10
|
+
bin: string;
|
|
11
|
+
selection?: CommandSelection;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A complete command line to suggest to the user: the binary that is running,
|
|
15
|
+
* the `workflows` topic when mounted in a host CLI, `words`, then the selection
|
|
16
|
+
* flags of the current run.
|
|
17
|
+
*/
|
|
18
|
+
export declare function followUpCommand({ bin, selection }: FollowUpContext, ...words: string[]): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { STANDALONE_BIN, WORKFLOWS_TOPIC } from '../command-ids.js';
|
|
2
|
+
export function followUpCommand({ bin, selection = {} }, ...words) {
|
|
3
|
+
const prefix = bin === STANDALONE_BIN ? [bin] : [bin, WORKFLOWS_TOPIC];
|
|
4
|
+
return [...prefix, ...words, ...selectionFlags(selection)].join(' ');
|
|
5
|
+
}
|
|
6
|
+
function selectionFlags({ deployment, partition, allPartitions }) {
|
|
7
|
+
return [
|
|
8
|
+
...(deployment === undefined ? [] : ['--deployment', deployment]),
|
|
9
|
+
...(partition === undefined ? [] : ['--partition', partition]),
|
|
10
|
+
...(allPartitions === true ? ['--all-partitions'] : []),
|
|
11
|
+
];
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { displayTitle } from '@sanity/workflows';
|
|
2
|
+
function withNotes(text, ...notes) {
|
|
3
|
+
const present = notes.filter((note) => note !== undefined);
|
|
4
|
+
return present.length === 0 ? text : `${text} (${present.join(': ')})`;
|
|
5
|
+
}
|
|
6
|
+
function withMoveNotes(text, { via, reason }) {
|
|
7
|
+
return withNotes(text, via === 'setStage' ? 'forced' : undefined, reason);
|
|
8
|
+
}
|
|
9
|
+
function transitionName(move) {
|
|
10
|
+
return move.via === 'setStage' || move.transition === undefined ? '' : `${move.transition}, `;
|
|
11
|
+
}
|
|
12
|
+
const detailOf = {
|
|
13
|
+
stageEntered: (entry) => withMoveNotes(entry.stage, entry),
|
|
14
|
+
stageExited: (entry) => entry.stage,
|
|
15
|
+
activityStatusChanged: (entry) => `${entry.activity} ${entry.from} → ${entry.to}`,
|
|
16
|
+
actionFired: (entry) => withNotes(`${entry.activity} → ${entry.action}`, entry.triggered ? 'triggered' : undefined),
|
|
17
|
+
transitionFired: (entry) => withMoveNotes(`${transitionName(entry)}${entry.fromStage} → ${entry.toStage}`, entry),
|
|
18
|
+
effectQueued: (entry) => entry.effect,
|
|
19
|
+
effectCompleted: (entry) => withNotes(entry.effect, entry.status, entry.detail),
|
|
20
|
+
effectClaimReleased: (entry) => entry.effect,
|
|
21
|
+
spawned: (entry) => `${entry.activity} → ${entry.instanceRef.id}`,
|
|
22
|
+
subworkflowAdopted: (entry) => `${entry.activity} → ${entry.instanceRef.id}`,
|
|
23
|
+
subworkflowResolved: (entry) => withNotes(entry.activity, entry.status),
|
|
24
|
+
subworkflowOrphaned: (entry) => entry.instanceRef.id,
|
|
25
|
+
aborted: (entry) => entry.reason,
|
|
26
|
+
opApplied: (entry) => {
|
|
27
|
+
const subject = entry.target?.field ?? entry.activity;
|
|
28
|
+
return subject === undefined ? entry.opType : `${entry.opType} ${subject}`;
|
|
29
|
+
},
|
|
30
|
+
fieldQueryDiscarded: (entry) => entry.field,
|
|
31
|
+
};
|
|
32
|
+
function actorOf(entry) {
|
|
33
|
+
if (entry._type === 'actionFired' && entry.triggered) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return 'actor' in entry ? entry.actor : undefined;
|
|
37
|
+
}
|
|
38
|
+
export function historyRow(entry) {
|
|
39
|
+
const detail = detailOf[entry._type](entry);
|
|
40
|
+
const actor = actorOf(entry);
|
|
41
|
+
const title = displayTitle(entry._type);
|
|
42
|
+
const described = detail === undefined ? title : `${title}: ${detail}`;
|
|
43
|
+
return actor === undefined ? described : `${described} (by ${actor.id})`;
|
|
44
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type WorkflowConfig } from '@sanity/workflows';
|
|
2
|
+
/**
|
|
3
|
+
* The validated config a `sanity.workflow` module exports, and the names that
|
|
4
|
+
* module exports it alongside.
|
|
5
|
+
*/
|
|
6
|
+
export interface LoadedWorkflowConfig {
|
|
7
|
+
config: WorkflowConfig;
|
|
8
|
+
/** The discovered file's name, so a diagnostic names the file the user
|
|
9
|
+
* actually has among the supported config filenames. */
|
|
10
|
+
configFile: string;
|
|
11
|
+
/** Every name the module exports, `default` included. `blueprints generate`
|
|
12
|
+
* reads it because each generated module imports its deployment as a named
|
|
13
|
+
* export from this file. */
|
|
14
|
+
exportedNames: readonly string[];
|
|
15
|
+
/** The config file's directory. Generated Blueprint files are written here,
|
|
16
|
+
* not to the working directory the search started from. */
|
|
17
|
+
root: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Find the `sanity.workflow.{ts,js,mjs}` config, import its default export,
|
|
21
|
+
* and validate it through {@link defineWorkflowConfig}. `path` is a config
|
|
22
|
+
* file, or a directory to search from and then upward through its parents.
|
|
23
|
+
* Any problem — no file, unloadable module, invalid config — exits through
|
|
24
|
+
* the clean `fail` path.
|
|
25
|
+
*/
|
|
26
|
+
export declare function loadWorkflowConfig(path?: string): Promise<WorkflowConfig>;
|
|
27
|
+
/**
|
|
28
|
+
* {@link loadWorkflowConfig} plus the module's exported names and directory,
|
|
29
|
+
* for a caller that writes beside the config or checks one of its exports.
|
|
30
|
+
* Takes the same clean `fail` path on every problem.
|
|
31
|
+
*/
|
|
32
|
+
export declare function loadWorkflowConfigModule(path?: string): Promise<LoadedWorkflowConfig>;
|
|
33
|
+
/**
|
|
34
|
+
* {@link loadWorkflowConfig}, or `undefined` when no config file is found, for
|
|
35
|
+
* a read that can target a resource without one. Every other problem takes
|
|
36
|
+
* the same clean `fail` path.
|
|
37
|
+
*/
|
|
38
|
+
export declare function loadWorkflowConfigIfFound(path?: string): Promise<WorkflowConfig | undefined>;
|
|
39
|
+
export declare function noConfigFound(path?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* {@link loadWorkflowConfig} for telemetry setup, which must never break (or
|
|
42
|
+
* exit) a command: `undefined` when the file is absent or unusable. A broken
|
|
43
|
+
* config is not swallowed for real — the command's own load reports it through
|
|
44
|
+
* the clean `fail` path; this caller just runs with telemetry off.
|
|
45
|
+
*/
|
|
46
|
+
export declare function loadWorkflowConfigIfPresent(path?: string): Promise<WorkflowConfig | undefined>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { existsSync, statSync } from 'node:fs';
|
|
10
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
11
|
+
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import { errorMessage } from '@sanity/workflows';
|
|
13
|
+
import { CONFIG_FILE_NAMES } from '@sanity/workflows/blueprints';
|
|
14
|
+
import { defineWorkflowConfig } from '@sanity/workflows/define';
|
|
15
|
+
import * as find from 'empathic/find';
|
|
16
|
+
import { createJiti } from 'jiti';
|
|
17
|
+
import { fail, warnOnStderr } from './fail.js';
|
|
18
|
+
class ConfigLoadError extends Error {
|
|
19
|
+
headline;
|
|
20
|
+
detail;
|
|
21
|
+
constructor(headline, detail) {
|
|
22
|
+
super(`${headline} ${detail}`);
|
|
23
|
+
this.headline = headline;
|
|
24
|
+
this.detail = detail;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function findConfigFile(path) {
|
|
28
|
+
if (!existsSync(path)) {
|
|
29
|
+
throw new ConfigLoadError(`Nothing found at ${path}.`, 'Pass --path a config file or an existing directory.');
|
|
30
|
+
}
|
|
31
|
+
const absolute = resolve(path);
|
|
32
|
+
if (statSync(absolute).isFile()) {
|
|
33
|
+
return absolute;
|
|
34
|
+
}
|
|
35
|
+
return find.any([...CONFIG_FILE_NAMES], { cwd: absolute, type: 'file' });
|
|
36
|
+
}
|
|
37
|
+
async function importModule(filePath) {
|
|
38
|
+
const url = pathToFileURL(filePath).href;
|
|
39
|
+
try {
|
|
40
|
+
const loaded = filePath.endsWith('.ts')
|
|
41
|
+
? await createJiti(dirname(filePath)).import(url)
|
|
42
|
+
: await import(__rewriteRelativeImportExtension(url, true));
|
|
43
|
+
return { default: loaded.default, names: Object.keys(loaded) };
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
throw new ConfigLoadError(`Failed to load ${basename(filePath)}:`, errorMessage(err));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const parsedConfigs = new Map();
|
|
50
|
+
function parseConfigFile(filePath) {
|
|
51
|
+
const cached = parsedConfigs.get(filePath);
|
|
52
|
+
if (cached !== undefined) {
|
|
53
|
+
return cached;
|
|
54
|
+
}
|
|
55
|
+
const parsed = importModule(filePath).then((loaded) => {
|
|
56
|
+
let config;
|
|
57
|
+
try {
|
|
58
|
+
config = defineWorkflowConfig(loaded.default);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
throw new ConfigLoadError(`Invalid config in ${basename(filePath)}:`, errorMessage(err));
|
|
62
|
+
}
|
|
63
|
+
config.warnings.forEach(warnOnStderr);
|
|
64
|
+
return {
|
|
65
|
+
config,
|
|
66
|
+
configFile: basename(filePath),
|
|
67
|
+
exportedNames: loaded.names,
|
|
68
|
+
root: dirname(filePath),
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
parsedConfigs.set(filePath, parsed);
|
|
72
|
+
return parsed;
|
|
73
|
+
}
|
|
74
|
+
export async function loadWorkflowConfig(path) {
|
|
75
|
+
return (await loadWorkflowConfigModule(path)).config;
|
|
76
|
+
}
|
|
77
|
+
export async function loadWorkflowConfigModule(path = process.cwd()) {
|
|
78
|
+
return ((await loadIfFound(path)) ??
|
|
79
|
+
fail(noConfigFound(path), 'Create one that `export default defineWorkflowConfig({deployments: [...]})`, or pass --path to point at one.'));
|
|
80
|
+
}
|
|
81
|
+
export async function loadWorkflowConfigIfFound(path = process.cwd()) {
|
|
82
|
+
return (await loadIfFound(path))?.config;
|
|
83
|
+
}
|
|
84
|
+
export function noConfigFound(path = process.cwd()) {
|
|
85
|
+
return `No ${CONFIG_FILE_NAMES[0]} found in ${resolve(path)} or any parent directory.`;
|
|
86
|
+
}
|
|
87
|
+
async function loadIfFound(path) {
|
|
88
|
+
try {
|
|
89
|
+
const filePath = findConfigFile(path);
|
|
90
|
+
return filePath === undefined ? undefined : await parseConfigFile(filePath);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
if (err instanceof ConfigLoadError) {
|
|
94
|
+
fail(err.headline, err.detail);
|
|
95
|
+
}
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export async function loadWorkflowConfigIfPresent(path = process.cwd()) {
|
|
100
|
+
try {
|
|
101
|
+
const filePath = findConfigFile(path);
|
|
102
|
+
return filePath === undefined ? undefined : (await parseConfigFile(filePath)).config;
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
if (err instanceof ConfigLoadError) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { type WorkflowClient, type WorkflowDeployment, type WorkflowResource } from '@sanity/workflows';
|
|
2
|
+
/** A resource a nuke may delete from, with the client that reads/writes it and
|
|
3
|
+
* whether it is the engine's own resource — the only one that holds instances
|
|
4
|
+
* and definitions (guards can co-locate with subjects in any resource). */
|
|
5
|
+
export interface NukeTarget {
|
|
6
|
+
resource: WorkflowResource;
|
|
7
|
+
client: WorkflowClient;
|
|
8
|
+
holdsEngineDocs: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** One resolved resource of a {@link NukePlan}: the ids to delete, by doc type. */
|
|
11
|
+
export interface NukeResourcePlan {
|
|
12
|
+
resource: WorkflowResource;
|
|
13
|
+
/** The `project.dataset` (or `<type>:<id>`) label the plan shows this resource
|
|
14
|
+
* as — and, in tag mode, the one the operator confirms by. */
|
|
15
|
+
label: string;
|
|
16
|
+
client: WorkflowClient;
|
|
17
|
+
holdsEngineDocs: boolean;
|
|
18
|
+
instanceIds: string[];
|
|
19
|
+
definitionIds: string[];
|
|
20
|
+
guardIds: string[];
|
|
21
|
+
}
|
|
22
|
+
/** Which selector resolved a plan. Decides the delete wave order — see
|
|
23
|
+
* {@link WAVE_ORDER} — so it travels with the plan rather than being re-derived. */
|
|
24
|
+
export type NukeMode = 'partition' | 'instance';
|
|
25
|
+
export interface NukePlan {
|
|
26
|
+
partition: string;
|
|
27
|
+
mode: NukeMode;
|
|
28
|
+
resources: NukeResourcePlan[];
|
|
29
|
+
}
|
|
30
|
+
/** Per-doc-type totals across the whole plan, plus the count of resources that
|
|
31
|
+
* actually hold something to delete ({@link involvedTargets}). */
|
|
32
|
+
export interface PlanCounts {
|
|
33
|
+
instances: number;
|
|
34
|
+
definitions: number;
|
|
35
|
+
guards: number;
|
|
36
|
+
datasets: number;
|
|
37
|
+
total: number;
|
|
38
|
+
}
|
|
39
|
+
/** Every resource a deployment's nuke sweeps: its own workflow resource (which
|
|
40
|
+
* holds instances + definitions + guards) plus each alias-bound resource
|
|
41
|
+
* (guards co-locate with the subjects they lock). */
|
|
42
|
+
export declare function sweptResources(deployment: WorkflowDeployment): WorkflowResource[];
|
|
43
|
+
/**
|
|
44
|
+
* Fail before any nuke work when another same-tag deployment sweeps a resource
|
|
45
|
+
* the selected one does. Guard document ids embed only the partition
|
|
46
|
+
* (`temp.system.guard.<tag>.wf-instance.*`), so within a shared resource the
|
|
47
|
+
* sweep cannot tell such deployments' guards apart — nuking one would delete
|
|
48
|
+
* the others' live locks, invisibly to the plan. Config validation already
|
|
49
|
+
* forbids sharing tag + workflow resource, so an overlap can only arrive
|
|
50
|
+
* through alias bindings.
|
|
51
|
+
*/
|
|
52
|
+
export declare function refuseOverlappingNuke(deployments: WorkflowDeployment[], selected: WorkflowDeployment): void;
|
|
53
|
+
/**
|
|
54
|
+
* Resolve what a tag-scoped nuke would delete, per resource — the dry-run plan
|
|
55
|
+
* printed before any deletion. Instances and definitions are read only from the
|
|
56
|
+
* engine's own resource; guards are read from every target, since a guard
|
|
57
|
+
* co-locates with the subject it locks and may live in a foreign dataset.
|
|
58
|
+
*
|
|
59
|
+
* Every read uses the raw perspective, so a draft-form or otherwise
|
|
60
|
+
* perspective-hidden copy is still surfaced (and swept).
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveNukePlan(args: {
|
|
63
|
+
partition: string;
|
|
64
|
+
targets: NukeTarget[];
|
|
65
|
+
}): Promise<NukePlan>;
|
|
66
|
+
/** An instance a caller has already located: its id plus the resource whose
|
|
67
|
+
* document the locate actually read. The plan derives its instance row from
|
|
68
|
+
* that resource rather than assuming the engine one holds it, so a plan can
|
|
69
|
+
* only ever claim an instance the caller really found. */
|
|
70
|
+
export interface LocatedInstance {
|
|
71
|
+
id: string;
|
|
72
|
+
resource: WorkflowResource;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Resolve what deleting ONE located instance sweeps, per resource — the
|
|
76
|
+
* single-instance sibling of {@link resolveNukePlan}. The instance document is
|
|
77
|
+
* deleted from the resource that held it; its guards are read from every target,
|
|
78
|
+
* since a guard co-locates with the subject it locks and may live in an
|
|
79
|
+
* alias-bound dataset. Definitions are never in scope. Raw perspective, like the
|
|
80
|
+
* tag-scoped plan.
|
|
81
|
+
*/
|
|
82
|
+
export declare function resolveInstanceNukePlan(args: {
|
|
83
|
+
instance: LocatedInstance;
|
|
84
|
+
partition: string;
|
|
85
|
+
targets: NukeTarget[];
|
|
86
|
+
}): Promise<NukePlan>;
|
|
87
|
+
/** The `project.dataset` labels of resources the plan actually deletes from. A
|
|
88
|
+
* resource with nothing to delete is not "involved" and is omitted. Tag mode
|
|
89
|
+
* makes the operator type this set back; instance mode confirms with a plain
|
|
90
|
+
* y/N and consumes it only for the dataset count in its summary. */
|
|
91
|
+
export declare function involvedTargets(plan: NukePlan): string[];
|
|
92
|
+
/** Roll the plan up into per-doc-type totals for the summary and the
|
|
93
|
+
* nothing-to-do short-circuit. */
|
|
94
|
+
export declare function planCounts(plan: NukePlan): PlanCounts;
|
|
95
|
+
/**
|
|
96
|
+
* Does the operator's typed confirmation name every involved target, and only
|
|
97
|
+
* those? Order-independent, whitespace-tolerant set equality: the operator
|
|
98
|
+
* pastes back all `project.dataset` targets the plan listed.
|
|
99
|
+
*/
|
|
100
|
+
export declare function confirmationMatches(input: string, targets: string[]): boolean;
|
|
101
|
+
/** The dry-run plan as printable lines: a heading, the content-safety
|
|
102
|
+
* invariant, the API host the deletes will hit (plan rows alone can't tell
|
|
103
|
+
* same-named projects on different environments apart), and a per-resource,
|
|
104
|
+
* per-doc-type count table. A guard-only foreign resource shows `—` for the
|
|
105
|
+
* engine-only columns, since those docs can't live there. */
|
|
106
|
+
export declare function renderNukePlan(plan: NukePlan, { apiHost, heading }: {
|
|
107
|
+
apiHost: string;
|
|
108
|
+
heading?: string;
|
|
109
|
+
}): string[];
|
|
110
|
+
/** The line printed before a partition delete is confirmed or forced. */
|
|
111
|
+
export declare function formatNukePreview(partition: string, counts: PlanCounts): string;
|
|
112
|
+
/** The success line for a partition delete. */
|
|
113
|
+
export declare function formatNukeSummary(partition: string, counts: PlanCounts): string;
|
|
114
|
+
/** The success line for a single-instance delete; guards are named only when some were deleted. */
|
|
115
|
+
export declare function formatInstanceNukeSummary(instanceId: string, counts: Pick<PlanCounts, 'guards'>): string;
|
|
116
|
+
/**
|
|
117
|
+
* Delete exactly what the plan printed, in uniform waves over every resource,
|
|
118
|
+
* ordered by the plan's mode ({@link WAVE_ORDER}). Non-engine resources simply
|
|
119
|
+
* carry empty instance/definition lists. Idempotent: an empty plan deletes
|
|
120
|
+
* nothing.
|
|
121
|
+
*/
|
|
122
|
+
export declare function executeNuke(plan: NukePlan): Promise<void>;
|
|
123
|
+
/** The `definitions:` line under the plan table; undefined when there are no definitions. */
|
|
124
|
+
export declare function definitionNamesLine(definitionIds: string[]): string | undefined;
|