@sanity/runtime-cli 14.8.5 → 14.9.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 (50) hide show
  1. package/README.md +35 -30
  2. package/dist/actions/blueprints/blueprint.d.ts +4 -0
  3. package/dist/actions/blueprints/blueprint.js +6 -0
  4. package/dist/baseCommands.d.ts +21 -8
  5. package/dist/baseCommands.js +54 -15
  6. package/dist/commands/blueprints/add.js +3 -3
  7. package/dist/commands/blueprints/config.js +4 -4
  8. package/dist/commands/blueprints/deploy.js +5 -5
  9. package/dist/commands/blueprints/destroy.js +5 -5
  10. package/dist/commands/blueprints/doctor.d.ts +1 -1
  11. package/dist/commands/blueprints/doctor.js +7 -5
  12. package/dist/commands/blueprints/info.js +5 -5
  13. package/dist/commands/blueprints/init.js +4 -4
  14. package/dist/commands/blueprints/logs.js +6 -6
  15. package/dist/commands/blueprints/plan.js +5 -5
  16. package/dist/commands/blueprints/promote.js +8 -6
  17. package/dist/commands/blueprints/stacks.js +5 -5
  18. package/dist/commands/functions/add.js +3 -3
  19. package/dist/commands/functions/build.js +4 -4
  20. package/dist/commands/functions/dev.js +5 -5
  21. package/dist/commands/functions/env/add.js +4 -4
  22. package/dist/commands/functions/env/list.js +4 -4
  23. package/dist/commands/functions/env/remove.js +4 -4
  24. package/dist/commands/functions/logs.js +4 -4
  25. package/dist/commands/functions/test.js +4 -4
  26. package/dist/constants.d.ts +1 -0
  27. package/dist/constants.js +1 -0
  28. package/dist/cores/blueprints/config.js +0 -1
  29. package/dist/cores/blueprints/deploy.js +44 -12
  30. package/dist/cores/blueprints/destroy.js +18 -3
  31. package/dist/cores/blueprints/doctor.js +9 -2
  32. package/dist/cores/blueprints/plan.js +21 -13
  33. package/dist/cores/blueprints/promote.js +11 -3
  34. package/dist/cores/blueprints/stacks.js +14 -3
  35. package/dist/cores/functions/add.js +1 -1
  36. package/dist/cores/functions/build.js +3 -5
  37. package/dist/cores/functions/logs.js +1 -1
  38. package/dist/cores/functions/test.js +10 -5
  39. package/dist/cores/index.d.ts +6 -0
  40. package/dist/cores/index.js +0 -3
  41. package/dist/server/handlers/invoke.js +3 -3
  42. package/dist/utils/display/blueprints-formatting.js +2 -1
  43. package/dist/utils/display/resources-formatting.js +8 -3
  44. package/dist/utils/find-function.d.ts +7 -6
  45. package/dist/utils/find-function.js +5 -3
  46. package/dist/utils/functions/detect-native-modules.js +5 -1
  47. package/dist/utils/invoke-local.js +1 -1
  48. package/dist/utils/types.d.ts +3 -3
  49. package/oclif.manifest.json +13 -10
  50. package/package.json +2 -2
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.8.5 linux-x64 node-v24.14.1
23
+ @sanity/runtime-cli/14.9.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.8.5/src/commands/blueprints/add.ts)_
104
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.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.8.5/src/commands/blueprints/config.ts)_
143
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/blueprints/config.ts)_
144
144
 
145
145
  ## `sanity-run blueprints deploy`
146
146
 
@@ -159,8 +159,8 @@ FLAGS
159
159
  DESCRIPTION
160
160
  Deploy the local Blueprint to the remote Stack
161
161
 
162
- Pushes your local Blueprint configuration to the remote Stack; provisioning, updating, or destroying resources as
163
- needed. This is the primary command for applying infrastructure changes.
162
+ Applies your local Blueprint to the remote Stack, creating, updating, or removing resources as needed. This is the
163
+ primary command for applying infrastructure changes.
164
164
 
