@sanity/runtime-cli 12.1.0 → 12.2.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 (53) hide show
  1. package/README.md +20 -19
  2. package/dist/actions/blueprints/blueprint.d.ts +3 -2
  3. package/dist/actions/blueprints/stacks.d.ts +8 -4
  4. package/dist/actions/blueprints/stacks.js +6 -32
  5. package/dist/commands/blueprints/doctor.d.ts +1 -0
  6. package/dist/commands/blueprints/doctor.js +4 -0
  7. package/dist/commands/functions/dev.d.ts +2 -2
  8. package/dist/commands/functions/dev.js +3 -2
  9. package/dist/constants.d.ts +7 -0
  10. package/dist/constants.js +7 -0
  11. package/dist/cores/blueprints/doctor.d.ts +1 -0
  12. package/dist/cores/blueprints/doctor.js +36 -5
  13. package/dist/cores/blueprints/info.js +2 -2
  14. package/dist/cores/functions/env/add.js +2 -2
  15. package/dist/cores/functions/env/list.js +2 -2
  16. package/dist/cores/functions/env/remove.js +2 -2
  17. package/dist/cores/functions/logs.js +2 -2
  18. package/dist/cores/functions/test.js +31 -23
  19. package/dist/server/app.js +32 -21
  20. package/dist/server/handlers/invoke.d.ts +2 -2
  21. package/dist/server/handlers/invoke.js +2 -2
  22. package/dist/server/static/components/api-base.js +3 -0
  23. package/dist/server/static/components/app.css +120 -95
  24. package/dist/server/static/components/clear-button.js +1 -1
  25. package/dist/server/static/components/console-panel.js +6 -6
  26. package/dist/server/static/components/fetch-button.js +1 -1
  27. package/dist/server/static/components/filter-api-version.js +3 -3
  28. package/dist/server/static/components/filter-document-id.js +5 -5
  29. package/dist/server/static/components/filter-with-token.js +4 -4
  30. package/dist/server/static/components/filters.js +2 -2
  31. package/dist/server/static/components/function-list.js +14 -5
  32. package/dist/server/static/components/help-button.js +4 -1
  33. package/dist/server/static/components/payload-panel.js +9 -9
  34. package/dist/server/static/components/response-panel.js +8 -8
  35. package/dist/server/static/components/rule-panel.js +4 -4
  36. package/dist/server/static/components/run-panel.js +4 -4
  37. package/dist/server/static/components/select-dropdown.js +5 -25
  38. package/dist/server/static/index.html +9 -9
  39. package/dist/server/static/vendor/m-.css +1 -0
  40. package/dist/server/static/vendor/m-.woff2 +0 -0
  41. package/dist/utils/display/blueprints-formatting.d.ts +3 -2
  42. package/dist/utils/display/blueprints-formatting.js +102 -50
  43. package/dist/utils/display/resources-formatting.d.ts +6 -2
  44. package/dist/utils/display/resources-formatting.js +71 -17
  45. package/dist/utils/find-function.d.ts +2 -2
  46. package/dist/utils/find-function.js +9 -2
  47. package/dist/utils/invoke-local.d.ts +2 -2
  48. package/dist/utils/invoke-local.js +27 -16
  49. package/dist/utils/types.d.ts +46 -22
  50. package/dist/utils/types.js +25 -2
  51. package/dist/utils/validate/resource.js +144 -23
  52. package/oclif.manifest.json +14 -1
  53. 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/12.1.0 linux-x64 node-v24.11.1
23
+ @sanity/runtime-cli/12.2.0 linux-x64 node-v24.11.1
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -92,7 +92,7 @@ EXAMPLES
92
92
  $ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
93
93
  ```
94
94
 
95
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/blueprints/add.ts)_
95
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/blueprints/add.ts)_
96
96
 
97
97
  ## `sanity-run blueprints config`
98
98
 
@@ -121,7 +121,7 @@ EXAMPLES
121
121
  $ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
122
122
  ```
123
123
 
124
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/blueprints/config.ts)_
124
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/blueprints/config.ts)_
125
125
 
126
126
  ## `sanity-run blueprints deploy`
127
127
 
@@ -143,7 +143,7 @@ EXAMPLES
143
143
  $ sanity-run blueprints deploy --no-wait
