@sanity/runtime-cli 8.1.6 → 8.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.
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/8.1.6 linux-x64 node-v22.16.0
23
+ @sanity/runtime-cli/8.2.0 linux-x64 node-v22.16.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -86,7 +86,7 @@ EXAMPLES
86
86
  $ sanity-run blueprints add function --name my-function --fn-type document-publish --lang js
87
87
  ```
88
88
 
89
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/add.ts)_
89
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/blueprints/add.ts)_
90
90
 
91
91
  ## `sanity-run blueprints config`
92
92
 
@@ -117,7 +117,7 @@ EXAMPLES
117
117
  $ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
118
118
  ```
119
119
 
120
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/config.ts)_
120
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/blueprints/config.ts)_
121
121
 
122
122
  ## `sanity-run blueprints deploy`
123
123
 
@@ -139,7 +139,7 @@ EXAMPLES
139
139
  $ sanity-run blueprints deploy --no-wait
140
140
  ```
141
141
 
142
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/deploy.ts)_
142
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/blueprints/deploy.ts)_
143
143
 
144
144
  ## `sanity-run blueprints destroy`
145
145
 
@@ -164,7 +164,7 @@ EXAMPLES
164
164
  $ sanity-run blueprints destroy --stack-id <stackId> --project-id <projectId> --force --no-wait
165
165
  ```
166
166
 
167
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/destroy.ts)_
167
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/blueprints/destroy.ts)_
168
168
 
169
169
  ## `sanity-run blueprints info`
170
170
 
@@ -186,7 +186,7 @@ EXAMPLES
186
186
  $ sanity-run blueprints info --stack-id <stackId>
187
187
  ```
188
188
 
189
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/info.ts)_
189
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/blueprints/info.ts)_
190
190
 
191
191
  ## `sanity-run blueprints init [DIR]`
192
192
 
@@ -224,7 +224,7 @@ EXAMPLES
224
224
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
225
225
  ```
226
226
 
227
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/init.ts)_
227
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/blueprints/init.ts)_
228
228
 
229
229
  ## `sanity-run blueprints logs`
230
230
 
@@ -246,7 +246,7 @@ EXAMPLES
246
246
  $ sanity-run blueprints logs --watch
247
247
  ```
248
248
 
249
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/logs.ts)_
249
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/blueprints/logs.ts)_
250
250
 
251
251
  ## `sanity-run blueprints plan`
252
252
 
@@ -263,7 +263,7 @@ EXAMPLES
263
263
  $ sanity-run blueprints plan
264
264
  ```
265
265
 
266
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/plan.ts)_
266
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/blueprints/plan.ts)_
267
267
 
268
268
  ## `sanity-run blueprints stacks`
269
269
 
@@ -285,7 +285,7 @@ EXAMPLES
285
285
  $ sanity-run blueprints stacks --project-id <projectId>
286
286
  ```
287
287
 
288
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/stacks.ts)_
288
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/blueprints/stacks.ts)_
289
289
 
290
290
  ## `sanity-run functions dev`
291
291
 
@@ -305,7 +305,7 @@ EXAMPLES
305
305
  $ sanity-run functions dev --port 8974
306
306
  ```
307
307
 
308
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/dev.ts)_
308
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/functions/dev.ts)_
309
309
 
310
310
  ## `sanity-run functions env add NAME KEY VALUE`
311
311
 
@@ -327,7 +327,7 @@ EXAMPLES
327
327
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
328
328
  ```
329
329
 
330
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/env/add.ts)_
330
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/functions/env/add.ts)_
331
331
 
332
332
  ## `sanity-run functions env list NAME`
333
333
 
@@ -347,7 +347,7 @@ EXAMPLES
347
347
  $ sanity-run functions env list MyFunction
348
348
  ```
349
349
 
350
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/env/list.ts)_
350
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/functions/env/list.ts)_
351
351
 
352
352
  ## `sanity-run functions env remove NAME KEY`
353
353
 
@@ -368,7 +368,7 @@ EXAMPLES
368
368
  $ sanity-run functions env remove MyFunction API_URL
