@sanity/runtime-cli 14.12.1 → 14.13.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/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
20
20
  $ sanity-run COMMAND
21
21
  running command...
22
22
  $ sanity-run (--version)
23
- @sanity/runtime-cli/14.12.1 linux-x64 node-v24.14.1
23
+ @sanity/runtime-cli/14.13.0 linux-x64 node-v24.14.1
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -101,7 +101,7 @@ EXAMPLES
101
101
  $ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
102
102
  ```
103
103
 
104
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/blueprints/add.ts)_
104
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/add.ts)_
105
105
 
106
106
  ## `sanity-run blueprints config`
107
107
 
@@ -140,7 +140,7 @@ EXAMPLES
140
140
  $ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
141
141
  ```
142
142
 
143
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/blueprints/config.ts)_
143
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/config.ts)_
144
144
 
145
145
  ## `sanity-run blueprints deploy`
146
146
 
@@ -182,7 +182,7 @@ EXAMPLES
182
182
  $ sanity-run blueprints deploy --fn-installer npm
183
183
  ```
184
184
 
185
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/blueprints/deploy.ts)_
185
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/deploy.ts)_
186
186
 
187
187
  ## `sanity-run blueprints destroy`
188
188
 
@@ -218,7 +218,7 @@ EXAMPLES
218
218
  $ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
219
219
  ```
220
220
 
221
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/blueprints/destroy.ts)_
221
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/destroy.ts)_
222
222
 
223
223
  ## `sanity-run blueprints doctor`
224
224
 
@@ -250,7 +250,7 @@ EXAMPLES
250
250
  $ sanity-run blueprints doctor --fix
251
251
  ```
252
252
 
253
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/blueprints/doctor.ts)_
253
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/doctor.ts)_
254
254
 
255
255
  ## `sanity-run blueprints info`
256
256
 
@@ -285,7 +285,7 @@ EXAMPLES
285
285
  $ sanity-run blueprints info --project-id <id> --stack <name-or-id>
286
286
  ```
287
287
 
288
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/blueprints/info.ts)_
288
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/info.ts)_
289
289
 
290
290
  ## `sanity-run blueprints init [DIR]`
291
291
 
@@ -338,7 +338,7 @@ EXAMPLES
338
338
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
339
339
  ```
340
340
 
341
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/blueprints/init.ts)_
341
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/init.ts)_
342
342
 
343
343
  ## `sanity-run blueprints logs`
344
344
 
@@ -369,7 +369,7 @@ EXAMPLES
369
369
  $ sanity-run blueprints logs --watch
370
370
  ```
371
371
 
372
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/blueprints/logs.ts)_
372
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/logs.ts)_
373
373
 
374
374
  ## `sanity-run blueprints plan`
375
375
 
@@ -397,7 +397,7 @@ EXAMPLES
397
397
  $ sanity-run blueprints plan
398
398
  ```
399
399
 
400
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/blueprints/plan.ts)_
400
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/plan.ts)_
401
401
 
402
402
  ## `sanity-run blueprints stacks`
403
403
 
@@ -405,9 +405,11 @@ List remote Stack deployments for your project or organization
405
405
 
406
406
  ```
407
407
  USAGE
408
- $ sanity-run blueprints stacks [--json] [--validate-resources] [--project-id <value> | --organization-id <value>]
408
+ $ sanity-run blueprints stacks [--json] [--validate-resources] [--project-id <value> | --organization-id <value> |
409
+ --include-projects]
409
410
 
410
411
  FLAGS
412
+ --include-projects Include Stacks from all projects within the organization. Requires --organization-id.
411
413
  --json Format output as json
412
414
  --organization-id=<value> Sanity organization ID used to scope Blueprint and Stack
413
415
  --project-id=<value> Sanity project ID used to scope Blueprint and Stack
@@ -421,15 +423,19 @@ DESCRIPTION
421
423
  Use this to discover existing Stacks you can scope a local Blueprint to (using 'blueprints config --edit'), or to
422
424
  audit what's deployed across your project.
423
425
 
426
+ Use --include-projects with --organization-id to also list Stacks from all projects within the organization.
427
+
424
428
  EXAMPLES
425
429
  $ sanity-run blueprints stacks
426
430
 
427
431
  $ sanity-run blueprints stacks --project-id <projectId>
428
432
 
429
433
  $ sanity-run blueprints stacks --organization-id <organizationId>
434
+
435
+ $ sanity-run blueprints stacks --organization-id <organizationId> --include-projects
430
436
  ```
431
437
 
432
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/blueprints/stacks.ts)_
438
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/stacks.ts)_
433
439
 
434
440
  ## `sanity-run functions add`
435
441
 
@@ -482,7 +488,7 @@ EXAMPLES
482
488
  $ sanity-run functions add --name my-function --type document-create --type document-update --lang js
483
489
  ```