144
144
  ```
145
145
 
146
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/blueprints/deploy.ts)_
146
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/blueprints/deploy.ts)_
147
147
 
148
148
  ## `sanity-run blueprints destroy`
149
149
 
@@ -170,7 +170,7 @@ EXAMPLES
170
170
  $ sanity-run blueprints destroy --stack-id <stackId> --project-id <projectId> --force --no-wait
171
171
  ```
172
172
 
173
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/blueprints/destroy.ts)_
173
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/blueprints/destroy.ts)_
174
174
 
175
175
  ## `sanity-run blueprints doctor`
176
176
 
@@ -178,9 +178,10 @@ Diagnose potential issues with Blueprint configuration
178
178
 
179
179
  ```
180
180
  USAGE
181
- $ sanity-run blueprints doctor [--verbose] [--path <value>]
181
+ $ sanity-run blueprints doctor [--verbose] [--path <value>] [--fix]
182
182
 
183
183
  FLAGS
184
+ --fix Interactively fix configuration issues
184
185
  --path=<value> Path to the Blueprint configuration file
185
186
  --verbose Provide detailed information about issues
186
187
 
@@ -188,7 +189,7 @@ DESCRIPTION
188
189
  Diagnose potential issues with Blueprint configuration
189
190
  ```
190
191
 
191
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/blueprints/doctor.ts)_
192
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/blueprints/doctor.ts)_
192
193
 
193
194
  ## `sanity-run blueprints info`
194
195
 
@@ -210,7 +211,7 @@ EXAMPLES
210
211
  $ sanity-run blueprints info --id <stackId>
211
212
  ```
212
213
 
213
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/blueprints/info.ts)_
214
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/blueprints/info.ts)_
214
215
 
215
216
  ## `sanity-run blueprints init [DIR]`
216
217
 
@@ -250,7 +251,7 @@ EXAMPLES
250
251
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
251
252
  ```
252
253
 
253
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/blueprints/init.ts)_
254
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/blueprints/init.ts)_
254
255
 
255
256
  ## `sanity-run blueprints logs`
256
257
 
@@ -272,7 +273,7 @@ EXAMPLES
272
273
  $ sanity-run blueprints logs --watch
273
274
  ```
274
275
 
275
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/blueprints/logs.ts)_
276
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/blueprints/logs.ts)_
276
277
 
277
278
  ## `sanity-run blueprints plan`
278
279
 
@@ -289,7 +290,7 @@ EXAMPLES
289
290
  $ sanity-run blueprints plan
290
291
  ```
291
292
 
292
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/blueprints/plan.ts)_
293
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/blueprints/plan.ts)_
293
294
 
294
295
  ## `sanity-run blueprints stacks`
295
296
 
@@ -314,7 +315,7 @@ EXAMPLES
314
315
  $ sanity-run blueprints stacks --organization-id <organizationId>
315
316
  ```
316
317
 
317
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/blueprints/stacks.ts)_
318
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/blueprints/stacks.ts)_
318
319
 
319
320
  ## `sanity-run functions add`
320
321
 
@@ -356,7 +357,7 @@ EXAMPLES
356
357
  $ sanity-run functions add --name my-function --type document-create --type document-update --lang js
357
358
  ```
358
359
 
359
- _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/functions/add.ts)_
360
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/functions/add.ts)_
360
361
 
361
362
  ## `sanity-run functions dev`
362
363
 
@@ -379,7 +380,7 @@ EXAMPLES
379
380
  $ sanity-run functions dev --host 127.0.0.1 --port 8974
380
381
  ```
381
382
 
382
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/functions/dev.ts)_
383
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/functions/dev.ts)_
383
384
 
384
385
  ## `sanity-run functions env add NAME KEY VALUE`
385
386
 
@@ -401,7 +402,7 @@ EXAMPLES
401
402
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
402
403
  ```
403
404
 
404
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/functions/env/add.ts)_
405
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/functions/env/add.ts)_
405
406
 
406
407
  ## `sanity-run functions env list NAME`
407
408
 
@@ -421,7 +422,7 @@ EXAMPLES
421
422
  $ sanity-run functions env list MyFunction
422
423
  ```
423
424
 
424
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/functions/env/list.ts)_
425
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/functions/env/list.ts)_
425
426
 
426
427
  ## `sanity-run functions env remove NAME KEY`
427
428
 
@@ -442,7 +443,7 @@ EXAMPLES
442
443
  $ sanity-run functions env remove MyFunction API_URL
443
444
  ```
