@sanity/workflows-cli 0.0.0 → 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.
Files changed (80) hide show
  1. package/CHANGELOG.md +407 -0
  2. package/README.md +95 -44
  3. package/dist/commands/workflows/codemod/packages.js +2 -2
  4. package/dist/commands/workflows/definitions/delete.js +2 -2
  5. package/dist/commands/workflows/definitions/list.d.ts +1 -0
  6. package/dist/commands/workflows/definitions/show.d.ts +1 -0
  7. package/dist/commands/workflows/definitions/validate.js +3 -3
  8. package/dist/commands/workflows/deploy.d.ts +2 -2
  9. package/dist/commands/workflows/deploy.js +4 -4
  10. package/dist/commands/workflows/diagnose.d.ts +1 -0
  11. package/dist/commands/workflows/diagnose.js +2 -2
  12. package/dist/commands/workflows/fire-action.js +3 -3
  13. package/dist/commands/workflows/list.d.ts +1 -0
  14. package/dist/commands/workflows/list.js +2 -1
  15. package/dist/commands/workflows/nuke.js +2 -3
  16. package/dist/commands/workflows/show.d.ts +1 -0
  17. package/dist/commands/workflows/start.js +6 -6
  18. package/dist/commands/workflows/tail.d.ts +1 -0
  19. package/dist/commands/workflows/tail.js +3 -3
  20. package/dist/commands/workflows/whoami.d.ts +1 -0
  21. package/dist/commands/workflows/whoami.js +11 -11
  22. package/dist/hooks/finally/telemetry.js +2 -1
  23. package/dist/hooks/prerun/telemetry.d.ts +5 -0
  24. package/dist/hooks/prerun/telemetry.js +19 -4
  25. package/dist/lib/base-command.d.ts +3 -3
  26. package/dist/lib/base-command.js +12 -5
  27. package/dist/lib/blueprint-needs.d.ts +1 -1
  28. package/dist/lib/blueprint-needs.js +98 -19
  29. package/dist/lib/blueprint-stacks.js +38 -8
  30. package/dist/lib/client.d.ts +4 -1
  31. package/dist/lib/client.js +9 -4
  32. package/dist/lib/codemod/ast.d.ts +17 -0
  33. package/dist/lib/codemod/ast.js +14 -0
  34. package/dist/lib/codemod/export-rename.d.ts +19 -0
  35. package/dist/lib/codemod/export-rename.js +337 -0
  36. package/dist/lib/codemod/manifest-rewrite.d.ts +5 -2
  37. package/dist/lib/codemod/manifest-rewrite.js +57 -21
  38. package/dist/lib/codemod/package-map.d.ts +5 -0
  39. package/dist/lib/codemod/package-map.js +27 -0
  40. package/dist/lib/codemod/report.d.ts +0 -1
  41. package/dist/lib/codemod/report.js +9 -1
  42. package/dist/lib/codemod/run.d.ts +5 -3
  43. package/dist/lib/codemod/run.js +6 -1
  44. package/dist/lib/codemod/source-rewrite.d.ts +6 -4
  45. package/dist/lib/codemod/source-rewrite.js +12 -17
  46. package/dist/lib/context.d.ts +6 -10
  47. package/dist/lib/context.js +18 -23
  48. package/dist/lib/default-partition.js +2 -3
  49. package/dist/lib/definition-files.d.ts +3 -0
  50. package/dist/lib/definition-files.js +5 -3
  51. package/dist/lib/fail.d.ts +8 -1
  52. package/dist/lib/fail.js +16 -7
  53. package/dist/lib/failure-kind.d.ts +7 -0
  54. package/dist/lib/failure-kind.js +66 -0
  55. package/dist/lib/flags.d.ts +7 -3
  56. package/dist/lib/flags.js +16 -6
  57. package/dist/lib/load-config.d.ts +5 -0
  58. package/dist/lib/load-config.js +4 -6
  59. package/dist/lib/nuke.d.ts +4 -4
  60. package/dist/lib/nuke.js +3 -3
  61. package/dist/lib/operation-args.d.ts +4 -4
  62. package/dist/lib/operation-args.js +1 -1
  63. package/dist/lib/ops-report.d.ts +1 -3
  64. package/dist/lib/ops-report.js +2 -2
  65. package/dist/lib/pick-resource.d.ts +13 -0
  66. package/dist/lib/pick-resource.js +82 -0
  67. package/dist/lib/read-fanout.d.ts +4 -4
  68. package/dist/lib/read-fanout.js +5 -4
  69. package/dist/lib/resource-target.d.ts +10 -0
  70. package/dist/lib/resource-target.js +12 -0
  71. package/dist/lib/telemetry-setup.d.ts +20 -24
  72. package/dist/lib/telemetry-setup.js +36 -30
  73. package/dist/lib/telemetry.d.ts +3 -0
  74. package/dist/lib/telemetry.js +2 -2
  75. package/dist/lib/ui.d.ts +1 -4
  76. package/dist/lib/ui.js +2 -4
  77. package/oclif.manifest.json +189 -26
  78. package/package.json +5 -5
  79. package/dist/lib/pick-dataset.d.ts +0 -10
  80. package/dist/lib/pick-dataset.js +0 -30
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @sanity/workflows-cli
2
2
 
