@sanity/workflow-cli 0.5.1

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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/bin/run.js +8 -0
  4. package/dist/commands/abort.d.ts +30 -0
  5. package/dist/commands/abort.js +62 -0
  6. package/dist/commands/definition/delete.d.ts +36 -0
  7. package/dist/commands/definition/delete.js +86 -0
  8. package/dist/commands/definition/diff.d.ts +13 -0
  9. package/dist/commands/definition/diff.js +57 -0
  10. package/dist/commands/definition/list.d.ts +31 -0
  11. package/dist/commands/definition/list.js +83 -0
  12. package/dist/commands/definition/show.d.ts +33 -0
  13. package/dist/commands/definition/show.js +118 -0
  14. package/dist/commands/deploy.d.ts +22 -0
  15. package/dist/commands/deploy.js +97 -0
  16. package/dist/commands/diagnose.d.ts +23 -0
  17. package/dist/commands/diagnose.js +269 -0
  18. package/dist/commands/fire-action.d.ts +63 -0
  19. package/dist/commands/fire-action.js +241 -0
  20. package/dist/commands/list.d.ts +46 -0
  21. package/dist/commands/list.js +106 -0
  22. package/dist/commands/move-stage.d.ts +47 -0
  23. package/dist/commands/move-stage.js +77 -0
  24. package/dist/commands/retry-task.d.ts +9 -0
  25. package/dist/commands/retry-task.js +11 -0
  26. package/dist/commands/set-stage.d.ts +12 -0
  27. package/dist/commands/set-stage.js +18 -0
  28. package/dist/commands/show.d.ts +23 -0
  29. package/dist/commands/show.js +85 -0
  30. package/dist/commands/tail.d.ts +15 -0
  31. package/dist/commands/tail.js +73 -0
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.js +4 -0
  34. package/dist/lib/client.d.ts +17 -0
  35. package/dist/lib/client.js +40 -0
  36. package/dist/lib/config.d.ts +18 -0
  37. package/dist/lib/config.js +50 -0
  38. package/dist/lib/definitions.d.ts +36 -0
  39. package/dist/lib/definitions.js +122 -0
  40. package/dist/lib/diff.d.ts +7 -0
  41. package/dist/lib/diff.js +49 -0
  42. package/dist/lib/env.d.ts +10 -0
  43. package/dist/lib/env.js +13 -0
  44. package/dist/lib/fail.d.ts +16 -0
  45. package/dist/lib/fail.js +33 -0
  46. package/dist/lib/flags.d.ts +5 -0
  47. package/dist/lib/flags.js +8 -0
  48. package/dist/lib/operation-args.d.ts +25 -0
  49. package/dist/lib/operation-args.js +48 -0
  50. package/dist/lib/ops-report.d.ts +30 -0
  51. package/dist/lib/ops-report.js +28 -0
  52. package/dist/lib/stub.d.ts +10 -0
  53. package/dist/lib/stub.js +24 -0
  54. package/oclif.manifest.json +684 -0
  55. package/package.json +94 -0
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The synthetic actor a CLI write is attributed to when the operator
3
+ * doesn't name a real user. The engine resolves a real actor from
4
+ * `/users/me`, which a token-only CLI can't reach; until the CLI hooks
5
+ * into Sanity auth proper, writes act as this system identity.
6
+ */
7
+ const SYSTEM_ACTOR = { kind: 'system', id: 'workflow-cli' };
8
+ /**
9
+ * The write-verb arguments every engine operation shares: tag scope,
10
+ * workflow resource, and the CLI's pinned actor ({@link SYSTEM_ACTOR}).
11
+ * Spread by both the instance verbs ({@link buildOperationArgs}) and the
12
+ * definition verbs (e.g. `definition delete`).
13
+ */
14
+ export function baseEngineArgs(config) {
15
+ return {
16
+ tag: config.tag,
17
+ workflowResource: config.workflowResource,
18
+ access: { actor: SYSTEM_ACTOR },
19
+ };
20
+ }
21
+ /**
22
+ * Resolve the actor a write is attributed to. With a named user the fire
23
+ * is pinned to it (plus any roles, so role-gated action filters pass);
24
+ * without one the {@link SYSTEM_ACTOR} fallback applies. Roles without a
25
+ * named user throw — they'd silently attach to nothing otherwise.
26
+ */
27
+ export function resolveActor(as, roles) {
28
+ if (as === undefined) {
29
+ if (roles.length > 0) {
30
+ throw new Error('--as-role requires --as <userId>');
31
+ }
32
+ return SYSTEM_ACTOR;
33
+ }
34
+ return { kind: 'user', id: as, ...(roles.length > 0 ? { roles } : {}) };
35
+ }
36
+ /**
37
+ * {@link baseEngineArgs} plus the instance-operation fields (everything
38
+ * but the client and the verb-specific fields). The `reason` is spread
39
+ * conditionally because the engine's optional field rejects an explicit
40
+ * `undefined` under `exactOptionalPropertyTypes`.
41
+ */
42
+ export function buildOperationArgs(config, instanceId, reason) {
43
+ return {
44
+ ...baseEngineArgs(config),
45
+ instanceId,
46
+ ...(reason !== undefined ? { reason } : {}),
47
+ };
48
+ }
@@ -0,0 +1,30 @@
1
+ import type { Ora } from 'ora';
2
+ /** A single engine primitive that ran during a write commit — the
3
+ * reportable subset of the engine's `OpAppliedSummary`. */
4
+ export interface RanOp {
5
+ opType: string;
6
+ target?: {
7
+ scope: string;
8
+ state: string;
9
+ };
10
+ }
11
+ /**
12
+ * The "ops applied" block shared by write-verb reports (move-stage,
13
+ * fire-action): a blank separator, a header, and one line per primitive
14
+ * that ran. Empty when nothing ran, so callers append it unconditionally.
15
+ */
16
+ export declare function opsAppliedLines(ranOps: RanOp[] | undefined): string[];
17
+ /** The spinner message + ops block a write verb prints once its engine
18
+ * call returns. {@link opsAppliedLines} builds `opsLines`. */
19
+ export interface WriteReport {
20
+ fired: boolean;
21
+ message: string;
22
+ opsLines: string[];
23
+ }
24
+ /**
25
+ * Emit a write-verb report through its spinner: warn and bail when the
26
+ * requested intent didn't fire, otherwise succeed and print the ops block.
27
+ * Shared by every write command so the fired / not-fired branches stay
28
+ * consistent.
29
+ */
30
+ export declare function emitWriteReport(spinner: Ora, report: WriteReport, log: (line: string) => void): void;
@@ -0,0 +1,28 @@
1
+ import logSymbols from 'log-symbols';
2
+ import pc from 'picocolors';
3
+ /**
4
+ * The "ops applied" block shared by write-verb reports (move-stage,
5
+ * fire-action): a blank separator, a header, and one line per primitive
6
+ * that ran. Empty when nothing ran, so callers append it unconditionally.
7
+ */
8
+ export function opsAppliedLines(ranOps) {
9
+ const details = (ranOps ?? []).map((op) => {
10
+ const target = op.target ? pc.dim(` → ${op.target.scope}.${op.target.state}`) : '';
11
+ return ` ${logSymbols.info} ${op.opType}${target}`;
12
+ });
13
+ return details.length > 0 ? ['', pc.dim('ops applied:'), ...details] : [];
14
+ }
15
+ /**
16
+ * Emit a write-verb report through its spinner: warn and bail when the
17
+ * requested intent didn't fire, otherwise succeed and print the ops block.
18
+ * Shared by every write command so the fired / not-fired branches stay
19
+ * consistent.
20
+ */
21
+ export function emitWriteReport(spinner, report, log) {
22
+ if (!report.fired) {
23
+ spinner.warn(report.message);
24
+ return;
25
+ }
26
+ spinner.succeed(report.message);
27
+ report.opsLines.forEach(log);
28
+ }
@@ -0,0 +1,10 @@
1
+ import { Command } from '@oclif/core';
2
+ /**
3
+ * Base class for commands that aren't wired to the engine yet. Parses
4
+ * the subclass's args + flags, then prints a "not yet implemented"
5
+ * banner plus the parsed inputs so the surface is testable end-to-end,
6
+ * and exits non-zero — a stub must never report success to a caller.
7
+ */
8
+ export declare abstract class StubCommand extends Command {
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,24 @@
1
+ import { Command } from '@oclif/core';
2
+ import boxen from 'boxen';
3
+ import logSymbols from 'log-symbols';
4
+ /**
5
+ * Base class for commands that aren't wired to the engine yet. Parses
6
+ * the subclass's args + flags, then prints a "not yet implemented"
7
+ * banner plus the parsed inputs so the surface is testable end-to-end,
8
+ * and exits non-zero — a stub must never report success to a caller.
9
+ */
10
+ export class StubCommand extends Command {
11
+ async run() {
12
+ // `this.parse()` with no args picks up the subclass's static metadata.
13
+ const parsed = await this.parse(this.ctor);
14
+ const body = [
15
+ `${logSymbols.warning} not yet implemented`,
16
+ '',
17
+ `command: ${this.ctor.id ?? this.constructor.name}`,
18
+ `args: ${JSON.stringify(parsed.args)}`,
19
+ `flags: ${JSON.stringify(parsed.flags)}`,
20
+ ].join('\n');
21
+ this.log(boxen(body, { padding: 1, borderStyle: 'round', borderColor: 'yellow' }));
22
+ this.exit(1);
23
+ }
24
+ }