165
165
  Before deploying, run 'blueprints plan' to preview changes. After deployment, use 'blueprints info' to verify Stack
166
166
  status or 'blueprints logs' to monitor activity.
@@ -179,11 +179,11 @@ EXAMPLES
179
179
  $ sanity-run blueprints deploy --fn-installer npm
180
180
  ```
181
181
 
182
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/blueprints/deploy.ts)_
182
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/blueprints/deploy.ts)_
183
183
 
184
184
  ## `sanity-run blueprints destroy`
185
185
 
186
- Destroy the remote Stack deployment and its resources (will not delete local files)
186
+ Destroy a remote Stack deployment and its resources
187
187
 
188
188
  ```
189
189
  USAGE
@@ -200,7 +200,7 @@ FLAGS
200
200
  --[no-]validate-resources Validate resources
201
201
 
202
202
  DESCRIPTION
203
- Destroy the remote Stack deployment and its resources (will not delete local files)
203
+ Destroy a remote Stack deployment and its resources
204
204
 
205
205
  Permanently removes the remote Stack and all its provisioned resources. Your local Blueprint files remain untouched,
206
206
  allowing you to redeploy later with 'blueprints init' + 'blueprints deploy'.
@@ -215,7 +215,7 @@ EXAMPLES
215
215
  $ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
216
216
  ```
217
217
 
218
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/blueprints/destroy.ts)_
218
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/blueprints/destroy.ts)_
219
219
 
220
220
  ## `sanity-run blueprints doctor`
221
221
 
@@ -240,13 +240,18 @@ DESCRIPTION
240
240
 
241
241
  Run this command when encountering errors with other Blueprint commands. Use --fix to interactively resolve detected
242
242
  issues.
243
+
244
+ EXAMPLES
245
+ $ sanity-run blueprints doctor
246
+
247
+ $ sanity-run blueprints doctor --fix
243
248
  ```
244
249
 
245
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/blueprints/doctor.ts)_
250
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/blueprints/doctor.ts)_
246
251
 
247
252
  ## `sanity-run blueprints info`
248
253
 
249
- Show information about the local Blueprint's remote Stack deployment
254
+ Display the status and resources of the remote Stack deployment
250
255
 
251
256
  ```
252
257
  USAGE
@@ -258,7 +263,7 @@ FLAGS
258
263
  --[no-]validate-resources Validate resources
259
264
 
260
265
  DESCRIPTION
261
- Show information about the local Blueprint's remote Stack deployment
266
+ Display the status and resources of the remote Stack deployment
262
267
 
263
268
  Displays the current state and metadata of your remote Stack deployment, including deployed resources, status, and
264
269
  configuration.
@@ -274,11 +279,11 @@ EXAMPLES
274
279
  $ sanity-run blueprints info --stack <name-or-id>
275
280
  ```
276
281
 
277
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/blueprints/info.ts)_
282
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/blueprints/info.ts)_
278
283
 
279
284
  ## `sanity-run blueprints init [DIR]`
280
285
 
281
- Initialize a local Blueprint and optionally provision a remote Stack deployment
286
+ Initialize a Blueprint and create a remote Stack
282
287
 
283
288
  ```
284
289
  USAGE
@@ -303,7 +308,7 @@ FLAGS
303
308
  --verbose Verbose output
304
309
 
305
310
  DESCRIPTION
306
- Initialize a local Blueprint and optionally provision a remote Stack deployment
311
+ Initialize a Blueprint and create a remote Stack
307
312
 
308
313
  A Blueprint is your local infrastructure-as-code configuration that defines Sanity resources (datasets, functions,
309
314
  etc.). A Stack is the remote deployment target where your Blueprint is applied.
@@ -328,7 +333,7 @@ EXAMPLES
328
333
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
329
334
  ```
330
335
 
331
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/blueprints/init.ts)_
336
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/blueprints/init.ts)_
332
337
 
333
338
  ## `sanity-run blueprints logs`
334
339
 
@@ -359,11 +364,11 @@ EXAMPLES
359
364
  $ sanity-run blueprints logs --watch