3
+ > **Documentation:** [Workflows docs](https://www.sanity.io/docs/workflows). For this package, see [CLI reference](https://www.sanity.io/docs/workflows/cli-reference).
4
+
3
5
  Command-line tool for deploying, inspecting, and administering Sanity workflow
4
6
  definitions and instances.
5
7
 
@@ -116,9 +118,12 @@ and partition by default. `--partition` filters to one partition, and
116
118
 
117
119
  The read commands `list`, `show`, `tail`, `diagnose`, `definitions list`,
118
120
  `definitions show`, and `whoami` can also read one resource you name, with or without a
119
- `sanity.workflow.ts`. Use the same flags as the Sanity CLI:
120
- `--project-id <id>` and `--dataset <name>` (`-p` and `-d`) together for a
121
- dataset, or `--media-library-id <id>` for a media library. The CLI then reads
121
+ `sanity.workflow.ts`. Pass `--workflow-resource <type>:<id>` for any resource
122
+ type: `dataset:<projectId>.<dataset>`, `media-library:<id>`, `canvas:<id>` or
123
+ `dashboard:<id>`, the same form a deployment's `workflowResource` takes as a
124
+ string. For a dataset you can also use the Sanity CLI flags `--project-id <id>`
125
+ and `--dataset <name>` (`-p` and `-d`) together. `--media-library-id <id>` is
126
+ deprecated; use `--workflow-resource media-library:<id>`. The CLI then reads
122
127
  only that resource and loads no config, so `--deployment` and `--path` can't be
123
128
  combined with them. `--partition` still filters. Commands that write, such as
124
129
  `start`, `abort`, and `deploy`, always act through a deployment in
@@ -131,24 +136,25 @@ them, and the project has a service. Otherwise they write directly with your
131
136
  token.
132
137
 
133
138
  ```sh
134
- sanity workflows definitions list --project-id abc123 --dataset production
139
+ sanity workflows definitions list --workflow-resource dataset:abc123.production
140
+ sanity workflows list --workflow-resource media-library:mlAbc123
135
141
  sanity workflows show prod.wf-instance.x7k2 -p abc123 -d production
136
142
  ```
137
143
 
138
144
  When no `sanity.workflow.ts` is found and you pass none of these flags or
139
145
  `--path` or `--deployment`, a read in an interactive terminal asks you to pick
140
- a project, then one of its datasets, from those your login can access. It then
141
- prints the `--project-id` and `--dataset` flags that read the same dataset, so
142
- you can script the next run. The picker offers datasets only; pass
143
- `--media-library-id` to read a media library. With `--json` or in a
144
- non-interactive shell, the read fails and names the flags instead.
146
+ a resource type, then a resource of that type your login can access (for a
147
+ dataset, a project and then one of its datasets). It then prints the
148
+ `--workflow-resource` flag that reads the same resource, so you can script the
149
+ next run. With `--json` or in a non-interactive shell, the read fails and names
150
+ the flags instead.
145
151
 
146
152
  When an instance ID or definition name is found in more than one deployment,
147
153
  for example two deployments on different resources that both use `default`,
148
154
  an interactive terminal prompts you to pick one. Each choice shows the
149
- deployment name with its dataset. With `--json` or in a non-interactive shell,
150
- the command fails, lists each candidate as `name (dataset)`, and asks for
151
- `--deployment`.
155
+ deployment name with its resource. With `--json` or in a non-interactive shell,
156
+ the command fails, lists each candidate as `name (<resource type> <id>)` (for
157
+ example `production (dataset acme.production)`), and asks for `--deployment`.
152
158
 
153
159
  A deployment alone on its configured resource may omit `partition`; it resolves
154
160
  to `default`, independent of its name. If several deployments share that
@@ -257,10 +263,14 @@ Current gaps:
257
263
  recognizes as boolean, starts on every matching write instead, and the
258
264
  generator warns about it and names which of these applies. Only the definition's own
259
265
  start requirements refuse a start, such as a `singleSubject` requirement.
260
- - A start watcher in a Media Library starts an asset only when the asset is
261
- created. When a deployment binds a Media Library, `blueprints generate` fails
262
- for an autonomous asset definition whose `start.filter` reads anything of the
263
- asset other than `_type`.
266
+ - A Media Library trigger receives one upload as more than one write, so
267
+ `blueprints generate` fails for an autonomous asset definition watched on a
268
+ Media Library whose `start.filter` would start on every write: one that reads
269
+ `$now` or another document, reads `$tag` or `$definition` and a field of
270
+ the asset other than `_type`, or is not an expression the generator
271
+ recognizes as boolean, unless the heartbeat starts it on the clock as
272
+ described below; then it gets no library watcher and the heartbeat alone
273
+ starts it. Other asset start filters are watched as on a dataset.
264
274
  - Definitions and functions deploy in two steps, definitions first, until the
265
275
  Blueprints service registers the `sanity.workflow` resource.
266
276
  - A generated file cannot be taken over: editing one is drift, and the next
@@ -336,7 +346,9 @@ your own `sanity.blueprint.ts`, anything it could not resolve), a count of the
336
346
  files it wrote, and a `Deploy:` section naming which stack to deploy with which
337
347
  token. The project stack is always named when there are document functions,
338
348
  because each function bundles `sanity.workflow.ts`; the heartbeat stack is named