484
490
 
485
- _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/functions/add.ts)_
491
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/add.ts)_
486
492
 
487
493
  ## `sanity-run functions dev`
488
494
 
@@ -518,7 +524,7 @@ EXAMPLES
518
524
  $ sanity-run functions dev --timeout 60
519
525
  ```
520
526
 
521
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/functions/dev.ts)_
527
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/dev.ts)_
522
528
 
523
529
  ## `sanity-run functions env add NAME KEY VALUE`
524
530
 
@@ -549,7 +555,7 @@ EXAMPLES
549
555
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
550
556
  ```
551
557
 
552
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/functions/env/add.ts)_
558
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/env/add.ts)_
553
559
 
554
560
  ## `sanity-run functions env list NAME`
555
561
 
@@ -577,7 +583,7 @@ EXAMPLES
577
583
  $ sanity-run functions env list MyFunction
578
584
  ```
579
585
 
580
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/functions/env/list.ts)_
586
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/env/list.ts)_
581
587
 
582
588
  ## `sanity-run functions env remove NAME KEY`
583
589
 
@@ -607,7 +613,7 @@ EXAMPLES
607
613
  $ sanity-run functions env remove MyFunction API_URL
608
614
  ```
609
615
 
610
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/functions/env/remove.ts)_
616
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/env/remove.ts)_
611
617
 
612
618
  ## `sanity-run functions logs [NAME]`
613
619
 
@@ -649,7 +655,7 @@ EXAMPLES
649
655
  $ sanity-run functions logs <name> --delete
650
656
  ```
651
657
 
652
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/functions/logs.ts)_
658
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/logs.ts)_
653
659
 
654
660
  ## `sanity-run functions test [NAME]`
655
661
 
@@ -707,7 +713,7 @@ EXAMPLES
707
713
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
708
714
  ```
709
715
 
710
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.12.1/src/commands/functions/test.ts)_
716
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/test.ts)_
711
717
 
712
718
  ## `sanity-run help [COMMAND]`
713
719
 