360
365
  ```
361
366
 
362
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/blueprints/logs.ts)_
367
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/blueprints/logs.ts)_
363
368
 
364
369
  ## `sanity-run blueprints plan`
365
370
 
366
- Enumerate resources to be deployed to the remote Stack - will not modify any resources
371
+ Preview changes that will be applied to the remote Stack
367
372
 
368
373
  ```
369
374
  USAGE
@@ -375,7 +380,7 @@ FLAGS
375
380
  --[no-]validate-resources Validate resources
376
381
 
377
382
  DESCRIPTION
378
- Enumerate resources to be deployed to the remote Stack - will not modify any resources
383
+ Preview changes that will be applied to the remote Stack
379
384
 
380
385
  Use this command to preview what changes will be applied to your remote Stack before deploying. This is a safe,
381
386
  read-only operation—no resources are created, modified, or deleted.
@@ -387,11 +392,11 @@ EXAMPLES
387
392
  $ sanity-run blueprints plan
388
393
  ```
389
394
 
390
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/blueprints/plan.ts)_
395
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/blueprints/plan.ts)_
391
396
 
392
397
  ## `sanity-run blueprints stacks`
393
398
 
394
- List all remote Stack deployments (defaults to the current Blueprint's project scope)
399
+ List remote Stack deployments for your project or organization
395
400
 
396
401
  ```
397
402
  USAGE
@@ -404,7 +409,7 @@ FLAGS
404
409
  --[no-]validate-resources Validate resources
405
410
 
406
411
  DESCRIPTION
407
- List all remote Stack deployments (defaults to the current Blueprint's project scope)
412
+ List remote Stack deployments for your project or organization
408
413
 
409
414
  Shows all Stacks associated with a project or organization. By default, lists Stacks scoped to the local Blueprint.
410
415
 
@@ -419,7 +424,7 @@ EXAMPLES
419
424
  $ sanity-run blueprints stacks --organization-id <organizationId>
420
425
  ```
421
426
 
422
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/blueprints/stacks.ts)_
427
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/blueprints/stacks.ts)_
423
428
 
424
429
  ## `sanity-run functions add`
425
430
 
@@ -472,7 +477,7 @@ EXAMPLES
472
477
  $ sanity-run functions add --name my-function --type document-create --type document-update --lang js
473
478
  ```
474
479
 
475
- _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/functions/add.ts)_
480
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/functions/add.ts)_
476
481
 
477
482
  ## `sanity-run functions dev`
478
483
 
@@ -508,7 +513,7 @@ EXAMPLES
508
513
  $ sanity-run functions dev --timeout 60
509
514
  ```
510
515
 
511
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/functions/dev.ts)_
516
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/functions/dev.ts)_
512
517
 
513
518
  ## `sanity-run functions env add NAME KEY VALUE`
514
519
 
@@ -539,7 +544,7 @@ EXAMPLES
539
544
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
540
545
  ```
541
546
 
542
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/functions/env/add.ts)_
547
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/functions/env/add.ts)_
543
548
 
544
549
  ## `sanity-run functions env list NAME`
545
550
 
@@ -567,7 +572,7 @@ EXAMPLES
567
572
  $ sanity-run functions env list MyFunction
568
573
  ```
569
574
 
570
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/functions/env/list.ts)_
575
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/functions/env/list.ts)_
571
576
 
572
577
  ## `sanity-run functions env remove NAME KEY`
573
578
 
@@ -597,7 +602,7 @@ EXAMPLES
597
602
  $ sanity-run functions env remove MyFunction API_URL
598
603
  ```
599
604
 
600
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/functions/env/remove.ts)_
605
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/functions/env/remove.ts)_
601
606
 
602
607
  ## `sanity-run functions logs [NAME]`
603
608
 
@@ -639,7 +644,7 @@ EXAMPLES
639
644
  $ sanity-run functions logs <name> --delete
640
645
  ```
641
646
 
642
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/functions/logs.ts)_
647
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/functions/logs.ts)_
643
648
 
644
649
  ## `sanity-run functions test [NAME]`
645
650
 
@@ -697,7 +702,7 @@ EXAMPLES
697
702
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
698
703
  ```