444
445
 
445
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/functions/env/remove.ts)_
446
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/functions/env/remove.ts)_
446
447
 
447
448
  ## `sanity-run functions logs NAME`
448
449
 
@@ -476,7 +477,7 @@ EXAMPLES
476
477
  $ sanity-run functions logs <name> --delete
477
478
  ```
478
479
 
479
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/functions/logs.ts)_
480
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/functions/logs.ts)_
480
481
 
481
482
  ## `sanity-run functions test NAME`
482
483
 
@@ -525,7 +526,7 @@ EXAMPLES
525
526
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
526
527
  ```
527
528
 
528
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v12.1.0/src/commands/functions/test.ts)_
529
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v12.2.0/src/commands/functions/test.ts)_
529
530
 
530
531
  ## `sanity-run help [COMMAND]`
531
532
 
@@ -1,5 +1,6 @@
1
+ import type { BlueprintResource } from '@sanity/blueprints';
1
2
  import { type Blueprint } from '@sanity/blueprints-parser';
2
- import type { BlueprintParserError, Resource } from '../../utils/types.js';
3
+ import type { BlueprintParserError } from '../../utils/types.js';
3
4
  import { type ScopeType } from '../../utils/types.js';
4
5
  import { type LocatedBlueprintsConfig } from './config.js';
5
6
  declare const SUPPORTED_FILE_EXTENSIONS: readonly [".json", ".js", ".mjs", ".ts"];
@@ -51,7 +52,7 @@ export declare function writeBlueprintToDisk({ blueprintFilePath, jsonContent, }
51
52
  blueprintFilePath: string;
52
53
  jsonContent?: Blueprint;
53
54
  }): string;
