@sanity/workflows-cli 0.0.0-stage → 0.39.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 +1981 -0
- package/LICENSE +21 -0
- package/README.md +848 -2
- 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 +52 -0
- package/dist/commands/workflows/definitions/list.js +139 -0
- package/dist/commands/workflows/definitions/show.d.ts +66 -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 +53 -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 +79 -0
- package/dist/commands/workflows/list.js +249 -0
- package/dist/commands/workflows/nuke.d.ts +73 -0
- package/dist/commands/workflows/nuke.js +175 -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 +30 -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 +24 -0
- package/dist/commands/workflows/tail.js +83 -0
- package/dist/commands/workflows/whoami.d.ts +16 -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 +33 -0
- package/dist/hooks/prerun/telemetry.js +52 -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 +284 -0
- package/dist/lib/blueprint-stacks.d.ts +6 -0
- package/dist/lib/blueprint-stacks.js +118 -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 +19 -0
- package/dist/lib/codemod/export-rename.js +337 -0
- package/dist/lib/codemod/manifest-rewrite.d.ts +17 -0
- package/dist/lib/codemod/manifest-rewrite.js +133 -0
- package/dist/lib/codemod/package-map.d.ts +27 -0
- package/dist/lib/codemod/package-map.js +99 -0
- package/dist/lib/codemod/report.d.ts +4 -0
- package/dist/lib/codemod/report.js +51 -0
- package/dist/lib/codemod/run.d.ts +25 -0
- package/dist/lib/codemod/run.js +108 -0
- package/dist/lib/codemod/source-rewrite.d.ts +20 -0
- package/dist/lib/codemod/source-rewrite.js +150 -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 +151 -0
- package/dist/lib/context.js +263 -0
- package/dist/lib/default-partition.d.ts +23 -0
- package/dist/lib/default-partition.js +47 -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 +53 -0
- package/dist/lib/flags.js +127 -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-resource.d.ts +13 -0
- package/dist/lib/pick-resource.js +82 -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 +45 -0
- package/dist/lib/resource-target.d.ts +10 -0
- package/dist/lib/resource-target.js +12 -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 +77 -0
- package/dist/lib/telemetry-setup.js +117 -0
- package/dist/lib/telemetry.d.ts +81 -0
- package/dist/lib/telemetry.js +90 -0
- package/dist/lib/ui.d.ts +88 -0
- package/dist/lib/ui.js +114 -0
- package/dist/standalone-argv.d.ts +14 -0
- package/dist/standalone-argv.js +57 -0
- package/oclif.manifest.json +1894 -0
- package/package.json +118 -3
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type WorkflowResource } from '@sanity/workflows';
|
|
2
|
+
import type { ReadTarget } from './context.ts';
|
|
3
|
+
/** A read target whose query threw — noted in place and reflected in the
|
|
4
|
+
* command's exit code. */
|
|
5
|
+
export interface ReadFailure {
|
|
6
|
+
resource: WorkflowResource;
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The `--json` tail of a list command — the structured counterpart of
|
|
11
|
+
* {@link runReadAcrossTargets} + the clipped table: fetch every target's
|
|
12
|
+
* rows, {@link clipToLimit} each target's page, map rows through the
|
|
13
|
+
* command's row view (`toRow`, the structured analogue of the table's
|
|
14
|
+
* `toCells`), annotate each with the resource it came from (the analogue of
|
|
15
|
+
* the banner), and log one `{<key>: rows, truncated}` payload.
|
|
16
|
+
* All-or-nothing, unlike the human path's per-resource tolerance: a script
|
|
17
|
+
* would mistake a listing that silently omitted an unreadable resource for
|
|
18
|
+
* the complete result, so any failure rejects the whole read.
|
|
19
|
+
*/
|
|
20
|
+
export declare function logJsonListing<T, R>({ targets, fetch, toRow, key, limit, log, }: {
|
|
21
|
+
targets: ReadTarget[];
|
|
22
|
+
fetch: (target: ReadTarget) => Promise<{
|
|
23
|
+
rows: T[];
|
|
24
|
+
hasMore: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
toRow: (row: T) => R;
|
|
27
|
+
/** The payload's row key — names what the rows are (`instances`, `definitions`). */
|
|
28
|
+
key: string;
|
|
29
|
+
limit: number;
|
|
30
|
+
log: (line: string) => void;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Run a read over every target, grouping output per resource: a banner when
|
|
34
|
+
* the read spans several, then whatever `run` logs for that target. A throw
|
|
35
|
+
* from one target is noted under its banner and the rest still render — a
|
|
36
|
+
* token that can't read one dataset must not sink the whole listing. A
|
|
37
|
+
* single-target run fails the command instead, naming the resource it read
|
|
38
|
+
* and keeping the error as the cause. Callers exit non-zero when failures
|
|
39
|
+
* come back.
|
|
40
|
+
*/
|
|
41
|
+
export declare function runReadAcrossTargets({ targets, log, run, }: {
|
|
42
|
+
targets: ReadTarget[];
|
|
43
|
+
log: (line: string) => void;
|
|
44
|
+
run: (target: ReadTarget) => Promise<void>;
|
|
45
|
+
}): Promise<ReadFailure[]>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describeResource } from '@sanity/workflows';
|
|
2
|
+
import logSymbols from 'log-symbols';
|
|
3
|
+
import { failOn, failureDetail } from './fail.js';
|
|
4
|
+
import { clipToLimit, groupBanner } from './ui.js';
|
|
5
|
+
export async function logJsonListing({ targets, fetch, toRow, key, limit, log, }) {
|
|
6
|
+
const fetched = await Promise.all(targets.map(async (target) => {
|
|
7
|
+
const { rows, hasMore } = await fetch(target);
|
|
8
|
+
return {
|
|
9
|
+
rows: clipToLimit(rows, limit).rows.map((row) => ({
|
|
10
|
+
...toRow(row),
|
|
11
|
+
resource: target.resource,
|
|
12
|
+
})),
|
|
13
|
+
hasMore: hasMore || rows.length > limit,
|
|
14
|
+
};
|
|
15
|
+
}));
|
|
16
|
+
log(JSON.stringify({
|
|
17
|
+
[key]: fetched.flatMap((result) => result.rows),
|
|
18
|
+
truncated: fetched.some((result) => result.hasMore),
|
|
19
|
+
}, null, 2));
|
|
20
|
+
}
|
|
21
|
+
export async function runReadAcrossTargets({ targets, log, run, }) {
|
|
22
|
+
const failures = [];
|
|
23
|
+
for (const [index, target] of targets.entries()) {
|
|
24
|
+
const banner = groupBanner({
|
|
25
|
+
label: describeResource(target.resource),
|
|
26
|
+
index,
|
|
27
|
+
total: targets.length,
|
|
28
|
+
});
|
|
29
|
+
if (banner !== undefined) {
|
|
30
|
+
log(banner);
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
await run(target);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (targets.length === 1) {
|
|
37
|
+
failOn(error, `Could not read ${describeResource(target.resource)}:`);
|
|
38
|
+
}
|
|
39
|
+
const message = failureDetail(error);
|
|
40
|
+
failures.push({ resource: target.resource, message });
|
|
41
|
+
log(`${logSymbols.error} ${message}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return failures;
|
|
45
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type WorkflowResource } from '@sanity/workflows';
|
|
2
|
+
export interface ResourceTargetFlags {
|
|
3
|
+
'workflow-resource'?: WorkflowResource | undefined;
|
|
4
|
+
'project-id'?: string | undefined;
|
|
5
|
+
dataset?: string | undefined;
|
|
6
|
+
'media-library-id'?: string | undefined;
|
|
7
|
+
}
|
|
8
|
+
/** The one resource the resource flags name, or `undefined` to read the
|
|
9
|
+
* resources `sanity.workflow.ts` declares. */
|
|
10
|
+
export declare function explicitResource(flags: ResourceTargetFlags): WorkflowResource | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parseResourceGdr } from '@sanity/workflows';
|
|
2
|
+
export function explicitResource(flags) {
|
|
3
|
+
if (flags['workflow-resource'] !== undefined)
|
|
4
|
+
return flags['workflow-resource'];
|
|
5
|
+
if (flags['media-library-id'] !== undefined) {
|
|
6
|
+
return parseResourceGdr(`media-library:${flags['media-library-id']}`);
|
|
7
|
+
}
|
|
8
|
+
if (flags['project-id'] !== undefined && flags.dataset !== undefined) {
|
|
9
|
+
return { type: 'dataset', id: `${flags['project-id']}.${flags.dataset}` };
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type AcknowledgedWorkflowDeployment, type DeployTarget, type WorkflowConfig, type WorkflowDefinition, type WorkflowDeployment } from '@sanity/workflows';
|
|
2
|
+
export type ChooseDeploymentName = (deployments: WorkflowDeployment[]) => Promise<string>;
|
|
3
|
+
export interface DeploymentSelectionOptions {
|
|
4
|
+
name: string | undefined;
|
|
5
|
+
partition: string | undefined;
|
|
6
|
+
allPartitions: boolean;
|
|
7
|
+
interactive?: boolean;
|
|
8
|
+
chooseName?: ChooseDeploymentName;
|
|
9
|
+
}
|
|
10
|
+
/** The one identity format for a deployment in output — banners, failure
|
|
11
|
+
* summaries, and "available deployments" listings all render it the same
|
|
12
|
+
* way. */
|
|
13
|
+
export declare function deploymentLabel({ name, partition, }: Pick<WorkflowDeployment, 'name' | 'partition'>): string;
|
|
14
|
+
/** Deployment names are unique across the config; partitions may repeat across resources. */
|
|
15
|
+
export declare function selectDeployment(config: WorkflowConfig, { name, partition, orAlternative, interactive, chooseName, }: {
|
|
16
|
+
name: string | undefined;
|
|
17
|
+
partition: string | undefined;
|
|
18
|
+
orAlternative?: string;
|
|
19
|
+
interactive?: boolean | undefined;
|
|
20
|
+
chooseName?: ChooseDeploymentName | undefined;
|
|
21
|
+
}): Promise<WorkflowDeployment>;
|
|
22
|
+
export declare function deploymentsForPartition(config: WorkflowConfig, partition: string): WorkflowDeployment[];
|
|
23
|
+
export declare function selectDeployments(config: WorkflowConfig, { name, partition, allPartitions, interactive, chooseName }: DeploymentSelectionOptions): Promise<WorkflowDeployment[]>;
|
|
24
|
+
/** The shared acknowledgement boundary for the CLI's definition-submission paths. */
|
|
25
|
+
export declare function acknowledgeDeployment(deployment: WorkflowDeployment, definitions: readonly WorkflowDefinition[]): AcknowledgedWorkflowDeployment;
|
|
26
|
+
/**
|
|
27
|
+
* Project a deployment into the engine's {@link DeployTarget} — the shape the
|
|
28
|
+
* deploy/diff verbs (`deployDefinitions`, `computeDiffEntries`, `diffEntry`)
|
|
29
|
+
* consume — expanding its handle bindings into the alias map in the same step.
|
|
30
|
+
*/
|
|
31
|
+
export declare function deploymentToTarget(deployment: AcknowledgedWorkflowDeployment): DeployTarget;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { assertReaderModelAcknowledgement, requiredDefinitionReaderModel, resourceAliasesToMap, } from '@sanity/workflows';
|
|
2
|
+
import { fail } from './fail.js';
|
|
3
|
+
import { canPromptOnStderr, selectOnStderr } from './prompt.js';
|
|
4
|
+
export function deploymentLabel({ name, partition, }) {
|
|
5
|
+
return `${name} (${partition})`;
|
|
6
|
+
}
|
|
7
|
+
export async function selectDeployment(config, { name, partition, orAlternative = '', interactive, chooseName = chooseDeploymentName, }) {
|
|
8
|
+
if (name !== undefined) {
|
|
9
|
+
const deployment = config.deployments.find((candidate) => candidate.name === name);
|
|
10
|
+
if (deployment === undefined) {
|
|
11
|
+
fail(`No deployment named "${name}".`, availableDeployments(config));
|
|
12
|
+
}
|
|
13
|
+
return deployment;
|
|
14
|
+
}
|
|
15
|
+
if (partition !== undefined) {
|
|
16
|
+
const matches = deploymentsForPartition(config, partition);
|
|
17
|
+
const [sole, ...rest] = matches;
|
|
18
|
+
if (sole === undefined || rest.length > 0) {
|
|
19
|
+
fail(`Multiple deployments in partition "${partition}" — pass --deployment to choose one.`, availableDeployments(config, matches));
|
|
20
|
+
}
|
|
21
|
+
return sole;
|
|
22
|
+
}
|
|
23
|
+
return selectDefaultDeployment(config, { orAlternative, interactive, chooseName });
|
|
24
|
+
}
|
|
25
|
+
async function selectDefaultDeployment(config, { orAlternative, interactive, chooseName, }) {
|
|
26
|
+
if (config.deployments.length > 1) {
|
|
27
|
+
if (interactive ?? canPromptOnStderr()) {
|
|
28
|
+
const selectedName = await chooseName(config.deployments);
|
|
29
|
+
return selectDeployment(config, { name: selectedName, partition: undefined });
|
|
30
|
+
}
|
|
31
|
+
fail(`Multiple deployments configured — pass --deployment or --partition${orAlternative}.`, availableDeployments(config));
|
|
32
|
+
}
|
|
33
|
+
const [sole] = config.deployments;
|
|
34
|
+
if (sole === undefined) {
|
|
35
|
+
fail('No deployments configured.');
|
|
36
|
+
}
|
|
37
|
+
return sole;
|
|
38
|
+
}
|
|
39
|
+
export function deploymentsForPartition(config, partition) {
|
|
40
|
+
const matches = config.deployments.filter((candidate) => candidate.partition === partition);
|
|
41
|
+
if (matches.length === 0) {
|
|
42
|
+
fail(`No deployment for partition "${partition}".`, availableDeployments(config));
|
|
43
|
+
}
|
|
44
|
+
return matches;
|
|
45
|
+
}
|
|
46
|
+
export async function selectDeployments(config, { name, partition, allPartitions, interactive, chooseName }) {
|
|
47
|
+
if (allPartitions) {
|
|
48
|
+
return config.deployments;
|
|
49
|
+
}
|
|
50
|
+
if (partition !== undefined) {
|
|
51
|
+
return deploymentsForPartition(config, partition);
|
|
52
|
+
}
|
|
53
|
+
return [
|
|
54
|
+
await selectDeployment(config, {
|
|
55
|
+
name,
|
|
56
|
+
partition,
|
|
57
|
+
orAlternative: ', or --all-partitions to deploy every deployment',
|
|
58
|
+
interactive,
|
|
59
|
+
chooseName,
|
|
60
|
+
}),
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
async function chooseDeploymentName(deployments) {
|
|
64
|
+
return selectOnStderr({
|
|
65
|
+
message: 'Select a deployment',
|
|
66
|
+
choices: deployments.map(({ name, partition }) => ({
|
|
67
|
+
name,
|
|
68
|
+
value: name,
|
|
69
|
+
description: `partition: ${partition}`,
|
|
70
|
+
})),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function availableDeployments(config, deployments = config.deployments) {
|
|
74
|
+
return `Available deployments: ${deployments.map(deploymentLabel).join(', ')}`;
|
|
75
|
+
}
|
|
76
|
+
export function acknowledgeDeployment(deployment, definitions) {
|
|
77
|
+
const expectedMinReaderModel = deployment.expectedMinReaderModel;
|
|
78
|
+
assertReaderModelAcknowledgement(expectedMinReaderModel, {
|
|
79
|
+
context: `Deployment ${deployment.name}`,
|
|
80
|
+
requiredMinReaderModel: requiredDefinitionReaderModel(definitions),
|
|
81
|
+
});
|
|
82
|
+
return { ...deployment, expectedMinReaderModel };
|
|
83
|
+
}
|
|
84
|
+
export function deploymentToTarget(deployment) {
|
|
85
|
+
return {
|
|
86
|
+
expectedMinReaderModel: deployment.expectedMinReaderModel,
|
|
87
|
+
partition: deployment.partition,
|
|
88
|
+
workflowResource: deployment.workflowResource,
|
|
89
|
+
resourceAliases: resourceAliasesToMap(deployment.resourceAliases),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** Consent model: opt-OUT. Sharing new definition versions defaults on; only
|
|
2
|
+
* --no-share-defs turns it off — CI, DO_NOT_TRACK, and non-TTY don't change that. */
|
|
3
|
+
import { type DeployDefinitionResult, type DeployedDefinition, type WorkflowResource } from '@sanity/workflows';
|
|
4
|
+
import { type FollowUpContext } from './follow-up-command.ts';
|
|
5
|
+
import type { UserConfigStore } from './telemetry-setup.ts';
|
|
6
|
+
import { type WorkflowDefinitionSharedData } from './telemetry.ts';
|
|
7
|
+
/** The client slice sharing uses — the read-back of just-deployed
|
|
8
|
+
* documents and the feedback POST, structurally, so a full
|
|
9
|
+
* `SanityClient` satisfies it and tests fake exactly these calls. */
|
|
10
|
+
export interface ShareClient {
|
|
11
|
+
fetch<T>(query: string, params: Record<string, unknown>, options: {
|
|
12
|
+
tag: string;
|
|
13
|
+
}): Promise<T>;
|
|
14
|
+
request<T>(opts: {
|
|
15
|
+
url: string;
|
|
16
|
+
method: string;
|
|
17
|
+
body: unknown;
|
|
18
|
+
tag: string;
|
|
19
|
+
}): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
/** One successfully deployed deployment's outcome, paired with the client
|
|
22
|
+
* that can read the just-deployed documents back and the resource the
|
|
23
|
+
* entries' deployment coordinates derive from. */
|
|
24
|
+
export interface ShareCandidate {
|
|
25
|
+
client: ShareClient;
|
|
26
|
+
partition: string;
|
|
27
|
+
resource: WorkflowResource;
|
|
28
|
+
results: DeployDefinitionResult[];
|
|
29
|
+
/** The deploy call's run id — the markers carry the same id the engine's
|
|
30
|
+
* deploy events minted, so donated definitions group with their deploy. */
|
|
31
|
+
deployId: string;
|
|
32
|
+
}
|
|
33
|
+
/** Sanity's first-party definition-feedback endpoint (editorial-ai-backend,
|
|
34
|
+
* routed project-agnostically through the API gateway). */
|
|
35
|
+
export declare const SHARE_ENDPOINT_URL = "/workflow/definition-feedback";
|
|
36
|
+
/**
|
|
37
|
+
* The first-run disclosure — a product contract, pinned by test. It must
|
|
38
|
+
* name the recipient (Sanity), state that the document ships VERBATIM with its
|
|
39
|
+
* deployment coordinates and is kept, name what is never shared, and disclose
|
|
40
|
+
* that the notice is remembered machine-wide and name the per-run opt-out.
|
|
41
|
+
* This is a notice, not a choice: sharing is the default unless the invocation
|
|
42
|
+
* supplies `--no-share-defs`.
|
|
43
|
+
*/
|
|
44
|
+
export declare const SHARE_FIRST_RUN_NOTICE: string;
|
|
45
|
+
/**
|
|
46
|
+
* The status block printed on every flagless deploy that does not show the
|
|
47
|
+
* first-run disclosure. It keeps the default donation obvious in terminals and
|
|
48
|
+
* unattended logs and names both explicit controls as runnable commands.
|
|
49
|
+
*/
|
|
50
|
+
export declare function shareReminder(followUp: FollowUpContext): string;
|
|
51
|
+
/**
|
|
52
|
+
* The content-free telemetry marker for one shared definition — projected
|
|
53
|
+
* from the engine's own deploy-event derivation ({@link definitionDeployedData})
|
|
54
|
+
* so `Workflows CLI Definition Shared` and `Workflows Engine Definition Deployed`
|
|
55
|
+
* can never disagree about one definition's structure. Status is dropped: only
|
|
56
|
+
* newly created versions are ever shared.
|
|
57
|
+
*/
|
|
58
|
+
export declare function definitionShareMarker(args: {
|
|
59
|
+
definition: DeployedDefinition;
|
|
60
|
+
contentHash: string;
|
|
61
|
+
deployId: string;
|
|
62
|
+
}): WorkflowDefinitionSharedData;
|
|
63
|
+
/**
|
|
64
|
+
* Whether the invocation's telemetry should send despite the environment
|
|
65
|
+
* denial (CI / `DO_NOT_TRACK`). Every flagless or explicitly enabled deploy
|
|
66
|
+
* that can create versions forces it, because definition donation defaults on
|
|
67
|
+
* in those environments too. Account-level consent is never
|
|
68
|
+
* overridden (the intake still reads `/intake/telemetry-status`).
|
|
69
|
+
*
|
|
70
|
+
* Computed from raw argv because the prerun hook builds the store before oclif
|
|
71
|
+
* parses flags, so it must land on the same value oclif will: repeated
|
|
72
|
+
* `allowNo` booleans are **last-token-wins**, and tokens after `--` aren't
|
|
73
|
+
* flags. `--dry-run` / `--check` never create versions, so they never donate —
|
|
74
|
+
* no telemetry to force. The `share-defs` flag has no char/alias/env source,
|
|
75
|
+
* so `--share-defs` / `--no-share-defs` are its only tokens (add one and this
|
|
76
|
+
* match must learn it too).
|
|
77
|
+
*/
|
|
78
|
+
export declare function shouldForceShareTelemetry(args: {
|
|
79
|
+
commandId: string | undefined;
|
|
80
|
+
argv: string[];
|
|
81
|
+
}): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* The whole post-deploy sharing flow. An explicit flag decides directly;
|
|
84
|
+
* otherwise sharing defaults on after emitting either the one-time disclosure
|
|
85
|
+
* or recurring reminder. It always records the content-free per-invocation
|
|
86
|
+
* decision so adoption dashboards can measure opt-out rate. No newly created
|
|
87
|
+
* versions (unchanged re-deploys, dry runs, nothing succeeded) means no
|
|
88
|
+
* decision, notice, or POST.
|
|
89
|
+
*
|
|
90
|
+
* The optional args exist for the flow's dependencies, mirroring
|
|
91
|
+
* `setupCliTelemetry` — omitted, the real process surfaces apply.
|
|
92
|
+
*/
|
|
93
|
+
export declare function shareDefinitionsAfterDeploy(args: {
|
|
94
|
+
flag: boolean | undefined;
|
|
95
|
+
followUp: FollowUpContext;
|
|
96
|
+
candidates: ShareCandidate[];
|
|
97
|
+
warn: (message: string) => void;
|
|
98
|
+
interactive?: boolean;
|
|
99
|
+
writeStderr?: (message: string) => void;
|
|
100
|
+
userConfig?: UserConfigStore;
|
|
101
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
|
+
import { getUserConfig } from '@sanity/cli-core';
|
|
3
|
+
import { assertReadableModel, definitionDeployedData, errorMessage, } from '@sanity/workflows';
|
|
4
|
+
import { WORKFLOWS_DEPLOY_COMMAND_ID } from '../command-ids.js';
|
|
5
|
+
import { buildDefinitionShowQuery } from './definitions.js';
|
|
6
|
+
import { flagTokens } from './flags.js';
|
|
7
|
+
import { followUpCommand } from './follow-up-command.js';
|
|
8
|
+
import { canPromptOnStderr } from './prompt.js';
|
|
9
|
+
import { cliTelemetry, WorkflowDefinitionShared, WorkflowDefinitionSharingDecided, } from './telemetry.js';
|
|
10
|
+
export const SHARE_ENDPOINT_URL = '/workflow/definition-feedback';
|
|
11
|
+
const SHARE_TAG = 'definition.share';
|
|
12
|
+
const SHARE_DECISION_KEY = 'workflowCliDefinitionSharing';
|
|
13
|
+
export const SHARE_FIRST_RUN_NOTICE = `${styleText('bold', 'Sharing new workflow definitions with Sanity')} to improve Workflows.\n` +
|
|
14
|
+
'They are sent verbatim (structure, names, filters, effect configuration,\n' +
|
|
15
|
+
'seeded values) with their deployment coordinates, and kept — never your\n' +
|
|
16
|
+
'content documents, workflow instances, or Sanity auth token. This notice is\n' +
|
|
17
|
+
`shown once on this machine; opt out of any run with ${styleText('cyan', '--no-share-defs')}.\n`;
|
|
18
|
+
export function shareReminder(followUp) {
|
|
19
|
+
const examples = [
|
|
20
|
+
{ flags: [], note: 'share by default' },
|
|
21
|
+
{ flags: ['--share-defs'], note: 'share explicitly; hide this warning' },
|
|
22
|
+
{ flags: ['--no-share-defs'], note: 'opt out' },
|
|
23
|
+
].map(({ flags, note }) => ({ command: followUpCommand(followUp, 'deploy', ...flags), note }));
|
|
24
|
+
const width = Math.max(...examples.map(({ command }) => command.length));
|
|
25
|
+
return (`${styleText('bold', 'Definition sharing: ON (default)')}\n` +
|
|
26
|
+
'New workflow definition versions are being shared with Sanity to improve Workflows.\n' +
|
|
27
|
+
'Examples:\n' +
|
|
28
|
+
examples
|
|
29
|
+
.map(({ command, note }) => ` ${styleText('dim', '$')} ${command.padEnd(width)} ${styleText('dim', `# ${note}`)}\n`)
|
|
30
|
+
.join(''));
|
|
31
|
+
}
|
|
32
|
+
export function definitionShareMarker(args) {
|
|
33
|
+
const { status: _status, ...structural } = definitionDeployedData(args.definition, {
|
|
34
|
+
contentHash: args.contentHash,
|
|
35
|
+
status: 'created',
|
|
36
|
+
deployId: args.deployId,
|
|
37
|
+
});
|
|
38
|
+
return structural;
|
|
39
|
+
}
|
|
40
|
+
export function shouldForceShareTelemetry(args) {
|
|
41
|
+
const { commandId, argv } = args;
|
|
42
|
+
if (commandId !== WORKFLOWS_DEPLOY_COMMAND_ID) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const tokens = flagTokens(argv);
|
|
46
|
+
if (tokens.includes('--dry-run') || tokens.includes('--check')) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return (tokens.lastIndexOf('--share-defs') > tokens.lastIndexOf('--no-share-defs') ||
|
|
50
|
+
!tokens.includes('--no-share-defs'));
|
|
51
|
+
}
|
|
52
|
+
async function loadShareEntry(args) {
|
|
53
|
+
const { candidate, result, warn } = args;
|
|
54
|
+
const deployed = await loadDeployedForShare(args);
|
|
55
|
+
if (deployed === undefined) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
if (deployed.contentHash === undefined) {
|
|
59
|
+
warn(`${result.name} v${result.version} carries no content hash — not shared.`);
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
definition: deployed,
|
|
64
|
+
contentHash: deployed.contentHash,
|
|
65
|
+
name: result.name,
|
|
66
|
+
version: result.version,
|
|
67
|
+
resourceType: candidate.resource.type,
|
|
68
|
+
resourceId: candidate.resource.id,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async function loadDeployedForShare(args) {
|
|
72
|
+
const { candidate, result, warn } = args;
|
|
73
|
+
const { groq, params } = buildDefinitionShowQuery({
|
|
74
|
+
name: result.name,
|
|
75
|
+
partition: candidate.partition,
|
|
76
|
+
version: result.version,
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
const deployed = await candidate.client.fetch(groq, params, {
|
|
80
|
+
tag: SHARE_TAG,
|
|
81
|
+
});
|
|
82
|
+
if (deployed === null) {
|
|
83
|
+
warn(`Could not read back ${result.name} v${result.version} — not shared.`);
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
assertReadableModel(deployed);
|
|
87
|
+
return deployed;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
warn(`Could not read back ${result.name} v${result.version} — not shared. ${errorMessage(error)}`);
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function collectCreated(candidates) {
|
|
95
|
+
return candidates.flatMap((candidate) => candidate.results
|
|
96
|
+
.filter((result) => result.status === 'created')
|
|
97
|
+
.map((result) => ({ candidate, result })));
|
|
98
|
+
}
|
|
99
|
+
function wasShareNoticeShown(userConfig) {
|
|
100
|
+
const value = userConfig.get(SHARE_DECISION_KEY);
|
|
101
|
+
return typeof value === 'boolean';
|
|
102
|
+
}
|
|
103
|
+
function rememberShareNotice(userConfig) {
|
|
104
|
+
try {
|
|
105
|
+
userConfig.set(SHARE_DECISION_KEY, true);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function resolveShareIntent(args) {
|
|
111
|
+
if (args.flag === true) {
|
|
112
|
+
return { share: true, decision: 'opt-in' };
|
|
113
|
+
}
|
|
114
|
+
if (args.flag === false) {
|
|
115
|
+
return { share: false, decision: 'opt-out' };
|
|
116
|
+
}
|
|
117
|
+
if (args.interactive && !wasShareNoticeShown(args.userConfig)) {
|
|
118
|
+
args.writeStderr(SHARE_FIRST_RUN_NOTICE);
|
|
119
|
+
rememberShareNotice(args.userConfig);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
args.writeStderr(shareReminder(args.followUp));
|
|
123
|
+
}
|
|
124
|
+
return { share: true, decision: 'default' };
|
|
125
|
+
}
|
|
126
|
+
async function donate(args) {
|
|
127
|
+
const shared = [];
|
|
128
|
+
try {
|
|
129
|
+
for (const item of args.created) {
|
|
130
|
+
const entry = await loadShareEntry({ ...item, warn: args.warn });
|
|
131
|
+
if (entry !== undefined) {
|
|
132
|
+
shared.push({ entry, candidate: item.candidate });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (shared.length === 0) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
await shared[0].candidate.client.request({
|
|
139
|
+
url: SHARE_ENDPOINT_URL,
|
|
140
|
+
method: 'POST',
|
|
141
|
+
body: { definitions: shared.map(({ entry }) => entry) },
|
|
142
|
+
tag: SHARE_TAG,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
args.warn(`Definition sharing failed — nothing shared. ${errorMessage(error)}`);
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
emitShareMarkers(shared);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
function emitShareMarkers(shared) {
|
|
153
|
+
try {
|
|
154
|
+
const { logger } = cliTelemetry();
|
|
155
|
+
for (const { entry, candidate } of shared) {
|
|
156
|
+
logger.log(WorkflowDefinitionShared, definitionShareMarker({ ...entry, deployId: candidate.deployId }));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function emitSharingDecided(data) {
|
|
163
|
+
try {
|
|
164
|
+
cliTelemetry().logger.log(WorkflowDefinitionSharingDecided, data);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
export async function shareDefinitionsAfterDeploy(args) {
|
|
170
|
+
const created = collectCreated(args.candidates);
|
|
171
|
+
if (created.length === 0) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
const { share, decision } = resolveShareIntent({
|
|
176
|
+
flag: args.flag,
|
|
177
|
+
followUp: args.followUp,
|
|
178
|
+
interactive: args.interactive ?? canPromptOnStderr(),
|
|
179
|
+
userConfig: args.userConfig ?? getUserConfig(),
|
|
180
|
+
writeStderr: args.writeStderr ?? ((message) => void process.stderr.write(message)),
|
|
181
|
+
});
|
|
182
|
+
const shared = share ? await donate({ created, warn: args.warn }) : false;
|
|
183
|
+
emitSharingDecided({ decision, shared, definitionCount: created.length });
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
args.warn(`Definition sharing skipped — ${errorMessage(error)}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Discovery is deliberately soft: telemetry must never break or exit a
|
|
2
|
+
* command — a missing/broken config, token, or dataset just leaves it off. */
|
|
3
|
+
import { processShellUserProperties, type TelemetryIntakeClient, type WorkflowResource } from '@sanity/workflows';
|
|
4
|
+
import { type WorkflowCliCommandContext } from './command-context.ts';
|
|
5
|
+
/** The get/set slice of the shared Sanity user config (cli-core's
|
|
6
|
+
* `getUserConfig`) the shell persists flags into — narrow so tests fake
|
|
7
|
+
* exactly what's read and written. */
|
|
8
|
+
export interface UserConfigStore {
|
|
9
|
+
get: (key: string) => unknown;
|
|
10
|
+
set: (key: string, value: unknown) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The one-time transparency notice, mirroring the sanity CLI's
|
|
14
|
+
* `telemetryDisclosure` — both CLIs feed the same pipeline. Written to
|
|
15
|
+
* stderr so it never garbles command output.
|
|
16
|
+
*/
|
|
17
|
+
export declare function maybeShowTelemetryDisclosure(args: {
|
|
18
|
+
userConfig: UserConfigStore;
|
|
19
|
+
writeStderr: (message: string) => void;
|
|
20
|
+
}): void;
|
|
21
|
+
/**
|
|
22
|
+
* Assemble and install the invocation's shell: a config-provided
|
|
23
|
+
* `telemetry` logger replaces the built-in shell wholesale (none of its
|
|
24
|
+
* policy applies); otherwise the built-in Sanity-intake store is
|
|
25
|
+
* constructed whenever an auth token exists, with or without a config —
|
|
26
|
+
* mirroring the standard recipe's "not logged in → nothing sent". Events
|
|
27
|
+
* are attributed to the resource the run's flags name, else to the resource
|
|
28
|
+
* of the deployment `--deployment` names, else (without `--deployment`) to
|
|
29
|
+
* the config's first deployment's resource, else to no resource. The intake
|
|
30
|
+
* project is that resource's project when it lives in one.
|
|
31
|
+
*
|
|
32
|
+
* The optional args exist for the hook's dependencies (config path, environment,
|
|
33
|
+
* user config, stderr) — omitted, the real process surfaces apply.
|
|
34
|
+
*/
|
|
35
|
+
export declare function setupCliTelemetry(args?: {
|
|
36
|
+
/** The command's `--path`; omitted, the search starts in the working directory. */
|
|
37
|
+
configPath?: string | undefined;
|
|
38
|
+
/** The resource the command's resource flags name, which wins over the config's. */
|
|
39
|
+
target?: WorkflowResource | undefined;
|
|
40
|
+
/** The command's `--deployment`, whose resource the config fallback reads. */
|
|
41
|
+
deployment?: string | undefined;
|
|
42
|
+
env?: Record<string, string | undefined>;
|
|
43
|
+
userConfig?: UserConfigStore;
|
|
44
|
+
writeStderr?: (message: string) => void;
|
|
45
|
+
/** This package's version — the prerun hook supplies it. */
|
|
46
|
+
cliVersion?: string | undefined;
|
|
47
|
+
/** Override the environment denial (CI / `DO_NOT_TRACK`) — the prerun hook
|
|
48
|
+
* sets this for a deploy that may share definitions, either by default or
|
|
49
|
+
* through `--share-defs`. */
|
|
50
|
+
forceSend?: boolean;
|
|
51
|
+
/** Intake client override — tests inject a fake here, like the other
|
|
52
|
+
* hook dependencies above; omitted, the real project client applies. */
|
|
53
|
+
client?: TelemetryIntakeClient;
|
|
54
|
+
/** Omitted, the trace reports no command path and no flag values. */
|
|
55
|
+
context?: WorkflowCliCommandContext;
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* The invocation's environment user properties: the sanity CLI's precedent
|
|
59
|
+
* set (versions, platform, runtime), the resource the run reads or writes as
|
|
60
|
+
* `resourceType` and `resourceId`, and a dataset's `projectId` and `dataset`
|
|
61
|
+
* coordinates. `orgId`, which Studio's shell sends and the sanity CLI does not
|
|
62
|
+
* yet, attaches separately once {@link resolveOrgId} resolves. Joined to the
|
|
63
|
+
* session's events by sessionId downstream; user identity stays sink-side.
|
|
64
|
+
*/
|
|
65
|
+
export declare function cliUserProperties(args: {
|
|
66
|
+
resource: WorkflowResource | undefined;
|
|
67
|
+
cliVersion: string | undefined;
|
|
68
|
+
}): ReturnType<typeof processShellUserProperties> & {
|
|
69
|
+
cliVersion?: string;
|
|
70
|
+
resourceType?: WorkflowResource['type'];
|
|
71
|
+
resourceId?: string;
|
|
72
|
+
projectId?: string;
|
|
73
|
+
dataset?: string;
|
|
74
|
+
};
|
|
75
|
+
/** The organization that owns the run's resource. Degrade-soft: a failed, slow, or
|
|
76
|
+
* org-less lookup resolves undefined, never rejects, never breaks a command. */
|
|
77
|
+
export declare function resolveOrgId(client: TelemetryIntakeClient, resource: WorkflowResource): Promise<string | undefined>;
|