699
704
 
700
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.5/src/commands/functions/test.ts)_
705
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.9.0/src/commands/functions/test.ts)_
701
706
 
702
707
  ## `sanity-run help [COMMAND]`
703
708
 
@@ -39,9 +39,13 @@ export type ConfigSource = 'config' | 'env' | 'module' | 'inferred';
39
39
  export interface ReadBlueprintResult {
40
40
  fileInfo: FileInfo;
41
41
  blueprintConfig: LocatedBlueprintsConfig | null;
42
+ /** The raw blueprint data as read from disk */
42
43
  rawBlueprint: Record<string, unknown>;
44
+ /** The blueprints-parser blueprint result */
43
45
  parsedBlueprint: Blueprint;
44
46
  errors: BlueprintParserError[];
47
+ /** Validated resources escaped from parser types */
48
+ resources: BlueprintResource[];
45
49
  /** @deprecated - use blueprintConfig.configPath instead */
46
50
  configPath?: string;
47
51
  scopeType?: ScopeType;
@@ -229,10 +229,16 @@ export async function readLocalBlueprint(logger, validate, blueprintPath) {
229
229
  errors.push(...validateResources(parsedBlueprint.resources));
230
230
  }
231
231
  }
232
+ // Ceremony to cross from parser's Resource type to BlueprintResource
233
+ // widen from the parser's Resource type assignable to BlueprintResource
234
+ const parserResources = parsedBlueprint?.resources ?? [];
235
+ // filter to valid resources typed as BlueprintResource
236
+ const validResources = parserResources.filter((r) => !!r.type);
232
237
  return {
233
238
  fileInfo: { blueprintFilePath: foundFilePath, fileName, extension },
234
239
  blueprintConfig,
235
240
  rawBlueprint,
241
+ resources: validResources,
236
242
  errors,
237
243
  scopeType,
238
244
  scopeId,
@@ -1,6 +1,7 @@
1
1
  import type { Interfaces } from '@oclif/core';
2
2
  import { Command } from '@oclif/core';
3
3
  import type { ReadBlueprintResult } from './actions/blueprints/blueprint.js';
4
+ import type { CoreResult } from './cores/index.js';
4
5
  import type { AuthParams, ScopeType, Stack } from './utils/types.js';
5
6
  export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof RuntimeCommand)['baseFlags'] & T['flags']>;
6
7
  export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
@@ -21,12 +22,12 @@ export declare const organizationIdFlagConfig: {
21
22
  aliases: string[];
22
23
  };
23
24
  /**
24
- * @description Unhides a flag by setting its hidden property to false
25
+ * Unhides a flag by setting its hidden property to false
25
26
  * Also makes oclif's types happy when destructuring the flag
26
27
  */
27
28
  export declare function unhide<T>(flag: T): T;
28
29
  /**
29
- * @description Guarantees flags and args.
30
+ * Guarantees flags and args.
30
31
  * Also centralizes baseFlags and enables oclif's built-in --json for all subclasses.
31
32
  * @extends Command
32
33
  */
@@ -50,9 +51,25 @@ export declare abstract class RuntimeCommand<T extends typeof Command> extends C
50
51
  */
51
52
  static getHelpText(bin?: string, commandId?: string): string;
52
53
  init(): Promise<void>;
54
+ /**
55
+ * Throws an oclif error from a failed CoreResult.
56
+ * forwarding suggestions, ref, or code to oclif's PrettyPrintableError rendering.
57
+ */
58
+ protected coreError(result: CoreResult & {
59
+ success: false;
60
+ }): never;
61
+ /**
62
+ * If an error doesn't have suggestions, match against known patterns to
63
+ * attach relevant suggestions before oclif renders the error.
64
+ *
65
+ * Add patterns to `CATCH_HINT_PATTERNS` as needed.
66
+ */
67
+ protected catch(err: Error & {
68
+ exitCode?: number;
69
+ }): Promise<unknown>;
53
70
  }