339
- only when this run created or updated one of its files. On the first run:
349
+ when this run created or updated one of its files, and on every run when a
350
+ deployment has scheduled drains (a workflow stored in a Media Library). On the
351
+ first run:
340
352
 
341
353
  ```
342
354
  Runtime needs:
@@ -369,10 +381,16 @@ whether you deployed that stack, so it names the files and asks conditionally:
369
381
  heartbeat stack's instructions whether or not this run changed its files.
370
382
 
371
383
  The heartbeat stack's blueprint lists, in its header, the partition, the
372
- datasets, the `'function'`-hosted workflows the heartbeat ticks and the
373
- `'function'`-hosted effects it re-queues. Editing an existing workflow leaves it
374
- unchanged, so the default `Deploy:` section does not name the heartbeat stack,
375
- and `--verbose` lists the file as `unchanged`. Adding or removing a
384
+ workflow resource and each resource an alias binds, the `'function'`-hosted
385
+ workflows the heartbeat ticks, the `'function'`-hosted effects it re-queues, any
386
+ effects it drains on schedule, and each definition it starts on the clock with
387
+ its resource, subject types and start filter. Editing an existing workflow
388
+ stored in a dataset leaves it unchanged unless it changes which definitions the
389
+ heartbeat starts on the clock, or their start filter or subject types, so the default `Deploy:` section does not name the
390
+ heartbeat stack, and `--verbose` lists the file as `unchanged`. A workflow
391
+ stored in a Media Library drains its effects from the heartbeat stack, which
392
+ bundles your handlers, so the `Deploy:` section always names that stack: redeploy
393
+ it after you change a handler or a definition. Adding or removing a
376
394
  `'function'`-hosted workflow or effect changes it: redeploy the heartbeat stack
377
395
  too. So does moving the declared specification of `@sanity/functions`,
378
396
  `@sanity/workflows/blueprints`, or `@sanity/workflows`,
@@ -434,6 +452,30 @@ minutes after it was queued, and a later heartbeat run re-queues it; each run
434
452
  re-queues on at most 30 instances, so a large backlog takes several runs. Check
435
453
  your plan's cadence before relying on a `$now` deadline in a deployed workflow.
436
454
 
455
+ A `'function'`-hosted autonomous definition whose `start.filter` reads `$now`,
456
+ such as `embargoAt <= $now`, also starts from the heartbeat when the filter
457
+ reads no other document and is recognized as a boolean expression, its
458
+ subject is taken from the started document, and its `start.roles`, if any,
459
+ admit the project `editor` role the heartbeat robot holds (with a Media
460
+ Library workflow resource, a definition declaring `start.roles` is not
461
+ started on the clock). Each run queries every resource
462
+ the definition's subjects can live in for the documents the filter admits at
463
+ that moment and that no instance of the definition holds yet, and starts them.
464
+ In the workflow resource, a document created before its embargo starts on the
465
+ first run past the embargo, with no further write. In another resource, each
466
+ run checks a window of 500 matching documents, held ones included, and with
467
+ `n` matching documents, a heartbeat that runs every minute checks every window
468
+ within `2 * ceil(n / 500) - 1` runs; on an hourly or daily cadence the windows
469
+ still rotate, with no fixed bound. Each run starts at most its share, so a backlog of eligible documents,
470
+ such as every document the filter already admits when the heartbeat is first
471
+ deployed, starts over several runs. A start the engine
472
+ refuses, such as one an unmet start requirement refuses, is logged and
473
+ skipped. The report lists the queries
474
+ this costs per run. A run then shares its 60 instances evenly between
475
+ re-queueing, ticking and starting, 20 each. A `$now` start filter that does not
476
+ qualify starts only on a write: the report warns about it on a dataset, and
477
+ `blueprints generate` fails for it on a Media Library.
478
+
437
479
  ### Checking for drift in CI
438
480
 
439
481
  `blueprints generate --check` renders the same runtime in memory and compares it
@@ -544,9 +586,10 @@ policy](https://www.sanity.io/telemetry). This package sends a subset of it.
544
586
 
545
587
  Collected:
546
588
 
547
- - Project id, dataset, and organization id, as session properties. The
548
- organization id is best effort: it needs a lookup that can resolve to
549
- nothing, and the event sends either way.
589
+ - The resource the run reads or writes (its type and id), the project id and
590
+ dataset when that resource is a dataset, and the organization id that owns
591
+ it, as session properties. The organization id is best effort: it needs a
592
+ lookup that can resolve to nothing, and the event sends either way.
550
593
  - Operating system, CPU architecture, JavaScript runtime and version, and the
551
594
  CLI version.
552
595
  - The command invoked, and the flags it was given. Each is normalised to its
@@ -563,6 +606,11 @@ Collected:
563
606
  deployment partition (`<partition>.wf-instance.<random>`), so the partition
564
607
  reaches telemetry through this field. A caller-supplied instance id is sent verbatim.
565
608
  - The author-chosen effect name, on effect events.
609
+ - Whether a command succeeded and, when it failed, the kind of failure: a
610
+ fixed label such as `usage`, `auth-missing`, `permission-denied`,
611
+ `resource-not-found`, `request-failed`, `config-invalid`,
612
+ `definition-file-invalid`, or the engine error kind (for example
613
+ `instance-not-found`). A failure that matches none of these reports `other`.
566
614
 
567
615
  Never collected, because the policy excludes them:
568
616
 
@@ -585,7 +633,7 @@ package's choice and not a company-wide guarantee:
585
633
  - Error messages, and stack traces of any language. The policy permits error
586
634
  information that excludes sensitive data, but this package's errors quote
587
635
  definition names, partitions, and argv, so none is sent. A failure is reported as
588
- a success boolean and nothing else.
636
+ a success boolean and a fixed failure kind, never the error's text.
589
637
  - Document content, GROQ, and field values.
590
638
  - Definition names and stage names in the engine's own event payloads. A stage
591
639
  transition reports positions in `stages[]`, never names. This does not
@@ -622,23 +670,25 @@ The built-in store attaches these user properties once per invocation (joined
622
670
  to events by session id). User identity is not in the payload; the intake
623
671
  service resolves the sender from the authenticated session.
624
672
 
625
- | Property | What it is |
626
- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
627
- | `surface` | Always `'cli'`. |
628
- | `machinePlatform` | Node `process.platform` (for example `darwin`, `linux`). |
629
- | `cpuArchitecture` | Node `process.arch`. |
630
- | `runtime` | Always `'node'` for this CLI. |
631
- | `runtimeVersion` | Node `process.version`. |
632
- | `cliVersion` | The CLI package version, when oclif supplied it. |
633
- | `projectId` | The `--project-id` the run names, else the first dataset-backed deployment's project in `sanity.workflow.ts`. Absent when neither exists. |
634
- | `dataset` | The `--dataset` the run names, else that deployment's dataset. Absent when neither exists. |
635
- | `orgId` | Organization id for that project, when the lookup succeeds before the command flushes. Optional. |
673
+ | Property | What it is |
674
+ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
675
+ | `surface` | Always `'cli'`. |
676
+ | `machinePlatform` | Node `process.platform` (for example `darwin`, `linux`). |
677
+ | `cpuArchitecture` | Node `process.arch`. |
678
+ | `runtime` | Always `'node'` for this CLI. |
679
+ | `runtimeVersion` | Node `process.version`. |
680
+ | `cliVersion` | The CLI package version, when oclif supplied it. |
681
+ | `resourceType` | The type of the resource the run names with `--workflow-resource`, `--project-id`/`--dataset` or `--media-library-id`, else of the `--deployment` it names, else (without `--deployment`) of the first deployment in `sanity.workflow.ts`. Absent when none exists, or when `--deployment` names no deployment in the config. |
682
+ | `resourceId` | That resource's id. Absent when none exists. |
683
+ | `projectId` | That resource's project, when it is a dataset. |
684
+ | `dataset` | That resource's dataset name, when it is a dataset. |
685
+ | `orgId` | Organization id that owns that resource, when the lookup succeeds before the command flushes. Optional. |
636
686
 
637
687
  ### CLI events
638
688
 
639
689
  These events are defined by this package.
640
690
 
641
- #### `Workflows CLI Command Executed` (version 2)
691
+ #### `Workflows CLI Command Executed` (version 3)
642
692
 
643
693
  One trace per workflows command, shaped like the `sanity` CLI's own
644
694
  `CLI Command Executed` so both join on the same columns. The built-in store
@@ -655,14 +705,15 @@ The context carries:
655
705
  | `extraArguments` | `string[]` | Each flag on the invocation, in the order given and repeated if repeated, in its canonical `--name=value` form: `--partition prod`, `--partition=prod`, and the deprecated `--tag prod` all report `--partition=prod`. A boolean reports `--name` or `--no-name`. A redacted flag reports `--name` alone, and an undeclared flag reports its name as typed (`--resaon`, `-z`) alone. Tokens after `--` are not reported. |
656
706
  | `coreOptions` | `object` | `{debug, help, version}`. `debug` comes from a set `DEBUG` variable, `help` from a literal `help` token, `version` from `--version`. |
657
707
 
658
- The payload carries one field, on `trace.log`:
708
+ The payload is sent on `trace.log`:
659
709
 
660
- | Field | Type | What is collected |
661
- | --------- | --------- | -------------------------------------------------------- |
662
- | `success` | `boolean` | `true` when the command finished without an oclif error. |
710
+ | Field | Type | What is collected |
711
+ | ------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
712
+ | `success` | `boolean` | `true` when the command finished without an oclif error. |
713
+ | `failureKind` | `string` | Present only when `success` is `false`. The engine error kind (for example `instance-not-found`), or one of `usage`, `auth-missing`, `permission-denied`, `resource-not-found`, `request-failed`, `config-invalid`, `definition-file-invalid`, and `other`. Never the error's message, name, or stack. |
663
714
 
664
- A config-supplied logger has no trace, so it receives the four context fields
665
- and `success` together as one log payload.
715
+ A config-supplied logger has no trace, so it receives the four context fields,
716
+ `success`, and on failure `failureKind`, together as one log payload.
666
717
 
667
718
  #### `Workflows CLI Definition Shared` (version 1)
668
719
 
@@ -778,7 +829,7 @@ acting user (and their roles) from `/users/me`, so every write is attributed
778
829
  to whoever the token authenticates — there is no identity injection and no
779
830
  `--as` impersonation. Run `whoami` to see that user: its Sanity user ID is the
780
831
  value user assignee fields take. `whoami` asks about one resource; when the
781
- config names several, pass `--deployment` or `--project-id` with `--dataset`.
832
+ config names several, pass `--deployment` or `--workflow-resource <type>:<id>`.
782
833
  Alongside that "who", the CLI declares an advisory "via what": every verb carries
783
834
  `executionContext: { kind: "cli", id: "workflow-cli" }`, stamped on the history
784
835
  entries of the writes it commits directly. A write it sends to the project's
@@ -5,7 +5,7 @@ import { codemodLines } from '../../../lib/codemod/report.js';
5
5
  import { runCodemod } from '../../../lib/codemod/run.js';
6
6
  import { fail } from '../../../lib/fail.js';
7
7
  export default class CodemodPackages extends WorkflowCommand {
8
- static description = 'Move imports and package.json dependencies from the retired Workflows packages to @sanity/workflows, @sanity/workflows-ui, @sanity/workflows-cli, and @sanity/workflows-test. Rewrites module specifiers in import, export, dynamic import(), require(), and vi.mock() calls, and replaces the old packages in every package.json dependency field. Package names in other strings, comments, and built-up specifiers are listed for you to fix by hand. Generated blueprint files are skipped: run blueprints generate after installing. Lockfiles are never edited.';
8
+ static description = 'Move imports and package.json dependencies from the retired Workflows packages to @sanity/workflows, @sanity/workflows-ui, @sanity/workflows-cli, and @sanity/workflows-test. Rewrites module specifiers in import, export, dynamic import(), require(), and vi.mock() calls, and replaces the old packages in every package.json dependency field. Imports of exports renamed in the same release, such as workflowStudioPlugin, are renamed with every reference to them, as are names after an import() type. A name read through export *, require(), import x = require(), a dynamic import(), a mocked module factory, a computed member, or destructuring from a namespace keeps its old name, so check require() calls, plain JavaScript files, and test mocks by hand. Package names in other strings, comments, and built-up specifiers are listed for you to fix by hand, as are members read through a namespace name the file declares again: rename one if it reads the import. Generated blueprint files are skipped: run blueprints generate after installing. Lockfiles are never edited.';
9
9
  static examples = [
10
10
  '<%= config.bin %> workflows codemod packages --dry-run',
11
11
  '<%= config.bin %> workflows codemod packages',
@@ -36,6 +36,6 @@ export default class CodemodPackages extends WorkflowCommand {
36
36
  range: `^${version}`,
37
37
  write: !flags['dry-run'],
38
38
  });
39
- codemodLines({ ...outcome, dryRun: flags['dry-run'], bin: this.config.bin }).forEach((line) => this.log(line));
39
+ codemodLines({ ...outcome, dryRun: flags['dry-run'] }).forEach((line) => this.log(line));
40
40
  }
41
41
  }
@@ -37,8 +37,8 @@ export default class DefinitionDelete extends WorkflowCommand {
37
37
  static telemetry = defineCommandTelemetry(flags, { redact: ['reason'] });
38
38
  async run() {
39
39
  const { args, flags } = await this.parse(DefinitionDelete);
40
- const { deployment, client } = await resolveContext(flags);
41
- const deleteArgs = buildDeleteArgs({ scope: deployment, name: args.name, flags });
40
+ const { scope, client } = await resolveContext(flags);
41
+ const deleteArgs = buildDeleteArgs({ scope, name: args.name, flags });
42
42
  await runWriteVerb({
43
43
  startLabel: `Deleting definition ${deleteTargetLabel(deleteArgs)}…`,
44
44
  failLabel: 'Delete rejected',
@@ -27,6 +27,7 @@ export default class DefinitionList extends WorkflowCommand {
27
27
  static examples: string[];
28
28
  static flags: {
29
29
  path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
30
+ 'workflow-resource': import("@oclif/core/interfaces").OptionFlag<import("@sanity/workflows").WorkflowResource | undefined, import("@oclif/core/interfaces").CustomOptions>;
30
31
  'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
31
32
  dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
32
33
  'media-library-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -9,6 +9,7 @@ export default class DefinitionShow extends WorkflowCommand {
9
9
  };
10
10
  static flags: {
11
11
  path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'workflow-resource': import("@oclif/core/interfaces").OptionFlag<import("@sanity/workflows").WorkflowResource | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
13
  'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
14
  dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
15
  'media-library-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -1,9 +1,9 @@
1
1
  import { Args } from '@oclif/core';
2
- import { errorMessage, validateDefinitionInputs } from '@sanity/workflows';
2
+ import { validateDefinitionInputs } from '@sanity/workflows';
3
3
  import logSymbols from 'log-symbols';
4
4
  import { WorkflowCommand } from '../../../lib/base-command.js';
5
5
  import { describeValidation, readDefinitionFiles } from '../../../lib/definition-files.js';
6
- import { fail } from '../../../lib/fail.js';
6
+ import { fail, failOn } from '../../../lib/fail.js';
7
7
  import { jsonFlags } from '../../../lib/flags.js';
8
8
  export default class DefinitionValidate extends WorkflowCommand {
9
9
  static hiddenAliases = ['workflows:definition:validate'];
@@ -29,7 +29,7 @@ export default class DefinitionValidate extends WorkflowCommand {
29
29
  entries = await readDefinitionFiles(paths);
30
30
  }
31
31
  catch (err) {
32
- fail('Could not read definitions:', errorMessage(err));
32
+ failOn(err, 'Could not read definitions:');
33
33
  }
34
34
  const report = validateDefinitionInputs(entries.map((entry) => entry.definition));
35
35
  if (flags.json) {
@@ -93,9 +93,9 @@ export declare function deploymentBanner({ deployment, index, total, }: {
93
93
  index: number;
94
94
  total: number;
95
95
  }): string | undefined;
96
- /** The deploy target as one label — the deployment's friendly name/partition
96
+ /** The deploy target as one label: the deployment's friendly name/partition
97
97
  * ({@link deploymentLabel}) and the resource it writes to
98
- * ({@link resourceLabel}) — so every progress and result line names where a
98
+ * ({@link describeResource}), so every progress and result line names where a
99
99
  * deploy landed, including the common single-deployment run that prints no
100
100
  * banner. */
101
101
  export declare function targetLabel(deployment: WorkflowDeployment): string;
@@ -1,6 +1,6 @@
1
1
  import { styleText } from 'node:util';
2
2
  import { Flags } from '@oclif/core';
3
- import { computeDiffEntries, deployedPartitionsGroq, errorMessage, workflow, } from '@sanity/workflows';
3
+ import { computeDiffEntries, deployedPartitionsGroq, describeResource, errorMessage, workflow, } from '@sanity/workflows';
4
4
  import logSymbols from 'log-symbols';
5
5
  import ora from 'ora';
6
6
  import { WorkflowCommand } from '../../lib/base-command.js';
@@ -15,7 +15,7 @@ import { loadWorkflowConfigModule } from '../../lib/load-config.js';
15
15
  import { acknowledgeDeployment, deploymentLabel, deploymentToTarget, selectDeployments, } from '../../lib/select-deployment.js';
16
16
  import { shareDefinitionsAfterDeploy } from '../../lib/share-definitions.js';
17
17
  import { cliTelemetry } from '../../lib/telemetry.js';
18
- import { groupBanner, resourceLabel, terminalWidth, warningLines } from '../../lib/ui.js';
18
+ import { groupBanner, terminalWidth, warningLines } from '../../lib/ui.js';
19
19
  export default class Deploy extends WorkflowCommand {
20
20
  static description = 'Validate workflow definitions, check any generated runtime beside the config against them, then diff and deploy to the resource bound by the selected deployment. A generated runtime that no longer matches the definitions fails the deploy before anything is written; regenerate it with `sanity-workflows blueprints generate`.';
21
21
  static examples = [
@@ -147,7 +147,7 @@ export default class Deploy extends WorkflowCommand {
147
147
  async processDeployment({ deployment, defs, dryRun, client, }) {
148
148
  const target = deploymentToTarget(deployment);
149
149
  const where = targetLabel(deployment);
150
- const resource = resourceLabel(deployment.workflowResource);
150
+ const resource = describeResource(deployment.workflowResource);
151
151
  if (dryRun) {
152
152
  await this.runDryRun({ client, defs, target, where, resource });
153
153
  return undefined;
@@ -243,7 +243,7 @@ export function deploymentBanner({ deployment, index, total, }) {
243
243
  return groupBanner({ label: deploymentLabel(deployment), index, total });
244
244
  }
245
245
  export function targetLabel(deployment) {
246
- return `${deploymentLabel(deployment)} → ${resourceLabel(deployment.workflowResource)}`;
246
+ return `${deploymentLabel(deployment)} → ${describeResource(deployment.workflowResource)}`;
247
247
  }
248
248
  export function deployStartLine(count, where) {
249
249
  return `Deploying ${count} definition(s) to ${where}…`;
@@ -41,6 +41,7 @@ export default class Diagnose extends WorkflowCommand {
41
41
  };
42
42
  static flags: {
43
43
  path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
44
+ 'workflow-resource': import("@oclif/core/interfaces").OptionFlag<import("@sanity/workflows").WorkflowResource | undefined, import("@oclif/core/interfaces").CustomOptions>;
44
45
  'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
45
46
  dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
46
47
  'media-library-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -6,7 +6,7 @@ import logSymbols from 'log-symbols';
6
6
  import { WorkflowCommand } from '../../lib/base-command.js';
7
7
  import { stuckDiagnosisLines, stuckHeadline } from '../../lib/cause-detail.js';
8
8
  import { resolveReadInstanceContext } from '../../lib/context.js';
9
- import { fail, failureDetail } from '../../lib/fail.js';
9
+ import { failOn } from '../../lib/fail.js';
10
10
  import { instanceFlags, jsonFlags, resourceFlags } from '../../lib/flags.js';
11
11
  import { baseEngineArgs } from '../../lib/operation-args.js';
12
12
  import { sectionHeader, activityIcon } from '../../lib/ui.js';
@@ -167,7 +167,7 @@ export default class Diagnose extends WorkflowCommand {
167
167
  ...baseEngineArgs(scope),
168
168
  instanceId: args.instanceId,
169
169
  })
170
- .catch((error) => fail('diagnose failed:', failureDetail(error)));
170
+ .catch((error) => failOn(error, 'diagnose failed:'));
171
171
  const input = diagnoseInputFromEvaluation(evaluation);
172
172
  if (flags.json) {
173
173
  this.log(JSON.stringify({
@@ -5,7 +5,7 @@ import logSymbols from 'log-symbols';
5
5
  import { WorkflowCommand } from '../../lib/base-command.js';
6
6
  import { defineCommandTelemetry } from '../../lib/command-telemetry.js';
7
7
  import { resolveInstanceContext } from '../../lib/context.js';
8
- import { fail, failOnThrow, failureDetail } from '../../lib/fail.js';
8
+ import { fail, failOn, failOnThrow } from '../../lib/fail.js';
9
9
  import { instanceFlags, jsonFlags } from '../../lib/flags.js';
10
10
  import { followUpCommand } from '../../lib/follow-up-command.js';
11
11
  import { baseEngineArgs, cliEngine } from '../../lib/operation-args.js';
@@ -146,7 +146,7 @@ export default class FireAction extends WorkflowCommand {
146
146
  ...baseEngineArgs(scope),
147
147
  instanceId,
148
148
  })
149
- .catch((error) => fail('fire-action failed:', failureDetail(error)));
149
+ .catch((error) => failOn(error, 'fire-action failed:'));
150
150
  const stage = evaluation.instance.currentStage;
151
151
  if (json) {
152
152
  this.log(JSON.stringify({ instanceId, stage, actions }, null, 2));
@@ -166,7 +166,7 @@ export default class FireAction extends WorkflowCommand {
166
166
  if (json) {
167
167
  const result = await engine
168
168
  .fireAction(fireArgs)
169
- .catch((error) => fail('fire-action error:', failureDetail(error)));
169
+ .catch((error) => failOn(error, 'fire-action error:'));
170
170
  this.log(JSON.stringify(fireResultJson(result, { instanceId, activity, action }), null, 2));
171
171
  return;
172
172
  }
@@ -47,6 +47,7 @@ export default class List extends WorkflowCommand {
47
47
  static examples: string[];
48
48
  static flags: {
49
49
  path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
50
+ 'workflow-resource': import("@oclif/core/interfaces").OptionFlag<import("@sanity/workflows").WorkflowResource | undefined, import("@oclif/core/interfaces").CustomOptions>;
50
51
  'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
51
52
  dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
52
53
  'media-library-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -151,10 +151,11 @@ async function logTargetInstances(args) {
151
151
  });
152
152
  }
153
153
  export default class List extends WorkflowCommand {
154
- static description = 'List workflow instances (in-flight by default) across the resources sanity.workflow.ts declares, or in the one resource --project-id/--dataset or --media-library-id names.';
154
+ static description = 'List workflow instances (in-flight by default) across the resources sanity.workflow.ts declares, or in the one resource --workflow-resource (or --project-id with --dataset) names.';
155
155
  static examples = [
156
156
  '<%= config.bin %> workflows list',
157
157
  '<%= config.bin %> workflows list --include-completed',
158
+ '<%= config.bin %> workflows list --workflow-resource media-library:mlAbc123',
158
159
  '<%= config.bin %> workflows list --definition product-launch',
159
160
  '<%= config.bin %> workflows list --document dataset:proj:ds:article-1',
160
161
  '<%= config.bin %> workflows list --assignment-user gAda --assignment-role legal --assignment-state routed',
@@ -1,6 +1,6 @@
1
1
  import { Flags } from '@oclif/core';
2
2
  import { input } from '@sanity/cli-core/ux';
3
- import { WORKFLOW_INSTANCE_TYPE, resourceGdr, terminalState, } from '@sanity/workflows';
3
+ import { describeResource, resourceGdr, terminalState, WORKFLOW_INSTANCE_TYPE, } from '@sanity/workflows';
4
4
  import logSymbols from 'log-symbols';
5
5
  import { WorkflowCommand } from '../../lib/base-command.js';
6
6
  import { clientFor, resolveApiHost, resolveTokenOrFail } from '../../lib/client.js';
@@ -13,7 +13,6 @@ import { confirmationMatches, executeNuke, formatInstanceNukeSummary, formatNuke
13
13
  import { runWriteVerb } from '../../lib/ops-report.js';
14
14
  import { canPromptOnStderr, confirmOnStderr } from '../../lib/prompt.js';
15
15
  import { selectDeployment } from '../../lib/select-deployment.js';
16
- import { resourceLabel } from '../../lib/ui.js';
17
16
  function planApiHost() {
18
17
  return resolveApiHost() ?? 'https://api.sanity.io (production default)';
19
18
  }
@@ -132,7 +131,7 @@ export function deploymentForInstanceScope(config, located) {
132
131
  const deployment = config.deployments.find((candidate) => candidate.partition === located.partition && resourceGdr(candidate.workflowResource) === gdr);
133
132
  if (deployment === undefined) {
134
133
  fail(`No deployment in this workflow config has partition "${located.partition}" on ` +
135
- `${resourceLabel(located.resource)}.`, 'A single-instance delete resolves the deployment to find the alias-bound resources its ' +
134
+ `${describeResource(located.resource)}.`, 'A single-instance delete resolves the deployment to find the alias-bound resources its ' +
136
135
  'guards can live in. Add that deployment to the config, or pass --deployment to name ' +
137
136
  'the one that should own it.');
138
137
  }
@@ -9,6 +9,7 @@ export default class Show extends WorkflowCommand {
9
9
  };
10
10
  static flags: {
11
11
  path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'workflow-resource': import("@oclif/core/interfaces").OptionFlag<import("@sanity/workflows").WorkflowResource | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
13
  'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
14
  dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
15
  'media-library-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -1,11 +1,11 @@
1
1
  import { styleText } from 'node:util';
2
2
  import { Args, Flags } from '@oclif/core';
3
- import { buildInitialFields, errorMessage, releaseRef, sameResource, StartNotPrimedError, StartNotSettledError, startRefusal, } from '@sanity/workflows';
3
+ import { buildInitialFields, errorMessage, foreignAliasResources, releaseRef, StartNotPrimedError, StartNotSettledError, startRefusal, } from '@sanity/workflows';
4
4
  import { WorkflowCommand } from '../../lib/base-command.js';
5
5
  import { defineCommandTelemetry } from '../../lib/command-telemetry.js';
6
- import { dedupeResources, resolveContext } from '../../lib/context.js';
6
+ import { resolveContext } from '../../lib/context.js';
7
7
  import { fetchDeployedDefinition } from '../../lib/definitions.js';
8
- import { fail, failOnThrow, failureDetail } from '../../lib/fail.js';
8
+ import { fail, failOn, failOnThrow } from '../../lib/fail.js';
9
9
  import { deploymentFlags, jsonFlags } from '../../lib/flags.js';
10
10
  import { cliEngine } from '../../lib/operation-args.js';
11
11
  import { runWriteVerb } from '../../lib/ops-report.js';
@@ -76,7 +76,7 @@ export default class Start extends WorkflowCommand {
76
76
  this.log(JSON.stringify(startNotSettledJson(error), null, 2));
77
77
  return undefined;
78
78
  }
79
- fail('start error:', failureDetail(withRetryHint(error)));
79
+ failOn(withRetryHint(error), 'start error:');
80
80
  });
81
81
  if (result !== undefined) {
82
82
  this.log(JSON.stringify(startResultJson(result.instance), null, 2));
@@ -101,7 +101,7 @@ export default class Start extends WorkflowCommand {
101
101
  }
102
102
  export function withRetryHint(error) {
103
103
  return error instanceof StartNotPrimedError
104
- ? new Error(`${errorMessage(error)} (--instance-id ${error.instanceId})`)
104
+ ? new Error(`${errorMessage(error)} (--instance-id ${error.instanceId})`, { cause: error })
105
105
  : error;
106
106
  }
107
107
  export function startNotSettledReport(error) {
@@ -162,7 +162,7 @@ function contentResource({ deployment, field, alias, }) {
162
162
  }
163
163
  return binding.resource;
164
164
  }
165
- const foreign = dedupeResources(bindings.map((binding) => binding.resource)).filter((resource) => !sameResource(resource, deployment.workflowResource));
165
+ const foreign = foreignAliasResources(deployment);
166
166
  if (foreign.length > 1) {
167
167
  throw new Error(`field "${field}" takes a release, but the deployment binds several resources, so a bare ` +
168
168
  `release name is ambiguous. Pass --release-resource <alias>, or the full object: ${field}=` +
@@ -7,6 +7,7 @@ export default class Tail extends WorkflowCommand {
7
7
  };
8
8
  static flags: {
9
9
  path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'workflow-resource': import("@oclif/core/interfaces").OptionFlag<import("@sanity/workflows").WorkflowResource | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
11
  'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
12
  dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
13
  'media-library-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -5,11 +5,11 @@ import { assertReadableModel, displayTitle, errorMessage, } from '@sanity/workfl
5
5
  import logSymbols from 'log-symbols';
6
6
  import { WorkflowCommand } from '../../lib/base-command.js';
7
7
  import { ambiguityFor, findInstance, resolveReadTargets } from '../../lib/context.js';
8
- import { fail, failureDetail } from '../../lib/fail.js';
8
+ import { fail, failOn } from '../../lib/fail.js';
9
9
  import { instanceFlags, resourceFlags } from '../../lib/flags.js';
10
10
  const TAIL_TAG = 'tail';
11
11
  export default class Tail extends WorkflowCommand {
12
- static description = 'Stream new history entries on a workflow instance as they land in the dataset.';
12
+ static description = 'Stream new history entries on a workflow instance as they land in its workflow resource.';
13
13
  static examples = ['<%= config.bin %> workflows tail wf-instance.abc123'];
14
14
  static args = {
15
15
  instanceId: Args.string({
@@ -66,7 +66,7 @@ export default class Tail extends WorkflowCommand {
66
66
  process.on('SIGTERM', shutdown);
67
67
  await listenFailed.catch((err) => {
68
68
  subscription.unsubscribe();
69
- fail('Listen subscription error:', failureDetail(err));
69
+ failOn(err, 'Listen subscription error:');
70
70
  });
71
71
  }
72
72
  async printNewEntries({ client, instanceId, seen, }) {
@@ -4,6 +4,7 @@ export default class WhoamiCommand extends WorkflowCommand {
4
4
  static examples: string[];
5
5
  static flags: {
6
6
  path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ 'workflow-resource': import("@oclif/core/interfaces").OptionFlag<import("@sanity/workflows").WorkflowResource | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
8
  'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
9
  dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
10
  'media-library-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;