@@ -17,8 +17,9 @@ export interface Project {
17
17
  interface ListProjectsResponse extends ActionResponse {
18
18
  projects: Project[];
19
19
  }
20
- export declare function listProjects({ token, logger, }: {
20
+ export declare function listProjects({ token, organizationId, logger, }: {
21
21
  token: string;
22
+ organizationId?: string;
22
23
  logger: Logger;
23
24
  }): Promise<ListProjectsResponse>;
24
25
  interface GroupedProjectsByOrganizationResponse extends ActionResponse {
@@ -3,9 +3,12 @@ import { createTracedFetch } from '../../utils/traced-fetch.js';
3
3
  const { populusApiUrl } = config;
4
4
  export const projectsApiPath = `${populusApiUrl}v2021-06-07/projects`;
5
5
  export const orgsApiPath = `${populusApiUrl}v2021-06-07/organizations`;
6
- export async function listProjects({ token, logger, }) {
6
+ export async function listProjects({ token, organizationId, logger, }) {
7
7
  const fetchFn = createTracedFetch(logger);
8
- const projectsFetch = await fetchFn(projectsApiPath, {
8
+ const url = organizationId
9
+ ? `${projectsApiPath}?organizationId=${encodeURIComponent(organizationId)}`
10
+ : projectsApiPath;
11
+ const projectsFetch = await fetchFn(url, {
9
12
  method: 'GET',
10
13
  headers: {
11
14
  Authorization: `Bearer ${token}`,
@@ -7,6 +7,7 @@ export default class StacksCommand extends ResolvedCommand<typeof StacksCommand>
7
7
  static flags: {
8
8
  'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
9
  'organization-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'include-projects': import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
11
  };
11
12
  run(): Promise<Record<string, unknown> | undefined>;
12
13
  }
@@ -7,15 +7,25 @@ export default class StacksCommand extends ResolvedCommand {
7
7
  static summary = 'List remote Stack deployments for your project or organization';
8
8
  static description = `Shows all Stacks associated with a project or organization. By default, lists Stacks scoped to the local Blueprint.
9
9
 
10
- Use this to discover existing Stacks you can scope a local Blueprint to (using 'blueprints config --edit'), or to audit what's deployed across your project.`;
10
+ Use this to discover existing Stacks you can scope a local Blueprint to (using 'blueprints config --edit'), or to audit what's deployed across your project.
11
+
12
+ Use --include-projects with --organization-id to also list Stacks from all projects within the organization.`;
11
13
  static examples = [
12
14
  '<%= config.bin %> <%= command.id %>',
13
15
  '<%= config.bin %> <%= command.id %> --project-id <projectId>',
14
16
  '<%= config.bin %> <%= command.id %> --organization-id <organizationId>',
17
+ '<%= config.bin %> <%= command.id %> --organization-id <organizationId> --include-projects',
15
18
  ];
16
19
  static flags = {
17
- 'project-id': Flags.string({ ...projectIdFlagConfig, exclusive: ['organization-id'] }),
20
+ 'project-id': Flags.string({
21
+ ...projectIdFlagConfig,
22
+ exclusive: ['organization-id', 'include-projects'],
23
+ }),
18
24
  'organization-id': Flags.string({ ...organizationIdFlagConfig, exclusive: ['project-id'] }),
25
+ 'include-projects': Flags.boolean({
26
+ description: 'Include Stacks from all projects within the organization. Requires --organization-id.',
27
+ dependsOn: ['organization-id'],
28
+ }),
19
29
  };
20
30
  async run() {
21
31
  const result = await blueprintStacksCore({
@@ -3,6 +3,7 @@ export interface BlueprintStacksOptions extends BlueprintConfig {
3
3
  flags: {
4
4
  'project-id'?: string;
5
5
  'organization-id'?: string;
6
+ 'include-projects'?: boolean;
6
7
  verbose?: boolean;
7
8
  };
8
9
  }
@@ -1,11 +1,14 @@
1
1
  import { listStacks } from '../../actions/blueprints/stacks.js';
2
+ import { listProjects } from '../../actions/sanity/projects.js';
2
3
  import { formatStacksListing } from '../../utils/display/blueprints-formatting.js';
3
- import { capitalize, niceId } from '../../utils/display/presenters.js';
4
+ import { capitalize, niceId, warn } from '../../utils/display/presenters.js';
4
5
  import { styleText } from '../../utils/style-text.js';
6
+ /** Max projects to query for stacks during --include-projects */
7
+ const PROJECT_LIMIT = 50;
5
8
  export async function blueprintStacksCore(options) {
6
9
  const { log, token, blueprint, flags } = options;
7
10
  const { scopeType: blueprintScopeType, scopeId: blueprintScopeId, stackId: blueprintStackId, } = blueprint;
8
- const { 'project-id': flagProjectId, 'organization-id': flagOrganizationId, verbose: _verbose = false, } = flags;
11
+ const { 'project-id': flagProjectId, 'organization-id': flagOrganizationId, 'include-projects': includeProjects = false, verbose: _verbose = false, } = flags;
9
12
  if (flagOrganizationId && flagProjectId) {
10
13
  log.error('Cannot specify both --organization-id and --project-id');
11
14
  return { success: false, error: 'Cannot specify both --organization-id and --project-id' };
@@ -27,6 +30,9 @@ export async function blueprintStacksCore(options) {
27
30
  suggestions: ['Run in a Blueprint directory or provide a project with --project-id.'],
28
31
  };
29
32
  }
33
+ if (includeProjects && scopeType === 'organization') {
34
+ return deepListStacks({ organizationId: scopeId, token, log, blueprintStackId });
35
+ }
30
36
  try {
31
37
  const spinner = log.ora('Fetching Stacks...').start();
32
38
  const { ok, stacks, error } = await listStacks({ token, scopeType, scopeId }, log);
@@ -57,3 +63,68 @@ export async function blueprintStacksCore(options) {
57
63
  return { success: false, error: errorMessage };
58
64
  }
59
65
  }
66
+ async function deepListStacks(options) {
67
+ const { organizationId, token, log, blueprintStackId } = options;
68
+ const allStacks = [];
69
+ const spinner = log.ora('Fetching Stacks...').start();
70
+ try {
71
+ // 1. Org-scoped stacks
72
+ const orgResult = await listStacks({ token, scopeType: 'organization', scopeId: organizationId }, log);
73
+ const orgStacks = orgResult.ok ? orgResult.stacks : [];
74
+ // 2. Get projects in the organization
75
+ const projectsResult = await listProjects({ token, organizationId, logger: log });
76
+ if (!projectsResult.ok) {
77
+ spinner.fail('Failed to list projects');
78
+ return { success: false, error: projectsResult.error || 'Failed to list projects' };
79
+ }
80
+ const projects = projectsResult.projects;
81
+ const totalProjects = projects.length;
82
+ const cappedProjects = projects.slice(0, PROJECT_LIMIT);
83
+ // 3. Fetch stacks for each project
84
+ const projectGroups = [];
85
+ for (let i = 0; i < cappedProjects.length; i++) {
86
+ const project = cappedProjects[i];
87
+ spinner.text = `Fetching Stacks... (project ${i + 1}/${cappedProjects.length})`;
88
+ const result = await listStacks({ token, scopeType: 'project', scopeId: project.id }, log);
89
+ if (result.ok && result.stacks.length > 0) {
90
+ projectGroups.push({
91
+ projectId: project.id,
92
+ displayName: project.displayName,
93
+ stacks: result.stacks,
94
+ });
95
+ allStacks.push(...result.stacks);
96
+ }
97
+ }
98
+ spinner.stop().clear();
99
+ // 4. Print results
100
+ if (orgStacks.length > 0) {
101
+ log(`${styleText('bold', 'Organization')} ${niceId(organizationId)} ${styleText('bold', 'Stacks')}:\n`);
102
+ log(formatStacksListing(orgStacks, blueprintStackId));
103
+ if (projectGroups.length > 0)
104
+ log(''); // blank line between sections
105
+ }
106
+ for (const group of projectGroups) {
107
+ log(`${styleText('bold', 'Project')} "${group.displayName}" ${niceId(group.projectId)} ${styleText('bold', 'Stacks')}:`);
108
+ log(formatStacksListing(group.stacks, blueprintStackId));
109
+ log('');
110
+ }
111
+ if (totalProjects > PROJECT_LIMIT) {
112
+ log(warn(`Organization has ${totalProjects} projects, only checked the first ${PROJECT_LIMIT}.`));
113
+ }
114
+ if (orgStacks.length === 0 && allStacks.length === 0) {
115
+ log('No stacks found');
116
+ return { success: true };
117
+ }
118
+ allStacks.push(...orgStacks);
119
+ return {
120
+ success: true,
121
+ json: { stacks: allStacks, scopeType: 'organization', scopeId: organizationId },
122
+ };
123
+ }
124
+ catch (error) {
125
+ spinner.stop().clear();
126
+ const errorMessage = error instanceof Error ? error.message : String(error);
127
+ log.error(`Error: ${errorMessage}`);
128
+ return { success: false, error: errorMessage };
129
+ }
130
+ }
@@ -1289,11 +1289,12 @@
1289
1289
  "blueprints:stacks": {
1290
1290
  "aliases": [],
1291
1291
  "args": {},
1292
- "description": "Shows all Stacks associated with a project or organization. By default, lists Stacks scoped to the local Blueprint.\n\nUse this to discover existing Stacks you can scope a local Blueprint to (using 'blueprints config --edit'), or to audit what's deployed across your project.",
1292
+ "description": "Shows all Stacks associated with a project or organization. By default, lists Stacks scoped to the local Blueprint.\n\nUse this to discover existing Stacks you can scope a local Blueprint to (using 'blueprints config --edit'), or to audit what's deployed across your project.\n\nUse --include-projects with --organization-id to also list Stacks from all projects within the organization.",
1293
1293
  "examples": [
1294
1294
  "<%= config.bin %> <%= command.id %>",
1295
1295
  "<%= config.bin %> <%= command.id %> --project-id <projectId>",
1296
- "<%= config.bin %> <%= command.id %> --organization-id <organizationId>"
1296
+ "<%= config.bin %> <%= command.id %> --organization-id <organizationId>",
1297
+ "<%= config.bin %> <%= command.id %> --organization-id <organizationId> --include-projects"
1297
1298
  ],
1298
1299
  "flags": {
1299
1300
  "json": {
@@ -1350,7 +1351,8 @@
1350
1351
  ],
1351
1352
  "description": "Sanity project ID used to scope Blueprint and Stack",
1352
1353
  "exclusive": [
1353
- "organization-id"
1354
+ "organization-id",
1355
+ "include-projects"
1354
1356
  ],
1355
1357
  "name": "project-id",
1356
1358
  "hasDynamicHelp": false,
@@ -1371,6 +1373,15 @@
1371
1373
  "hasDynamicHelp": false,
1372
1374
  "multiple": false,
1373
1375
  "type": "option"
1376
+ },
1377
+ "include-projects": {
1378
+ "dependsOn": [
1379
+ "organization-id"
1380
+ ],
1381
+ "description": "Include Stacks from all projects within the organization. Requires --organization-id.",
1382
+ "name": "include-projects",
1383
+ "allowNo": false,
1384
+ "type": "boolean"
1374
1385
  }
1375
1386
  },
1376
1387
  "hasDynamicHelp": false,
@@ -2677,5 +2688,5 @@
2677
2688
  ]
2678
2689
  }
2679
2690
  },
2680
- "version": "14.12.1"
2691
+ "version": "14.13.0"
2681
2692
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sanity/runtime-cli",
3
3
  "description": "Sanity's Runtime CLI for Blueprints and Functions",
4
- "version": "14.12.1",
4
+ "version": "14.13.0",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",