54
71
  /**
55
- * @description Guarantees flags, args, sanityToken, and blueprint.
72
+ * Guarantees flags, args, sanityToken, and blueprint.
56
73
  * Blueprint parser errors are logged and the command exits with an error
57
74
  * @extends RuntimeCommand
58
75
  */
@@ -67,13 +84,9 @@ export declare abstract class LocalBlueprintCommand<T extends typeof Command> ex
67
84
  verbose: Interfaces.BooleanFlag<boolean>;
68
85
  };
69
86
  init(): Promise<void>;
70
- protected catch(err: Error & {
71
- exitCode?: number;
72
- }): Promise<unknown>;
73
- protected finally(_: Error | undefined): Promise<unknown>;
74
87
  }
75
88
  /**
76
- * @description Guarantees flags, args, sanityToken, blueprint, scopeType, scopeId, stackId, auth, and deployedStack.
89
+ * Guarantees flags, args, sanityToken, blueprint, scopeType, scopeId, stackId, auth, and deployedStack.
77
90
  * If scope or stack is missing, the command exits with an error
78
91
  * @extends LocalBlueprintCommand
79
92
  */
@@ -2,6 +2,15 @@
2
2
  import { Command, CommandHelp, Flags as OclifFlags } from '@oclif/core';
3
3
  import { initBlueprintConfig, initDeployedBlueprintConfig } from './cores/index.js';
4
4
  import { Logger } from './utils/logger.js';
5
+ /**
6
+ * Fallback error-to-hint patterns for RuntimeCommand.catch().
7
+ * Each entry maps a regex to a function that returns suggestion strings.
8
+ * These only apply when the core did not set suggestions in the result.
9
+ */
10
+ const CATCH_HINT_PATTERNS = [
11
+ // Add patterns here as needed, for example:
12
+ // [/scope/i, (bin) => [`Run \`npx ${bin} blueprints promote\` to change the Stack scope.`]],
13
+ ];
5
14
  const hidden = true;
6
15
  export const baseFlags = {
7
16
  json: OclifFlags.boolean({
@@ -44,14 +53,14 @@ export const organizationIdFlagConfig = {
44
53
  aliases: ['organization', 'organizationId', 'org'],
45
54
  };
46
55
  /**
47
- * @description Unhides a flag by setting its hidden property to false
56
+ * Unhides a flag by setting its hidden property to false
48
57
  * Also makes oclif's types happy when destructuring the flag
49
58
  */
50
59
  export function unhide(flag) {
51
60
  return { ...flag, hidden: false };
52
61
  }
53
62
  /**
54
- * @description Guarantees flags and args.
63
+ * Guarantees flags and args.
55
64
  * Also centralizes baseFlags and enables oclif's built-in --json for all subclasses.
56
65
  * @extends Command
57
66
  */
@@ -115,9 +124,38 @@ export class RuntimeCommand extends Command {
115
124
  this.args = args;
116
125
  await super.init();
117
126
  }
127
+ /**
128
+ * Throws an oclif error from a failed CoreResult.
129
+ * forwarding suggestions, ref, or code to oclif's PrettyPrintableError rendering.
130
+ */
131
+ coreError(result) {
132
+ this.error(result.error, {
133
+ suggestions: result.suggestions,
134
+ ref: result.ref,
135
+ code: result.code,
136
+ });
137
+ }
138
+ /**
139
+ * If an error doesn't have suggestions, match against known patterns to
140
+ * attach relevant suggestions before oclif renders the error.
141
+ *
142
+ * Add patterns to `CATCH_HINT_PATTERNS` as needed.
143
+ */
144
+ async catch(err) {
145
+ const pErr = err;
146
+ if (!pErr.suggestions?.length) {
147
+ for (const [pattern, hints] of CATCH_HINT_PATTERNS) {
148
+ if (pattern.test(err.message)) {
149
+ pErr.suggestions = hints(this.config.bin);
150
+ break;
151
+ }
152
+ }
153
+ }
154
+ return super.catch(err);
155
+ }
118
156
  }
119
157
  /**
120
- * @description Guarantees flags, args, sanityToken, and blueprint.
158
+ * Guarantees flags, args, sanityToken, and blueprint.
121
159
  * Blueprint parser errors are logged and the command exits with an error
122
160
  * @extends RuntimeCommand
123
161
  */
@@ -134,23 +172,22 @@ export class LocalBlueprintCommand extends RuntimeCommand {
134
172
  blueprintPath: this.flags.path,
135
173
  });
136
174
  if (!result.ok) {
137
- this.error(result.error);
175
+ const suggestions = [];
176
+ if (/token|login/i.test(result.error)) {
177
+ suggestions.push('Run `npx @sanity/cli login` to authenticate.');
178
+ }
179
+ else if (/blueprint/i.test(result.error) && /error/i.test(result.error)) {
180
+ suggestions.push('Fix the Blueprint errors listed above.');
181
+ }
182
+ suggestions.push(`Run \`${this.config.bin} blueprints doctor\` to check your configuration.`);
183
+ this.error(result.error, { suggestions });
138
184
  }
139
185
  this.sanityToken = result.value.token;
140
186
  this.blueprint = result.value.blueprint;
141
187
  }