369
369
  ```
370
370
 
371
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/env/remove.ts)_
371
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/functions/env/remove.ts)_
372
372
 
373
373
  ## `sanity-run functions logs NAME`
374
374
 
@@ -402,7 +402,7 @@ EXAMPLES
402
402
  $ sanity-run functions logs <name> --delete
403
403
  ```
404
404
 
405
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/logs.ts)_
405
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/functions/logs.ts)_
406
406
 
407
407
  ## `sanity-run functions test NAME`
408
408
 
@@ -435,7 +435,7 @@ EXAMPLES
435
435
  $ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
436
436
  ```
437
437
 
438
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/test.ts)_
438
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v8.2.0/src/commands/functions/test.ts)_
439
439
 
440
440
  ## `sanity-run help [COMMAND]`
441
441
 
@@ -1,7 +1,7 @@
1
- import type { AuthParams, LocalFunctionResource } from '../../utils/types.js';
1
+ import type { AuthParams, FunctionResource } from '../../utils/types.js';
2
2
  export declare const stashUrl: string;
3
3
  export declare function stashAsset({ resource, auth, }: {
4
- resource: LocalFunctionResource;
4
+ resource: FunctionResource;
5
5
  auth: AuthParams;
6
6
  }): Promise<{
7
7
  success: boolean;
@@ -1,4 +1,4 @@
1
- import type { BlueprintParserError, LocalBlueprint, LocalResource } from '../../utils/types.js';
1
+ import type { BlueprintParserError, LocalBlueprint, Resource } from '../../utils/types.js';
2
2
  export { BLUEPRINT_CONFIG_FILE, BLUEPRINT_CONFIG_VERSION, BLUEPRINT_DIR } from '../../config.js';
3
3
  declare const SUPPORTED_FILE_EXTENSIONS: readonly [".json", ".js", ".mjs", ".ts"];
4
4
  type BlueprintFileExtension = (typeof SUPPORTED_FILE_EXTENSIONS)[number];
@@ -69,8 +69,8 @@ export declare function writeGitignoreFile({ blueprintFilePath, }: {
69
69
  }): string | null;
70
70
  export declare function addResourceToBlueprint({ blueprintFilePath, resource, }: {
71
71
  blueprintFilePath?: string;
72
- resource: LocalResource;
73
- }): LocalResource | undefined;
72
+ resource: Resource;
73
+ }): Resource | undefined;
74
74
  export declare function updateBlueprintMetadata({ blueprintFilePath, metadata, }: {
75
75
  blueprintFilePath?: string;
76
76
  metadata: LocalBlueprint['metadata'];
@@ -1,4 +1,4 @@
1
- import type { LocalFunctionResource } from '../../utils/types.js';
1
+ import type { FunctionResource } from '../../utils/types.js';
2
2
  interface FunctionResourceOptions {
3
3
  name: string;
4
4
  type: string;
@@ -13,6 +13,6 @@ interface FunctionResourceOptions {
13
13
  export declare function createFunctionResource(options: FunctionResourceOptions): Promise<{
14
14
  filePath: string;
15
15
  resourceAdded: boolean;
16
- resource: LocalFunctionResource;
16
+ resource: FunctionResource;
17
17
  }>;
18
18
  export {};
@@ -1,4 +1,4 @@
1
- import type { AuthParams, Stack, StackPayload } from '../../utils/types.js';
1
+ import type { AuthParams, Stack, StackMutation } from '../../utils/types.js';
2
2
  export declare const stacksUrl: string;
3
3
  interface ListStacksResponse {
4
4
  ok: boolean;
@@ -20,8 +20,8 @@ interface CreateStackResponse {
20
20
  error: string | null;
21
21
  stack: Stack;
22
22
  }
23
- export declare function createStack({ stackPayload, auth, }: {
24
- stackPayload: StackPayload;
23
+ export declare function createStack({ stackMutation, auth, }: {
24
+ stackMutation: StackMutation;
25
25
  auth: AuthParams;
26
26
  }): Promise<CreateStackResponse>;
27
27
  export declare function createEmptyStack({ token, projectId, name, projectBased, }: {
@@ -35,9 +35,9 @@ interface UpdateStackResponse {
35
35
  error: string | null;
36
36
  stack: Stack;
37
37
  }
38
- export declare function updateStack({ stackId, stackPayload, auth, }: {
38
+ export declare function updateStack({ stackId, stackMutation, auth, }: {
39
39
  stackId: string;
40
- stackPayload: StackPayload;
40
+ stackMutation: StackMutation;
41
41
  auth: AuthParams;
42
42
  }): Promise<UpdateStackResponse>;
43
43
  interface DestroyStackResponse {
@@ -2,16 +2,39 @@ 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
+ function hasParameters(obj) {
6
+ return (typeof obj === 'object' &&
7
+ obj !== null &&
8
+ 'parameters' in obj &&
9
+ typeof obj.parameters === 'object' &&
10
+ obj.parameters !== null);
11
+ }
12
+ function flattenResource(resource) {
13
+ if (hasParameters(resource)) {
14
+ const { parameters, ...rest } = resource;
15
+ return { ...rest, ...parameters };
16
+ }
17
+ return resource;
18
+ }
19
+ function flattenStackResources(stack) {
20
+ if (stack && Array.isArray(stack.resources)) {
21
+ return {
22
+ ...stack,
23
+ resources: stack.resources.map(flattenResource),
24
+ };
25
+ }
26
+ return stack;
27
+ }
5
28
  export async function listStacks(auth) {
6
29
  const response = await fetch(stacksUrl, {
7
30
  method: 'GET',
8
31
  headers: getHeaders(auth),
9
32
  });
10
- const stacks = await response.json();
33
+ const data = await response.json();
11
34
  return {
12
35
  ok: response.ok,
13
- error: response.ok ? null : stacks.message,
14
- stacks,
36
+ error: response.ok ? null : data.message,
37
+ stacks: response.ok ? data.map(flattenStackResources) : data,
15
38
  };
16
39
  }
17
40
  export async function getStack({ stackId, auth, }) {
@@ -19,51 +42,51 @@ export async function getStack({ stackId, auth, }) {
19
42
  method: 'GET',
20
43
  headers: getHeaders(auth),
21
44
  });
22
- const stack = await response.json();
45
+ const data = await response.json();
23
46
  return {
24
47
  ok: response.ok,
25
- error: response.ok ? null : stack.message,
26
- stack,
48
+ error: response.ok ? null : data.message,
49
+ stack: response.ok ? flattenStackResources(data) : data,
27
50
  };
28
51
  }
29
- export async function createStack({ stackPayload, auth, }) {
52
+ export async function createStack({ stackMutation, auth, }) {
30
53
  const response = await fetch(stacksUrl, {
31
54
  method: 'POST',
32
55
  headers: getHeaders(auth),
33
- body: JSON.stringify(stackPayload),
56
+ body: JSON.stringify(stackMutation),
34
57
  });
35
- const stack = await response.json();
58
+ const data = await response.json();
36
59
  return {
37
60
  ok: response.ok,
38
- error: response.ok ? null : stack.message,
39
- stack,
61
+ error: response.ok ? null : data.message,
62
+ stack: response.ok ? flattenStackResources(data) : data,
40
63
  };
41
64
  }
42
65
  export async function createEmptyStack({ token, projectId, name, projectBased = true, }) {
43
- const stackPayload = {
66
+ const stackMutation = {
44
67
  name,
45
68
  projectId,
46
69
  useProjectBasedId: projectBased,
47
70
  document: { resources: [] },
48
71
  };
49
72
  const auth = { token, projectId };
50
- const response = await createStack({ stackPayload, auth });
73
+ const response = await createStack({ stackMutation, auth });
51
74
  if (!response.ok) {
52
75
  throw new Error(response.error || 'Failed to create new Stack');
53
76
  }
54
- return response.stack;
77
+ return flattenStackResources(response.stack);
55
78
  }
56
- export async function updateStack({ stackId, stackPayload, auth, }) {
79
+ export async function updateStack({ stackId, stackMutation, auth, }) {
57
80
  const response = await fetch(`${stacksUrl}/${stackId}`, {
58
81
  method: 'PUT',
59
82
  headers: getHeaders(auth),
60
- body: JSON.stringify(stackPayload),
83
+ body: JSON.stringify(stackMutation),
61
84
  });
62
- const stack = await response.json();
85
+ const data = await response.json();
63
86
  return {
64
87
  ok: response.ok,
65
- error: response.ok ? null : stack.message,
66
- stack,
88
+ error: response.ok ? null : data.message,
89
+ stack: response.ok ? flattenStackResources(data) : data,
67
90
  };
68
91
  }
69
92
  export async function destroyStack({ stackId, auth, }) {
@@ -71,10 +94,10 @@ export async function destroyStack({ stackId, auth, }) {
71
94
  method: 'DELETE',
72
95
  headers: getHeaders(auth),
73
96
  });
74
- const stack = await response.json();
97
+ const data = await response.json();
75
98
  return {
76
99
  ok: response.ok,
77
- error: response.ok ? null : stack.message,
78
- stack,
100
+ error: response.ok ? null : data.message,
101
+ stack: response.ok ? flattenStackResources(data) : data,
79
102
  };
80
103
  }
@@ -1,2 +1,2 @@
1
- import type { InvocationResponse, InvokeContextOptions, InvokePayloadOptions, LocalFunctionResource } from '../../utils/types.js';
2
- export declare function testAction(resource: LocalFunctionResource, options: InvokePayloadOptions, context: InvokeContextOptions): Promise<InvocationResponse>;
1
+ import type { FunctionResource, InvocationResponse, InvokeContextOptions, InvokePayloadOptions } from '../../utils/types.js';
2
+ export declare function testAction(resource: FunctionResource, options: InvokePayloadOptions, context: InvokeContextOptions): Promise<InvocationResponse>;
@@ -169,8 +169,8 @@ async function startReinitializeStack({ token, projectId, }) {
169
169
  };
170
170
  }
171
171
  const projectDisplayName = project.displayName;
172
- const stackPayload = { name: projectDisplayName, projectId, document: { resources: [] } };
173
- const response = await createStack({ stackPayload, auth });
172
+ const stackMutation = { name: projectDisplayName, projectId, document: { resources: [] } };
173
+ const response = await createStack({ stackMutation, auth });
174
174
  if (!response.ok)
175
175
  return { ok: false, error: response.error || 'Failed to create new Stack' };
176
176
  return {
@@ -33,14 +33,14 @@ export async function blueprintDeployCore(options) {
33
33
  }
34
34
  }
35
35
  }
36
- const stackPayload = {
36
+ const stackMutation = {
37
37
  projectId,
38
38
  name: deployedStack.name,
39
39
  document: { resources: validResources },
40
40
  };
41
41
  const spinner = ora('Deploying...').start();
42
42
  const isoNow = new Date().toISOString();
43
- const { ok: deployOk, stack, error: deployError, } = await updateStack({ stackId, stackPayload, auth });
43
+ const { ok: deployOk, stack, error: deployError, } = await updateStack({ stackId, stackMutation, auth });
44
44
  if (!deployOk) {
45
45
  spinner.fail(`${chalk.red('Failed')} to update deployment`);
46
46
  return { success: false, error: deployError || 'Failed to update deployment' };
@@ -1,5 +1,5 @@
1
- import type { LocalFunctionResource } from '../types.js';
2
- export declare function bundleFunction(resource: LocalFunctionResource): Promise<{
1
+ import type { FunctionResource } from '../types.js';
2
+ export declare function bundleFunction(resource: FunctionResource): Promise<{
3
3
  type: string;
4
4
  outputDir: string;
5
5
  warnings: string[];
@@ -1,6 +1,6 @@
1
- import type { LocalBlueprint, LocalResource, Stack, StackResource } from '../types.js';
1
+ import type { LocalBlueprint, Resource, Stack } from '../types.js';
2
2
  export declare function formatTitle(title: string, name: string): string;
3
- export declare function formatResourceTree(resources: StackResource[] | LocalResource[] | undefined): string;
3
+ export declare function formatResourceTree(resources: Resource[] | undefined): string;
4
4
  export declare function formatStackInfo(stack: Stack | LocalBlueprint, isCurrentStack?: boolean): string;
5
5
  export declare function formatStacksListing(stacks: Stack[], currentStackId?: string): string;
6
6
  export declare function stackDeployDiff(localBlueprint: LocalBlueprint, deployedStack: Stack): string | null;
@@ -2,7 +2,7 @@ import { treeify } from 'array-treeify';
2
2
  import chalk from 'chalk';
3
3
  import { formatDate, formatDuration } from './dates.js';
4
4
  import { niceId } from './presenters.js';
5
- import { arrayifyLocalFunction, arrayifyStackFunction } from './resources-formatting.js';
5
+ import { arraifyCors, arrayifyFunction } from './resources-formatting.js';
6
6
  export function formatTitle(title, name) {
7
7
  return `${chalk.bold.blue(title)} ${chalk.bold(`"${name}"`)}`;
8
8
  }
@@ -10,33 +10,72 @@ export function formatResourceTree(resources) {
10
10
  if (!resources || resources.length === 0)
11
11
  return ' Zero resources';
12
12
  const output = [`${chalk.bold.underline('Resources')} [${resources.length}]`];
13
- const functionResources = resources.filter((r) => r.type?.startsWith('sanity.function.'));
14
- const otherResources = resources.filter((r) => !r.type?.startsWith('sanity.function.'));
15
- const hasOtherResources = otherResources.length > 0;
16
- if (functionResources.length > 0) {
17
- const fnsOutput = [`${chalk.bold('Functions')} [${functionResources.length}]`];
18
- const fnDetails = [];
19
- for (const fn of functionResources) {
20
- const name = chalk.bold.green(fn.displayName || fn.name);
21
- const ids = [
22
- 'id' in fn && fn.id ? `${niceId(fn.id)}` : '',
23
- 'externalId' in fn && fn.externalId ? `<${niceId(fn.externalId)}>` : '',
24
- ].join(' ');
25
- fnDetails.push(`${name} ${ids}`);
26
- if ('parameters' in fn && fn.parameters) {
27
- fnDetails.push(arrayifyStackFunction(fn));
13
+ const RESOURCE_CATEGORIES = [
14
+ {
15
+ label: 'Functions',
16
+ match: (type) => type?.startsWith('sanity.function.'),
17
+ name: (res) => {
18
+ const name = chalk.bold.green(res.displayName || res.name || 'unnamed');
19
+ const ids = [
20
+ 'id' in res && res.id ? `${niceId(res.id)}` : '',
21
+ 'externalId' in res && res.externalId ? `<${niceId(res.externalId)}>` : '',
22
+ ].join(' ');
23
+ return `${name} ${ids}`;
24
+ },
25
+ formatDetails: arrayifyFunction,
26
+ },
27
+ {
28
+ label: 'CORS Origins',
29
+ match: (type) => type === 'sanity.project.cors',
30
+ name: (res) => {
31
+ const name = chalk.bold.yellow(res.displayName || res.name || 'unnamed');
32
+ const ids = [
33
+ 'id' in res && res.id ? `${niceId(res.id)}` : '',
34
+ 'externalId' in res && res.externalId ? `<${niceId(res.externalId)}>` : '',
35
+ ].join(' ');
36
+ return `${name} ${ids}`;
37
+ },
38
+ formatDetails: arraifyCors,
39
+ },
40
+ ];
41
+ const categorized = {};
42
+ const matchedIndices = new Set();
43
+ for (const [i, resource] of resources.entries()) {
44
+ for (const cat of RESOURCE_CATEGORIES) {
45
+ if (cat.match(resource.type)) {
46
+ if (!categorized[cat.label])
47
+ categorized[cat.label] = [];
48
+ categorized[cat.label].push(resource);
49
+ matchedIndices.add(i);
50
+ break;
28
51
  }
29
- else {
30
- fnDetails.push(arrayifyLocalFunction(fn));
52
+ }
53
+ }
54
+ // unmatched resources are 'Other Resources'
55
+ const otherResources = resources.filter((_, i) => !matchedIndices.has(i));
56
+ if (otherResources.length > 0) {
57
+ categorized['Other Resources'] = otherResources;
58
+ }
59
+ for (const category of RESOURCE_CATEGORIES) {
60
+ const catResources = categorized[category.label];
61
+ if (catResources && catResources.length > 0) {
62
+ const catOutput = [`${chalk.bold(category.label)} [${catResources.length}]`];
63
+ const details = [];
64
+ for (const res of catResources) {
65
+ details.push(category.name(res));
66
+ if (category.formatDetails)
67
+ details.push(category.formatDetails(res));
31
68
  }
69
+ catOutput.push(details);
70
+ output.push(catOutput);
32
71
  }
33
- fnsOutput.push(fnDetails);
34
- output.push(fnsOutput);
35
72
  }
36
- if (hasOtherResources) {
37
- const otherOutput = [`${chalk.bold('Other Resources')} [${otherResources.length}]`];
38
- const otherResourcesOutput = otherResources.map((other) => {
39
- return `"${chalk.yellow(other.displayName ?? other.name ?? 'unnamed')}"`;
73
+ if (categorized['Other Resources'] && categorized['Other Resources'].length > 0) {
74
+ const otherOutput = [
75
+ `${chalk.bold('Other Resources')} [${categorized['Other Resources'].length}]`,
76
+ ];
77
+ const otherResourcesOutput = categorized['Other Resources'].map((other) => {
78
+ return `${chalk.yellow(other.displayName ?? other.name ?? 'unnamed')}`;
40
79
  });
41
80
  otherOutput.push(otherResourcesOutput);
42
81
  output.push(otherOutput);
@@ -116,10 +155,10 @@ export function stackDeployDiff(localBlueprint, deployedStack) {
116
155
  return null;
117
156
  const output = [];
118
157
  if (added.length > 0) {
119
- output.push(` ${chalk.bold.greenBright('++')} ${added.map(({ name }) => `"${name}"`).join(', ')}`);
158
+ output.push(` ${chalk.bold.greenBright('++')} ${added.map(({ name }) => chalk.bgGreen.whiteBright(`"${name}"`)).join(' ')}`);
120
159
  }
121
160
  if (removed.length > 0) {
122
- output.push(` ${chalk.bold.redBright('--')} ${removed.map(({ name }) => `"${name}"`).join(', ')}`);
161
+ output.push(` ${chalk.bold.redBright('--')} ${removed.map(({ name }) => chalk.bgRed.whiteBright(`"${name}"`)).join(' ')}`);
123
162
  }
124
163
  return output.join('\n');
125
164
  }
@@ -1,4 +1,4 @@
1
1
  import type { TreeInput } from 'array-treeify';
2
- import type { LocalFunctionResource, StackFunctionResource } from '../../utils/types.js';
3
- export declare function arrayifyLocalFunction(fn: LocalFunctionResource): TreeInput;
4
- export declare function arrayifyStackFunction(fn: StackFunctionResource): TreeInput;
2
+ import type { CorsResource, FunctionResource } from '../../utils/types.js';
3
+ export declare function arrayifyFunction(fn: FunctionResource): TreeInput;
4
+ export declare function arraifyCors(resource: CorsResource): TreeInput;
@@ -20,7 +20,7 @@ function arrayifyEvent(event) {
20
20
  }
21
21
  return details;
22
22
  }
23
- export function arrayifyLocalFunction(fn) {
23
+ export function arrayifyFunction(fn) {
24
24
  const details = [`${chalk.dim('type:')} "${fn.type}"`];
25
25
  if (fn.memory)
26
26
  details.push(formatMemory(fn.memory));
@@ -35,18 +35,6 @@ export function arrayifyLocalFunction(fn) {
35
35
  }
36
36
  return details;
37
37
  }
38
- export function arrayifyStackFunction(fn) {
39
- const details = [`${chalk.dim('type:')} "${fn.type}"`];
40
- if (fn.parameters.memory)
41
- details.push(formatMemory(fn.parameters.memory));
42
- if (fn.parameters.timeout)
43
- details.push(formatTimeout(fn.parameters.timeout));
44
- if (fn.parameters.event) {
45
- const eventDetails = arrayifyEvent(fn.parameters.event);
46
- if (eventDetails) {
47
- details.push(`${chalk.dim('event:')}`);
48
- details.push(eventDetails);
49
- }
50
- }
51
- return details;
38
+ export function arraifyCors(resource) {
39
+ return [`${chalk.dim('origin:')} "${resource.origin}"`];
52
40
  }
@@ -1,4 +1,4 @@
1
- import type { LocalBlueprint, LocalFunctionResource, Stack, StackFunctionResource } from './types.js';
2
- export declare function findFunctionByName(blueprintOrStack: LocalBlueprint, name: string): LocalFunctionResource;
3
- export declare function findFunctionByName(blueprintOrStack: Stack, name: string): StackFunctionResource;
1
+ import type { DeployedResource, FunctionResource, LocalBlueprint, Stack } from './types.js';
2
+ export declare function findFunctionByName(blueprintOrStack: LocalBlueprint, name: string): FunctionResource;
3
+ export declare function findFunctionByName(blueprintOrStack: Stack, name: string): FunctionResource & DeployedResource;
4
4
  export declare function getFunctionSource(blueprintOrStack: LocalBlueprint | Stack, name: string): string;
@@ -8,9 +8,7 @@ export function findFunctionByName(blueprintOrStack, name) {
8
8
  }
9
9
  export function getFunctionSource(blueprintOrStack, name) {
10
10
  const func = findFunctionByName(blueprintOrStack, name);
11
- const src = 'parameters' in func
12
- ? func.parameters.src
13
- : func.src;
11
+ const { src } = func;
14
12
  if (!src)
15
13
  throw Error(`Function ${name} has no source code`);
16
14
  if (!existsSync(src))
@@ -1,2 +1,2 @@
1
- import type { LocalFunctionResource } from '../types.js';
2
- export declare function shouldBundleFunction(resource: LocalFunctionResource): Promise<boolean>;
1
+ import type { FunctionResource } from '../types.js';
2
+ export declare function shouldBundleFunction(resource: FunctionResource): Promise<boolean>;
@@ -1,4 +1,4 @@
1
- import type { GroqRule, InvocationResponse, InvokeContextOptions, InvokeExecutionOptions, LocalFunctionResource } from './types.js';
1
+ import type { FunctionResource, GroqRule, InvocationResponse, InvokeContextOptions, InvokeExecutionOptions } from './types.js';
2
2
  export declare function sanitizeLogs(logs: string): string;
3
3
  export declare const DEFAULT_GROQ_RULE: {
4
4
  on: string[];
@@ -6,5 +6,5 @@ export declare const DEFAULT_GROQ_RULE: {
6
6
  projection: string;
7
7
  };
8
8
  export declare function isDefaultGROQRule(rule: GroqRule | undefined): boolean;
9
- export declare function applyGroqRule(resource: LocalFunctionResource, data: Record<string, unknown> | null): Promise<any>;
10
- export default function invoke(resource: LocalFunctionResource, data: Record<string, unknown> | null, context: InvokeContextOptions, options: InvokeExecutionOptions): Promise<InvocationResponse>;
9
+ export declare function applyGroqRule(resource: FunctionResource, data: Record<string, unknown> | null): Promise<any>;
10
+ export default function invoke(resource: FunctionResource, data: Record<string, unknown> | null, context: InvokeContextOptions, options: InvokeExecutionOptions): Promise<InvocationResponse>;
@@ -26,7 +26,7 @@ export interface LocalBlueprint {
26
26
  /** @link https://github.com/sanity-io/blueprints-rfc/blob/main/readme.md#outputs */
27
27
  outputs?: Array<Record<string, unknown>>;
28
28
  /** @link https://github.com/sanity-io/blueprints-rfc/blob/main/readme.md#resources */
29
- resources?: Array<LocalResource | LocalFunctionResource>;
29
+ resources?: Array<Resource | FunctionResource>;
30
30
  /** @link https://github.com/sanity-io/blueprints-rfc/blob/main/readme.md#parameters */
31
31
  parameters?: Array<{
32
32
  name: string;
@@ -56,14 +56,20 @@ export interface LocalBlueprint {
56
56
  metadata?: Record<string, unknown>;
57
57
  }
58
58
  /** @internal */
59
- export interface LocalResource {
59
+ export interface Resource {
60
60
  name: string;
61
61
  type: string;
62
+ id?: string;
63
+ externalId?: string;
62
64
  displayName?: string;
63
65
  }
64
- export declare function isLocalFunctionResource(r: LocalResource): r is LocalFunctionResource;
66
+ export interface DeployedResource extends Resource {
67
+ id: string;
68
+ externalId: string;
69
+ }
70
+ export declare function isLocalFunctionResource(r: Resource): r is FunctionResource;
65
71
  /** @internal */
66
- export interface LocalFunctionResource extends LocalResource {
72
+ export interface FunctionResource extends Resource {
67
73
  src?: string;
68
74
  bundle?: boolean;
69
75
  memory?: number;
@@ -71,36 +77,20 @@ export interface LocalFunctionResource extends LocalResource {
71
77
  env?: Record<string, string>;
72
78
  event?: GroqRule;
73
79
  }
80
+ export interface CorsResource extends Resource {
81
+ origin?: string;
82
+ }
74
83
  export interface Stack {
75
84
  id: string;
76
85
  name: string;
77
86
  displayName: string;
78
87
  projectId: string;
79
- resources: Array<StackResource>;
88
+ resources: Array<DeployedResource>;
80
89
  createdAt?: string;
81
90
  updatedAt?: string;
82
91
  recentOperation?: StackOperation;
83
92
  }
84
93
  /** @internal */
85
- export interface StackResource {
86
- id: string;
87
- name: string;
88
- type: string;
89
- externalId: string;
90
- displayName?: string;
91
- parameters?: Record<string, unknown>;
92
- }
93
- /** @internal */
94
- export interface StackFunctionResource extends StackResource {
95
- parameters: {
96
- src: string;
97
- memory?: number;
98
- timeout?: number;
99
- env?: Record<string, string>;
100
- event?: GroqRule;
101
- };
102
- }
103
- /** @internal */
104
94
  export interface StackOperation {
105
95
  id: string;
106
96
  status: string;
@@ -108,7 +98,7 @@ export interface StackOperation {
108
98
  completedAt?: string;
109
99
  }
110
100
  /** @internal */
111
- export interface StackPayload {
101
+ export interface StackMutation {
112
102
  name: string;
113
103
  projectId: string;
114
104
  document: LocalBlueprint;
@@ -1,4 +1,4 @@
1
- import type { LocalFunctionResource } from '../types.js';
1
+ import type { FunctionResource } from '../types.js';
2
2
  import { type BlueprintParserError } from '../types.js';
3
3
  export declare function validateFunctionName(name: string): boolean;
4
- export declare function validateFunctionResource(resource: LocalFunctionResource): BlueprintParserError[];
4
+ export declare function validateFunctionResource(resource: FunctionResource): BlueprintParserError[];
@@ -871,5 +871,5 @@
871
871
  ]
872
872
  }
873
873
  },
874
- "version": "8.1.6"
874
+ "version": "8.2.0"
875
875
  }
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": "8.1.6",
4
+ "version": "8.2.0",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",