54
- export declare function addResourceToBlueprint<T extends Resource>({ blueprintFilePath, resource, }: {
55
+ export declare function addResourceToBlueprint<T extends BlueprintResource>({ blueprintFilePath, resource, }: {
55
56
  blueprintFilePath?: string;
56
57
  resource: T;
57
58
  }): T | undefined;
@@ -1,10 +1,14 @@
1
1
  import type { AuthParams, ScopeType, Stack, StackMutation } from '../../utils/types.js';
2
2
  export declare const stacksUrl: string;
3
- interface ListStacksResponse {
4
- ok: boolean;
5
- error: string | null;
3
+ type ListStacksResponse = {
4
+ ok: true;
5
+ error: null;
6
6
  stacks: Stack[];
7
- }
7
+ } | {
8
+ ok: false;
9
+ error: string;
10
+ stacks: unknown;
11
+ };
8
12
  export declare function listStacks(auth: AuthParams): Promise<ListStacksResponse>;
9
13
  interface GetStackResponse {
10
14
  ok: boolean;
@@ -2,32 +2,6 @@ import config from '../../config.js';
2
2
  import getHeaders from '../../utils/get-headers.js';
3
3
  const { apiUrl } = config;
4
4
  export const stacksUrl = `${apiUrl}vX/blueprints/stacks`;
5
- /** Discriminate between Resource and Resource with parameters */
6
- function hasParameters(obj) {
7
- return (typeof obj === 'object' &&
8
- obj !== null &&
9
- 'parameters' in obj &&
10
- typeof obj.parameters === 'object' &&
11
- obj.parameters !== null);
12
- }
13
- /** Flatten Resource with parameters */
14
- function flattenResource(resource) {
15
- if (hasParameters(resource)) {
16
- const { parameters, ...rest } = resource;
17
- return { ...rest, ...parameters };
18
- }
19
- return resource;
20
- }
21
- /** Flatten a Stack's resources */
22
- function flattenStackResources(stack) {
23
- if (stack && Array.isArray(stack.resources)) {
24
- return {
25
- ...stack,
26
- resources: stack.resources.map(flattenResource),
27
- };
28
- }
29
- return stack;
30
- }
31
5
  export async function listStacks(auth) {
32
6
  const response = await fetch(stacksUrl, {
33
7
  method: 'GET',
@@ -37,7 +11,7 @@ export async function listStacks(auth) {
37
11
  return {
38
12
  ok: response.ok,
39
13
  error: response.ok ? null : data.message,
40
- stacks: response.ok ? data.map(flattenStackResources) : data,
14
+ stacks: data,
41
15
  };
42
16
  }
43
17
  export async function getStack({ stackId, auth, }) {
@@ -49,7 +23,7 @@ export async function getStack({ stackId, auth, }) {
49
23
  return {
50
24
  ok: response.ok,
51
25
  error: response.ok ? null : data.message,
52
- stack: response.ok ? flattenStackResources(data) : data,
26
+ stack: data,
53
27
  response,
54
28
  };
55
29
  }
@@ -63,7 +37,7 @@ export async function createStack({ stackMutation, auth, }) {
63
37
  return {
64
38
  ok: response.ok,
65
39
  error: response.ok ? null : data.message,
66
- stack: response.ok ? flattenStackResources(data) : data,
40
+ stack: data,
67
41
  };
68
42
  }
69
43
  export async function createEmptyStack({ token, scopeType, scopeId, name, }) {
@@ -80,7 +54,7 @@ export async function createEmptyStack({ token, scopeType, scopeId, name, }) {
80
54
  if (!response.ok) {
81
55
  throw new Error(response.error || 'Failed to create new Stack');
82
56
  }
83
- return flattenStackResources(response.stack);
57
+ return response.stack;
84
58
  }
85
59
  export async function updateStack({ stackId, stackMutation, auth, }) {
86
60
  const response = await fetch(`${stacksUrl}/${stackId}`, {
@@ -92,7 +66,7 @@ export async function updateStack({ stackId, stackMutation, auth, }) {
92
66
  return {
93
67
  ok: response.ok,
94
68
  error: response.ok ? null : data.message,
95
- stack: response.ok ? flattenStackResources(data) : data,
69
+ stack: data,
96
70
  };
97
71
  }
98
72
  export async function destroyStack({ stackId, auth, }) {
@@ -104,6 +78,6 @@ export async function destroyStack({ stackId, auth, }) {
104
78
  return {
105
79
  ok: response.ok,
106
80
  error: response.ok ? null : data.message,
107
- stack: response.ok ? flattenStackResources(data) : data,
81
+ stack: data,
108
82
  };
109
83
  }
@@ -5,6 +5,7 @@ export default class DoctorCommand extends Command {
5
5
  static flags: {
6
6
  verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
7
  path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ fix: import("@oclif/core/interfaces").BooleanFlag<boolean>;
8
9
  };
9
10
  run(): Promise<void>;
10
11
  }
@@ -12,6 +12,10 @@ export default class DoctorCommand extends Command {
12
12
  path: Flags.string({
13
13
  description: 'Path to the Blueprint configuration file',
14
14
  }),
15
+ fix: Flags.boolean({
16
+ description: 'Interactively fix configuration issues',
17
+ default: false,
18
+ }),
15
19
  };
16
20
  async run() {
17
21
  const { flags } = await this.parse(DoctorCommand);
@@ -1,5 +1,5 @@
1
- import { Command } from '@oclif/core';
2
- export default class DevCommand extends Command {
1
+ import { BlueprintCommand } from '../../baseCommands.js';
2
+ export default class DevCommand extends BlueprintCommand<typeof DevCommand> {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
@@ -1,6 +1,7 @@
1
- import { Command, Flags } from '@oclif/core';
1
+ import { Flags } from '@oclif/core';
2
+ import { BlueprintCommand } from '../../baseCommands.js';
2
3
  import { functionDevCore } from '../../cores/functions/dev.js';
3
- export default class DevCommand extends Command {
4
+ export default class DevCommand extends BlueprintCommand {
4
5
  static description = 'Start the Sanity Function emulator';
5
6
  static examples = ['<%= config.bin %> <%= command.id %> --host 127.0.0.1 --port 8974'];
6
7
  static flags = {
@@ -0,0 +1,7 @@
1
+ export declare const SANITY_ACCESS_ROLE = "sanity.access.role";
2
+ export declare const SANITY_FUNCTION_DOCUMENT = "sanity.function.document";
3
+ export declare const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = "sanity.function.media-library.asset";
4
+ export declare const SANITY_FUNCTION_SCHEDULE = "sanity.function.cron";
5
+ export declare const SANITY_PROJECT_CORS = "sanity.project.cors";
6
+ export declare const SANITY_PROJECT_DATASET = "sanity.project.dataset";
7
+ export declare const SANITY_PROJECT_WEBHOOK = "sanity.project.webhook";
@@ -0,0 +1,7 @@
1
+ export const SANITY_ACCESS_ROLE = 'sanity.access.role';
2
+ export const SANITY_FUNCTION_DOCUMENT = 'sanity.function.document';
3
+ export const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = 'sanity.function.media-library.asset';
4
+ export const SANITY_FUNCTION_SCHEDULE = 'sanity.function.cron';
5
+ export const SANITY_PROJECT_CORS = 'sanity.project.cors';
6
+ export const SANITY_PROJECT_DATASET = 'sanity.project.dataset';
7
+ export const SANITY_PROJECT_WEBHOOK = 'sanity.project.webhook';
@@ -4,6 +4,7 @@ export interface BlueprintDoctorOptions extends CoreConfig {
4
4
  flags: {
5
5
  verbose?: boolean;
6
6
  path?: string;
7
+ fix?: boolean;
7
8
  };
8
9
  }
9
10
  export declare function blueprintDoctorCore(options: BlueprintDoctorOptions): Promise<CoreResult>;
@@ -5,6 +5,7 @@ import { getStack } from '../../actions/blueprints/stacks.js';
5
5
  import config from '../../config.js';
6
6
  import { capitalize, check, filePathRelativeToCwd, indent, niceId, severe, unsure, } from '../../utils/display/presenters.js';
7
7
  import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
8
+ import { blueprintConfigCore } from './config.js';
8
9
  const diagLookup = {
9
10
  online: 'Online',
10
11
  tokenPresent: 'Auth token present',
@@ -17,12 +18,13 @@ const diagLookup = {
17
18
  userHasAccess: 'User has access to deployed "Stack"',
18
19
  };
19
20
  export async function blueprintDoctorCore(options) {
20
- const { log, token, flags: { verbose: v, path: p }, } = options;
21
+ const { bin, log, token, flags: { verbose: v, path: p, fix }, } = options;
21
22
  const yikes = (s) => {
22
23
  log(chalk.bgRedBright.whiteBright.bold(` ${s} `));
23
24
  };
24
25
  const here = cwd();
25
26
  const path = p || here;
27
+ let tokenOrError;
26
28
  if (v)
27
29
  log(`Checking ${filePathRelativeToCwd(path)}`);
28
30
  // 3 states: null == unknown, true == good, false == bad
@@ -49,7 +51,7 @@ export async function blueprintDoctorCore(options) {
49
51
  // TOKEN
50
52
  if (token) {
51
53
  diagnostics.tokenPresent = true;
52
- const tokenOrError = await validTokenOrErrorMessage(token);
54
+ tokenOrError = await validTokenOrErrorMessage(token);
53
55
  if (tokenOrError.ok) {
54
56
  diagnostics.tokenValid = true;
55
57
  }
@@ -91,7 +93,8 @@ export async function blueprintDoctorCore(options) {
91
93
  diagnostics.blueprintValid = false;
92
94
  }
93
95
  if (blueprint) {
94
- const { configPath, scopeType, scopeId, stackId, projectId } = blueprint;
96
+ const { blueprintConfig, scopeType, scopeId, stackId, projectId } = blueprint;
97
+ const configPath = blueprintConfig?.configPath;
95
98
  // CONFIG file
96
99
  if (configPath) {
97
100
  if (v)
@@ -169,11 +172,39 @@ export async function blueprintDoctorCore(options) {
169
172
  log(severe(`${key} is ${value}`));
170
173
  }
171
174
  }
175
+ const errorMessage = 'One or more checks failed';
172
176
  if (allGood) {
173
177
  log(chalk.bold.green('All checks passed'));
178
+ if (fix)
179
+ log(chalk.bold.yellow('Nothing to fix; --fix flag is ignored'));
174
180
  return { success: true, data: { diagnostics } };
175
181
  }
176
- else {
177
- return { success: false, error: 'One or more checks failed', data: { diagnostics } };
182
+ else if (fix) {
183
+ if (p) {
184
+ return { success: false, error: `${errorMessage}. --fix cannot be used with --path` };
185
+ }
186
+ if (!tokenOrError) {
187
+ return { success: false, error: `${errorMessage}. Unable to fix: Missing authentication token` };
188
+ }
189
+ if (tokenOrError?.ok === false) {
190
+ return {
191
+ success: false,
192
+ error: `${errorMessage}. Unable to fix: ${tokenOrError.error.message}`,
193
+ };
194
+ }
195
+ if (!blueprint) {
196
+ return {
197
+ success: false,
198
+ error: `${errorMessage}. Unable to fix: Blueprint is missing or invalid`,
199
+ };
200
+ }
201
+ return blueprintConfigCore({
202
+ bin,
203
+ log,
204
+ token: tokenOrError.value,
205
+ blueprint,
206
+ flags: { edit: true, verbose: v },
207
+ });
178
208
  }
209
+ return { success: false, error: errorMessage, data: { diagnostics } };
179
210
  }
@@ -1,5 +1,5 @@
1
1
  import { getStack } from '../../actions/blueprints/stacks.js';
2
- import { formatResourceTree, formatStackInfo } from '../../utils/display/blueprints-formatting.js';
2
+ import { formatDeployedResourceTree, formatStackInfo, } from '../../utils/display/blueprints-formatting.js';
3
3
  import { niceId } from '../../utils/display/presenters.js';
4
4
  export async function blueprintInfoCore(options) {
5
5
  const { log, auth, stackId, flags, deployedStack } = options;
@@ -20,7 +20,7 @@ export async function blueprintInfoCore(options) {
20
20
  }
21
21
  log(formatStackInfo(stack, true));
22
22
  if (stack.resources)
23
- log(formatResourceTree(stack.resources));
23
+ log(formatDeployedResourceTree(stack.resources));
24
24
  return { success: true };
25
25
  }
26
26
  catch (error) {
@@ -1,11 +1,11 @@
1
1
  import chalk from 'chalk';
2
2
  import ora from 'ora';
3
3
  import { update } from '../../../actions/functions/env/update.js';
4
- import { findFunctionByName } from '../../../utils/find-function.js';
4
+ import { findFunctionInStack } from '../../../utils/find-function.js';
5
5
  export async function functionEnvAddCore(options) {
6
6
  const args = options.args;
7
7
  const spinner = ora(`Updating "${args.key}" environment variable in "${args.name}"`).start();
8
- const { externalId } = findFunctionByName(options.deployedStack, args.name);
8
+ const { externalId } = findFunctionInStack(options.deployedStack, args.name);
9
9
  const result = await update(externalId, args.key, args.value, options.auth);
10
10
  if (!result.ok) {
11
11
  spinner.fail(`${chalk.red('Failed')} to update ${args.key}`);
@@ -1,10 +1,10 @@
1
1
  import ora from 'ora';
2
2
  import { list } from '../../../actions/functions/env/list.js';
3
- import { findFunctionByName } from '../../../utils/find-function.js';
3
+ import { findFunctionInStack } from '../../../utils/find-function.js';
4
4
  export async function functionEnvListCore(options) {
5
5
  const args = options.args;
6
6
  const spinner = ora(`Listing environment variables for "${args.name}"`).start();
7
- const { externalId } = findFunctionByName(options.deployedStack, args.name);
7
+ const { externalId } = findFunctionInStack(options.deployedStack, args.name);
8
8
  const result = await list(externalId, options.auth);
9
9
  if (!result.ok) {
10
10
  spinner.stop();
@@ -1,11 +1,11 @@
1
1
  import chalk from 'chalk';
2
2
  import ora from 'ora';
3
3
  import { remove } from '../../../actions/functions/env/remove.js';
4
- import { findFunctionByName } from '../../../utils/find-function.js';
4
+ import { findFunctionInStack } from '../../../utils/find-function.js';
5
5
  export async function functionEnvRemoveCore(options) {
6
6
  const args = options.args;
7
7
  const spinner = ora(`Removing "${args.key}" environment variable in "${args.name}"`).start();
8
- const { externalId } = findFunctionByName(options.deployedStack, args.name);
8
+ const { externalId } = findFunctionInStack(options.deployedStack, args.name);
9
9
  const result = await remove(externalId, args.key, options.auth);
10
10
  if (!result.ok) {
11
11
  spinner.fail(`${chalk.red('Failed')} to remove ${args.key}`);
@@ -4,12 +4,12 @@ import ora from 'ora';
4
4
  import { deleteLogs as deleteLogsAction, logs as getLogsAction, streamLogs as streamLogsAction, } from '../../actions/functions/logs.js';
5
5
  import { formatTitle } from '../../utils/display/blueprints-formatting.js';
6
6
  import { niceId } from '../../utils/display/presenters.js';
7
- import { findFunctionByName } from '../../utils/find-function.js';
7
+ import { findFunctionInStack } from '../../utils/find-function.js';
8
8
  export async function functionLogsCore(options) {
9
9
  const { args, flags, log, auth, deployedStack } = options;
10
10
  const { name } = args;
11
11
  const { delete: shouldDelete, watch: shouldWatch, force, limit, json, utc } = flags;
12
- const { externalId } = findFunctionByName(deployedStack, name); // throws if not found
12
+ const { externalId } = findFunctionInStack(deployedStack, name); // throws if not found
13
13
  if (shouldDelete)
14
14
  return deleteLogs({ name, externalId, auth, force, log });
15
15
  if (shouldWatch)
@@ -4,11 +4,12 @@ import { cwd } from 'node:process';
4
4
  import ora from 'ora';
5
5
  import { testAction } from '../../actions/functions/test.js';
6
6
  import config from '../../config.js';
7
+ import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET } from '../../constants.js';
7
8
  import buildPayload from '../../utils/build-payload.js';
8
- import { findFunctionByName } from '../../utils/find-function.js';
9
+ import { findFunctionInBlueprint } from '../../utils/find-function.js';
9
10
  import { fetchAsset, fetchDocument } from '../../utils/functions/fetch-document.js';
10
11
  import { parseJsonObject } from '../../utils/parse-json-object.js';
11
- import { isEventType, } from '../../utils/types.js';
12
+ import { isEventType, isGroqContextOptions, } from '../../utils/types.js';
12
13
  export async function functionTestCore(options) {
13
14
  const { blueprint, log, args, flags } = options;
14
15
  const { name: fnName } = args;
@@ -29,22 +30,25 @@ export async function functionTestCore(options) {
29
30
  };
30
31
  }
31
32
  try {
32
- const resource = findFunctionByName(parsedBlueprint, fnName); // throws if not found
33
- const docFunction = resource.type === 'sanity.function.document';
34
- const contextOptions = {
35
- clientOptions: {
36
- apiVersion: api,
37
- dataset,
38
- projectId,
39
- organizationId,
40
- },
41
- eventResourceType: docFunction ? 'dataset' : 'media-library',
42
- eventResourceId: (docFunction ? `${projectId}.${dataset}` : mediaLibraryId) || '',
43
- functionResourceType: 'project',
44
- functionResourceId: (docFunction ? projectId : organizationId) || '',
45
- };
33
+ const resource = findFunctionInBlueprint(parsedBlueprint, fnName); // throws if not found
34
+ const docFunction = resource.type === SANITY_FUNCTION_DOCUMENT;
35
+ const mediaFunction = resource.type === SANITY_FUNCTION_MEDIA_LIBRARY_ASSET;
36
+ const contextOptions = docFunction || mediaFunction
37
+ ? {
38
+ clientOptions: {
39
+ apiVersion: api,
40
+ dataset,
41
+ projectId,
42
+ organizationId,
43
+ },
44
+ eventResourceType: docFunction ? 'dataset' : 'media-library',
45
+ eventResourceId: (docFunction ? `${projectId}.${dataset}` : mediaLibraryId) || '',
46
+ functionResourceType: 'project',
47
+ functionResourceId: projectId || '',
48
+ }
49
+ : {};
46
50
  // If the user sets the flag to use the real token set it in our options
47
- if (withUserToken) {
51
+ if (withUserToken && isGroqContextOptions(contextOptions)) {
48
52
  contextOptions.clientOptions.token = config.token || undefined;
49
53
  }
50
54
  let before = null;
@@ -115,12 +119,16 @@ export async function functionTestCore(options) {
115
119
  payload = buildPayload({ data, file });
116
120
  }
117
121
  }
118
- const invokeOptions = {
119
- event: eventType,
120
- payload,
121
- before,
122
- after,
123
- };
122
+ const invokeOptions = docFunction || mediaFunction
123
+ ? {
124
+ event: eventType,
125
+ payload,
126
+ before,
127
+ after,
128
+ }
129
+ : {
130
+ event: 'schedule',
131
+ };
124
132
  const spinner = ora('Executing function...').start();
125
133
  const { json, logs, error } = await testAction(resource, invokeOptions, contextOptions, {
126
134
  timeout: timeout ? timeout : resource.timeout,