142
- async catch(err) {
143
- // add any custom logic to handle errors from the command
144
- // or simply return the parent class error handling
145
- return super.catch(err);
146
- }
147
- async finally(_) {
148
- // called after run and catch regardless of whether or not the command errored
149
- return super.finally(_);
150
- }
151
188
  }
152
189
  /**
153
- * @description Guarantees flags, args, sanityToken, blueprint, scopeType, scopeId, stackId, auth, and deployedStack.
190
+ * Guarantees flags, args, sanityToken, blueprint, scopeType, scopeId, stackId, auth, and deployedStack.
154
191
  * If scope or stack is missing, the command exits with an error
155
192
  * @extends LocalBlueprintCommand
156
193
  */
@@ -173,7 +210,9 @@ export class DeployedStackCommand extends LocalBlueprintCommand {
173
210
  stackOverride: this.flags.stack,
174
211
  });
175
212
  if (!result.ok) {
176
- this.error(result.error);
213
+ this.error(result.error, {
214
+ suggestions: [`Run \`${this.config.bin} blueprints doctor\` to check your configuration.`],
215
+ });
177
216
  }
178
217
  this.scopeType = result.value.scopeType;
179
218
  this.scopeId = result.value.scopeId;
@@ -88,7 +88,7 @@ After adding a function, use 'functions dev' to test locally, then 'blueprints d
88
88
  // `\`npx ${bin} blueprints add function\` is deprecated. Use \`npx ${bin} functions add\` instead.`,
89
89
  // ),
90
90
  // )
91
- const { success, error } = await functionAddCore({
91
+ const result = await functionAddCore({
92
92
  bin,
93
93
  log: Logger(this.log.bind(this), this.flags),
94
94
  blueprint,
@@ -104,7 +104,7 @@ After adding a function, use 'functions dev' to test locally, then 'blueprints d
104
104
  install: flags.install,
105
105
  },
106
106
  });
107
- if (!success)
108
- this.error(error);
107
+ if (!result.success)
108
+ this.coreError(result);
109
109
  }
110
110
  }
@@ -30,7 +30,7 @@ If you need to switch your Blueprint to a different Stack, use --edit --stack.`;
30
30
  }),
31
31
  };
32
32
  async run() {
33
- const { success, error, json } = await blueprintConfigCore({
33
+ const result = await blueprintConfigCore({
34
34
  bin: this.config.bin,
35
35
  log: Logger(this.log.bind(this), this.flags),
36
36
  blueprint: this.blueprint,
@@ -38,8 +38,8 @@ If you need to switch your Blueprint to a different Stack, use --edit --stack.`;
38
38
  validateResources: this.flags['validate-resources'],
39
39
  flags: this.flags,
40
40
  });
