@sanity/runtime-cli 3.2.0 → 4.1.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.
@@ -1,12 +1,12 @@
1
1
  import { treeify } from 'array-treeify';
2
- import { blue, bold, boldnblue, green, red, yellow } from './colors.js';
2
+ import { blue, bold, boldnblue, green, niceId, red, yellow } from './colors.js';
3
3
  import { formatDate, formatDuration } from './dates.js';
4
4
  export function formatTitle(title, name) {
5
5
  return `${boldnblue(title)} ${bold(`"${name}"`)}`;
6
6
  }
7
7
  export function formatResourceTree(resources) {
8
8
  if (!resources || resources.length === 0) {
9
- return ' No resources in this stack';
9
+ return ' Zero resources in this stack';
10
10
  }
11
11
  const output = [];
12
12
  output.push(`${blue('Stack Resources')} [${resources.length}]`);
@@ -18,7 +18,7 @@ export function formatResourceTree(resources) {
18
18
  functionsOutput.push(`${bold('Functions')} [${functionResources.length}]`);
19
19
  const functionResourcesOutput = functionResources.map((fn) => {
20
20
  const name = green(fn.displayName || fn.name);
21
- const externalId = fn.externalId ? `Fn<${yellow(fn.externalId)}>` : '';
21
+ const externalId = fn.externalId ? `Fn${niceId(fn.externalId)}` : '';
22
22
  return `"${name}" ${externalId}`;
23
23
  });
24
24
  functionsOutput.push(functionResourcesOutput);
@@ -38,17 +38,20 @@ export function formatResourceTree(resources) {
38
38
  export function formatStackInfo(stack, isCurrentStack = false) {
39
39
  const output = [];
40
40
  const isStack = 'id' in stack;
41
+ const infoOutput = [];
41
42
  if (isStack) {
42
43
  const stackName = isCurrentStack ? boldnblue(stack.name) : bold(stack.name);
43
- output.push(`"${stackName}" <${yellow(stack.id)}>${isCurrentStack ? ' (current)' : ''}`);
44
+ output.push(`"${stackName}" ${niceId(stack.id)}${isCurrentStack ? ' (current)' : ''}`);
44
45
  }
45
46
  else {
46
47
  output.push('Local Blueprint');
47
48
  }
48
- const infoOutput = [];
49
49
  if (stack.resources) {
50
50
  infoOutput.push(`${stack.resources.length} resource${stack.resources.length === 1 ? '' : 's'}`);
51
51
  }
52
+ else {
53
+ infoOutput.push('No resources');
54
+ }
52
55
  if (isStack) {
53
56
  if (stack.createdAt)
54
57
  infoOutput.push(`Created: ${formatDate(stack.createdAt)}`);
@@ -58,7 +61,7 @@ export function formatStackInfo(stack, isCurrentStack = false) {
58
61
  const operation = stack.recentOperation;
59
62
  const operationOutput = [];
60
63
  if (operation.id)
61
- operationOutput.push(`Recent Operation <${yellow(operation.id)}>:`);
64
+ operationOutput.push(`Recent Operation ${niceId(operation.id)}:`);
62
65
  if (operation.status) {
63
66
  const operationColor = operation.status === 'COMPLETED' ? green : red;
64
67
  const status = operation.status || 'UNKNOWN';
@@ -1,4 +1,5 @@
1
1
  export declare function bold(str: string): string;
2
+ export declare function underline(str: string): string;
2
3
  export declare function dim(str: string): string;
3
4
  export declare function blue(str: string): string;
4
5
  export declare function green(str: string): string;
@@ -2,6 +2,9 @@ import chalk from 'chalk';
2
2
  export function bold(str) {
3
3
  return chalk.bold(str);
4
4
  }
5
+ export function underline(str) {
6
+ return chalk.underline(str);
7
+ }
5
8
  export function dim(str) {
6
9
  return chalk.dim(str);
7
10
  }
@@ -1,2 +1,3 @@
1
1
  import type { InvocationResponse, InvokeContextOptions } from './types.js';
2
+ export declare function sanitizeLogs(logs: string): string;
2
3
  export default function invoke(srcPath: string, data: null | object, context: InvokeContextOptions, timeout?: number): Promise<InvocationResponse>;
@@ -5,6 +5,9 @@ import config from '../config.js';
5
5
  function getChildProcessWrapperPath() {
6
6
  return new URL('./child-process-wrapper.js', import.meta.url).pathname;
7
7
  }
8
+ export function sanitizeLogs(logs) {
9
+ return logs.replace(/[a-zA-Z0-9]{75}/g, '*'.repeat(10));
10
+ }
8
11
  export default async function invoke(srcPath, data, context, timeout = 5) {
9
12
  return new Promise((resolve, reject) => {
10
13
  let child;
@@ -18,7 +21,7 @@ export default async function invoke(srcPath, data, context, timeout = 5) {
18
21
  child.on('message', (data) => {
19
22
  const { json, logs } = JSON.parse(data.toString());
20
23
  shutdown();
21
- resolve({ json, logs, error: '' });
24
+ resolve({ json, logs: sanitizeLogs(logs), error: '' });
22
25
  });
23
26
  child.on('error', (error) => {
24
27
  reject(new Error(`encountered error ${error.message}`));
@@ -40,9 +43,12 @@ export default async function invoke(srcPath, data, context, timeout = 5) {
40
43
  const payload = {
41
44
  ...data,
42
45
  context: {
43
- apiHost: config.apiUrl,
44
- token: config.token,
45
46
  ...context,
47
+ clientOptions: {
48
+ ...context.clientOptions,
49
+ apiHost: config.apiUrl,
50
+ token: config.token,
51
+ },
46
52
  },
47
53
  };
48
54
  child.send(JSON.stringify({ srcPath, payload }, null, 2));
@@ -5,10 +5,41 @@ export interface AuthParams {
5
5
  }
6
6
  /** @internal */
7
7
  export interface LocalBlueprint {
8
+ /** @link https://github.com/sanity-io/blueprints-rfc/blob/main/readme.md#versioning */
8
9
  blueprintVersion?: string;
10
+ /** @link https://github.com/sanity-io/blueprints-rfc/blob/main/readme.md#values */
9
11
  values?: Record<string, unknown>;
12
+ /** @link https://github.com/sanity-io/blueprints-rfc/blob/main/readme.md#outputs */
10
13
  outputs?: Array<Record<string, unknown>>;
14
+ /** @link https://github.com/sanity-io/blueprints-rfc/blob/main/readme.md#resources */
11
15
  resources?: Array<LocalResource>;
16
+ /** @link https://github.com/sanity-io/blueprints-rfc/blob/main/readme.md#parameters */
17
+ parameters?: Array<{
18
+ name: string;
19
+ type: 'arg' | 'argument' | 'env-var' | 'envVar' | 'config' | 'stdin';
20
+ } & ({
21
+ type: 'arg' | 'argument';
22
+ argument: string;
23
+ 'env-var'?: never;
24
+ setting?: never;
25
+ } | {
26
+ type: 'env-var' | 'envVar';
27
+ 'env-var': string;
28
+ argument?: never;
29
+ setting?: never;
30
+ } | {
31
+ type: 'config';
32
+ setting: string;
33
+ 'env-var'?: never;
34
+ argument?: never;
35
+ } | {
36
+ type: 'stdin';
37
+ 'env-var'?: never;
38
+ argument?: never;
39
+ setting?: never;
40
+ })>;
41
+ /** @link https://github.com/sanity-io/blueprints-rfc/blob/main/readme.md#arbitrary-userland-data */
42
+ metadata?: Record<string, unknown>;
12
43
  }
13
44
  /** @internal */
14
45
  export interface LocalResource {
@@ -73,9 +104,11 @@ export interface InvokePayloadOptions {
73
104
  }
74
105
  /** @internal */
75
106
  export interface InvokeContextOptions {
76
- apiVersion?: string;
77
- dataset?: string;
78
- projectId?: string;
107
+ clientOptions: {
108
+ apiVersion?: string;
109
+ dataset?: string;
110
+ projectId?: string;
111
+ };
79
112
  }
80
113
  /** @internal */
81
114
  export interface InvocationResponse {
@@ -89,6 +122,7 @@ export interface BlueprintLog {
89
122
  message: string;
90
123
  stackId: string;
91
124
  level: string;
125
+ metadata?: Record<string, unknown>;
92
126
  }
93
127
  /** @internal */
94
128
  export interface FunctionLog {
@@ -72,7 +72,14 @@
72
72
  "examples": [
73
73
  "<%= config.bin %> <%= command.id %>"
74
74
  ],
75
- "flags": {},
75
+ "flags": {
76
+ "no-wait": {
77
+ "description": "Do not wait for deployment to complete",
78
+ "name": "no-wait",
79
+ "allowNo": false,
80
+ "type": "boolean"
81
+ }
82
+ },
76
83
  "hasDynamicHelp": false,
77
84
  "hiddenAliases": [],
78
85
  "id": "blueprints:deploy",
@@ -132,10 +139,10 @@
132
139
  "blueprints:info": {
133
140
  "aliases": [],
134
141
  "args": {},
135
- "description": "Show information about a Blueprint",
142
+ "description": "Show information about a deployed Blueprint Stack",
136
143
  "examples": [
137
144
  "<%= config.bin %> <%= command.id %>",
138
- "<%= config.bin %> <%= command.id %> --id abc123"
145
+ "<%= config.bin %> <%= command.id %> --id ST-a1b2c3"
139
146
  ],
140
147
  "flags": {
141
148
  "id": {
@@ -250,9 +257,19 @@
250
257
  "args": {},
251
258
  "description": "List all Blueprint stacks",
252
259
  "examples": [
253
- "<%= config.bin %> <%= command.id %>"
260
+ "<%= config.bin %> <%= command.id %>",
261
+ "<%= config.bin %> <%= command.id %> --projectId a1b2c3"
254
262
  ],
255
- "flags": {},
263
+ "flags": {
264
+ "projectId": {
265
+ "description": "Project ID to show stacks for",
266
+ "name": "projectId",
267
+ "required": false,
268
+ "hasDynamicHelp": false,
269
+ "multiple": false,
270
+ "type": "option"
271
+ }
272
+ },
256
273
  "hasDynamicHelp": false,
257
274
  "hiddenAliases": [],
258
275
  "id": "blueprints:stacks",
@@ -591,5 +608,5 @@
591
608
  ]
592
609
  }
593
610
  },
594
- "version": "3.2.0"
611
+ "version": "4.1.0"
595
612
  }
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": "3.2.0",
4
+ "version": "4.1.0",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",