41
- if (!success)
42
- this.error(error);
43
- return json;
41
+ if (!result.success)
42
+ this.coreError(result);
43
+ return result.json;
44
44
  }
45
45
  }
@@ -5,7 +5,7 @@ import { Logger } from '../../utils/logger.js';
5
5
  import { INSTALLER_OPTIONS } from '../../utils/types.js';
6
6
  export default class DeployCommand extends DeployedStackCommand {
7
7
  static summary = 'Deploy the local Blueprint to the remote Stack';
8
- static description = `Pushes your local Blueprint configuration to the remote Stack; provisioning, updating, or destroying resources as needed. This is the primary command for applying infrastructure changes.
8
+ static description = `Applies your local Blueprint to the remote Stack, creating, updating, or removing resources as needed. This is the primary command for applying infrastructure changes.
9
9
 
10
10
  Before deploying, run 'blueprints plan' to preview changes. After deployment, use 'blueprints info' to verify Stack status or 'blueprints logs' to monitor activity.
11
11
 
@@ -37,7 +37,7 @@ Set SANITY_ASSET_TIMEOUT (seconds) to override the 60-second timeout for process
37
37
  }),
38
38
  };
39
39
  async run() {
40
- const { success, error, json } = await blueprintDeployCore({
40
+ const result = await blueprintDeployCore({
41
41
  bin: this.config.bin,
42
42
  log: Logger(this.log.bind(this), this.flags),
43
43
  auth: this.auth,
@@ -49,8 +49,8 @@ Set SANITY_ASSET_TIMEOUT (seconds) to override the 60-second timeout for process
49
49
  validateResources: this.flags['validate-resources'],
50
50
  flags: this.flags,
51
51
  });
52
- if (!success)
53
- this.error(error);
54
- return json;
52
+ if (!result.success)
53
+ this.coreError(result);
54
+ return result.json;
55
55
  }
56
56
  }
@@ -3,7 +3,7 @@ import { LocalBlueprintCommand, organizationIdFlagConfig, projectIdFlagConfig, }
3
3
  import { blueprintDestroyCore } from '../../cores/blueprints/destroy.js';
4
4
  import { Logger } from '../../utils/logger.js';
5
5
  export default class DestroyCommand extends LocalBlueprintCommand {
6
- static summary = 'Destroy the remote Stack deployment and its resources (will not delete local files)';
6
+ static summary = 'Destroy a remote Stack deployment and its resources';
7
7
  static description = `Permanently removes the remote Stack and all its provisioned resources. Your local Blueprint files remain untouched, allowing you to redeploy later with 'blueprints init' + 'blueprints deploy'.
8
8
 
9
9
  This is a destructive operation. You will be prompted to confirm unless --force is specified.
@@ -39,7 +39,7 @@ Use this to clean up test environments or decommission a Stack you no longer nee
39
39
  }),
40
40
  };
41
41
  async run() {
42
- const { success, error, json } = await blueprintDestroyCore({
42
+ const result = await blueprintDestroyCore({
43
43
  bin: this.config.bin,
44
44
  log: Logger(this.log.bind(this), this.flags),
45
45
  token: this.sanityToken,
@@ -47,8 +47,8 @@ Use this to clean up test environments or decommission a Stack you no longer nee
47
47
  validateResources: this.flags['validate-resources'],
48
48
  flags: this.flags,
49
49
  });
50
- if (!success)
51
- this.error(error);
52
- return json;
50
+ if (!result.success)
51
+ this.coreError(result);
52
+ return result.json;
53
53
  }
54
54
  }
@@ -2,7 +2,7 @@ import { RuntimeCommand } from '../../baseCommands.js';
2
2
  export default class DoctorCommand extends RuntimeCommand<typeof DoctorCommand> {
3
3
  static summary: string;
4
4
  static description: string;
5
- static examples: never[];
5
+ static examples: string[];
6
6
  static flags: {
7
7
  path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
8
  fix: import("@oclif/core/interfaces").BooleanFlag<boolean>;
@@ -9,7 +9,10 @@ export default class DoctorCommand extends RuntimeCommand {
9
9
 
10
10
  Run this command when encountering errors with other Blueprint commands. Use --fix to interactively resolve detected issues.`;
11
11
  // TODO: add "Supports --json for programmatic consumption of diagnostic results." to help text
12
- static examples = [];
12
+ static examples = [
13
+ '<%= config.bin %> <%= command.id %>',
14
+ '<%= config.bin %> <%= command.id %> --fix',
15
+ ];
13
16
  static flags = {
14
17
  path: unhide(baseFlags.path),
15
18
  fix: Flags.boolean({
@@ -32,9 +35,8 @@ Run this command when encountering errors with other Blueprint commands. Use --f
32
35
  validateResources: this.flags['validate-resources'],
33
36
  flags: this.flags,
34
37
  });
35
- const { success, error, json } = result;
36
- if (!success)
37
- this.error(error);
38
- return json;
38
+ if (!result.success)
39
+ this.coreError(result);
40
+ return result.json;
39
41
  }
40
42
  }
@@ -3,7 +3,7 @@ import { DeployedStackCommand } from '../../baseCommands.js';
3
3
  import { blueprintInfoCore } from '../../cores/blueprints/info.js';
4
4
  import { Logger } from '../../utils/logger.js';
5
5
  export default class InfoCommand extends DeployedStackCommand {
6
- static summary = "Show information about the local Blueprint's remote Stack deployment";
6
+ static summary = 'Display the status and resources of the remote Stack deployment';
7
7
  static description = `Displays the current state and metadata of your remote Stack deployment, including deployed resources, status, and configuration.
8
8
 
9
9
  Use this command to verify a deployment succeeded, check what resources are live, or confirm which Stack your local Blueprint is connected to.
@@ -20,7 +20,7 @@ Run 'blueprints stacks' to see all available Stacks in your project or organizat
20
20
  }),
21
21
  };
22
22
  async run() {
23
- const { success, error, json } = await blueprintInfoCore({
23
+ const result = await blueprintInfoCore({
24
24
  bin: this.config.bin,
25
25
  log: Logger(this.log.bind(this), this.flags),
26
26
  stackId: this.stackId,
@@ -28,8 +28,8 @@ Run 'blueprints stacks' to see all available Stacks in your project or organizat
28
28
  validateResources: this.flags['validate-resources'],
29
29
  flags: this.flags,
30
30
  });
31
- if (!success)
32
- this.error(error);
33
- return json;
31
+ if (!result.success)
32
+ this.coreError(result);
33
+ return result.json;
34
34
  }
35
35
  }
@@ -4,7 +4,7 @@ import { blueprintInitCore } from '../../cores/blueprints/init.js';
4
4
  import { Logger } from '../../utils/logger.js';
5
5
  import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
6
6
  export default class InitCommand extends RuntimeCommand {
7
- static summary = 'Initialize a local Blueprint and optionally provision a remote Stack deployment';
7
+ static summary = 'Initialize a Blueprint and create a remote Stack';
8
8
  static description = `A Blueprint is your local infrastructure-as-code configuration that defines Sanity resources (datasets, functions, etc.). A Stack is the remote deployment target where your Blueprint is applied.
9
9
  [NOTE: Currently, accounts are limited to three (3) Stacks per project scope.]
10
10
 
@@ -57,7 +57,7 @@ After initialization, use 'blueprints plan' to preview changes, then 'blueprints
57
57
  const result = await validTokenOrErrorMessage(log);
58
58
  if (!result.ok)
59
59
  this.error(result.error.message);
60
- const { success, error } = await blueprintInitCore({
60
+ const initResult = await blueprintInitCore({
61
61
  bin: this.config.bin,
62
62
  log,
63
63
  token: result.value,
@@ -65,7 +65,7 @@ After initialization, use 'blueprints plan' to preview changes, then 'blueprints
65
65
  args: this.args,
66
66
  flags: this.flags,
67
67
  });
68
- if (!success)
69
- this.error(error);
68
+ if (!initResult.success)
69
+ this.coreError(initResult);
70
70
  }
71
71
  }