@sanity/runtime-cli 2.2.0 → 2.3.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/2.2.0 linux-x64 node-v22.14.0
23
+ @sanity/runtime-cli/2.3.0 linux-x64 node-v22.14.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -63,7 +63,7 @@ EXAMPLES
63
63
  $ sanity-run blueprints add function
64
64
  ```
65
65
 
66
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/blueprints/add.ts)_
66
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/add.ts)_
67
67
 
68
68
  ## `sanity-run blueprints config`
69
69
 
@@ -85,7 +85,7 @@ EXAMPLES
85
85
  $ sanity-run blueprints config --edit
86
86
  ```
87
87
 
88
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/blueprints/config.ts)_
88
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/config.ts)_
89
89
 
90
90
  ## `sanity-run blueprints deploy`
91
91
 
@@ -102,7 +102,7 @@ EXAMPLES
102
102
  $ sanity-run blueprints deploy
103
103
  ```
104
104
 
105
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/blueprints/deploy.ts)_
105
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/deploy.ts)_
106
106
 
107
107
  ## `sanity-run blueprints info`
108
108
 
@@ -124,7 +124,7 @@ EXAMPLES
124
124
  $ sanity-run blueprints info --id abc123
125
125
  ```
126
126
 
127
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/blueprints/info.ts)_
127
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/info.ts)_
128
128
 
129
129
  ## `sanity-run blueprints init`
130
130
 
@@ -141,7 +141,7 @@ EXAMPLES
141
141
  $ sanity-run blueprints init
142
142
  ```
143
143
 
144
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/blueprints/init.ts)_
144
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/init.ts)_
145
145
 
146
146
  ## `sanity-run blueprints logs`
147
147
 
@@ -163,7 +163,7 @@ EXAMPLES
163
163
  $ sanity-run blueprints logs --watch
164
164
  ```
165
165
 
166
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/blueprints/logs.ts)_
166
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/logs.ts)_
167
167
 
168
168
  ## `sanity-run blueprints plan`
169
169
 
@@ -180,7 +180,7 @@ EXAMPLES
180
180
  $ sanity-run blueprints plan
181
181
  ```
182
182
 
183
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/blueprints/plan.ts)_
183
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/plan.ts)_
184
184
 
185
185
  ## `sanity-run blueprints stacks`
186
186
 
@@ -197,7 +197,7 @@ EXAMPLES
197
197
  $ sanity-run blueprints stacks
198
198
  ```
199
199
 
200
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/blueprints/stacks.ts)_
200
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/stacks.ts)_
201
201
 
202
202
  ## `sanity-run functions dev`
203
203
 
@@ -217,7 +217,7 @@ EXAMPLES
217
217
  $ sanity-run functions dev --port 8974
218
218
  ```
219
219
 
220
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/functions/dev.ts)_
220
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/dev.ts)_
221
221
 
222
222
  ## `sanity-run functions env add NAME KEY VALUE`
223
223
 
@@ -239,7 +239,7 @@ EXAMPLES
239
239
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
240
240
  ```
241
241
 
242
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/functions/env/add.ts)_
242
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/env/add.ts)_
243
243
 
244
244
  ## `sanity-run functions env remove NAME KEY`
245
245
 
@@ -260,7 +260,7 @@ EXAMPLES
260
260
  $ sanity-run functions env remove MyFunction API_URL
261
261
  ```
262
262
 
263
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/functions/env/remove.ts)_
263
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/env/remove.ts)_
264
264
 
265
265
  ## `sanity-run functions invoke NAME`
266
266
 
@@ -281,12 +281,12 @@ DESCRIPTION
281
281
  Invoke a remote Sanity Function
282
282
 
283
283
  EXAMPLES
284
- $ sanity-run functions invoke <ID> --data '{ "id": 1 }'
284
+ $ sanity-run functions invoke <name> --data '{ "id": 1 }'
285
285
 
286
- $ sanity-run functions invoke <ID> --file 'payload.json'
286
+ $ sanity-run functions invoke <name> --file 'payload.json'
287
287
  ```
288
288
 
289
- _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/functions/invoke.ts)_
289
+ _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/invoke.ts)_
290
290
 
291
291
  ## `sanity-run functions logs NAME`
292
292
 
@@ -294,19 +294,27 @@ Retrieve logs for a Sanity Function
294
294
 
295
295
  ```
296
296
  USAGE
297
- $ sanity-run functions logs NAME
297
+ $ sanity-run functions logs NAME [-l <value>] [-j]
298
298
 
299
299
  ARGUMENTS
300
300
  NAME The name of the Sanity Function
301
301
 
302
+ FLAGS
303
+ -j, --json Return logs in JSON format
304
+ -l, --limit=<value> [default: 50] Total number of log entries to retrieve
305
+
302
306
  DESCRIPTION
303
307
  Retrieve logs for a Sanity Function
304
308
 
305
309
  EXAMPLES
306
- $ sanity-run functions logs <ID>
310
+ $ sanity-run functions logs <name>
311
+
312
+ $ sanity-run functions logs <name> --json
313
+
314
+ $ sanity-run functions logs <name> --limit 100
307
315
  ```
308
316
 
309
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/functions/logs.ts)_
317
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/logs.ts)_
310
318
 
311
319
  ## `sanity-run functions test NAME`
312
320
 
@@ -328,14 +336,14 @@ DESCRIPTION
328
336
  Invoke a local Sanity Function
329
337
 
330
338
  EXAMPLES
331
- $ sanity-run functions test echo-fn --data '{ "id": 1 }'
339
+ $ sanity-run functions test <name> --data '{ "id": 1 }'
332
340
 
333
- $ sanity-run functions test echo-fn --file 'payload.json'
341
+ $ sanity-run functions test <name> --file 'payload.json'
334
342
 
335
- $ sanity-run functions test echo-fn --data '{ "id": 1 }' --timeout 60
343
+ $ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
336
344
  ```
337
345
 
338
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/functions/test.ts)_
346
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/test.ts)_
339
347
 
340
348
  ## `sanity-run help [COMMAND]`
341
349
 
@@ -1,6 +1,11 @@
1
1
  import type { AuthParams } from '../../utils/types.js';
2
- export declare function logs(id: string, auth: AuthParams): Promise<{
2
+ /** internal */
3
+ export interface LoggingOptions {
4
+ limit: number;
5
+ }
6
+ export declare function logs(id: string, options: LoggingOptions, auth: AuthParams): Promise<{
3
7
  ok: boolean;
4
8
  error: any;
5
9
  logs: any;
10
+ total: any;
6
11
  }>;
@@ -1,8 +1,9 @@
1
1
  import config from '../../config.js';
2
2
  import getHeaders from '../../utils/get-headers.js';
3
3
  const { functions } = config.server;
4
- export async function logs(id, auth) {
5
- const response = await fetch(`${functions}vX/functions/${id}/logs`, {
4
+ export async function logs(id, options, auth) {
5
+ const { limit } = options;
6
+ const response = await fetch(`${functions}vX/functions/${id}/logs?limit=${limit}`, {
6
7
  headers: getHeaders(auth),
7
8
  method: 'GET',
8
9
  });
@@ -11,5 +12,6 @@ export async function logs(id, auth) {
11
12
  ok: response.ok,
12
13
  error: response.ok ? null : json?.error?.message,
13
14
  logs: response.ok ? json.logs : [],
15
+ total: response.ok ? json.total : 0,
14
16
  };
15
17
  }
@@ -11,8 +11,8 @@ export default class Invoke extends Command {
11
11
  };
12
12
  static description = 'Invoke a remote Sanity Function';
13
13
  static examples = [
14
- `<%= config.bin %> <%= command.id %> <ID> --data '{ "id": 1 }'`,
15
- `<%= config.bin %> <%= command.id %> <ID> --file 'payload.json'`,
14
+ `<%= config.bin %> <%= command.id %> <name> --data '{ "id": 1 }'`,
15
+ `<%= config.bin %> <%= command.id %> <name> --file 'payload.json'`,
16
16
  ];
17
17
  static flags = {
18
18
  data: Flags.string({ char: 'd', description: 'Data to send to the function', required: false }),
@@ -5,5 +5,9 @@ export default class Logs extends Command {
5
5
  };
6
6
  static description: string;
7
7
  static examples: string[];
8
+ static flags: {
9
+ limit: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
10
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ };
8
12
  run(): Promise<void>;
9
13
  }
@@ -1,4 +1,4 @@
1
- import { Args, Command } from '@oclif/core';
1
+ import { Args, Command, Flags } from '@oclif/core';
2
2
  import Spinner from 'yocto-spinner';
3
3
  import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
4
4
  import { logs as logsAction } from '../../actions/functions/logs.js';
@@ -10,7 +10,7 @@ function logLevel(level) {
10
10
  if (level === 'ERROR') {
11
11
  return red(level);
12
12
  }
13
- if (level === 'ERROR') {
13
+ if (level === 'WARN') {
14
14
  return yellow(level);
15
15
  }
16
16
  return green(level);
@@ -20,16 +20,33 @@ export default class Logs extends Command {
20
20
  name: Args.string({ description: 'The name of the Sanity Function', required: true }),
21
21
  };
22
22
  static description = 'Retrieve logs for a Sanity Function';
23
- static examples = ['<%= config.bin %> <%= command.id %> <ID>'];
23
+ static examples = [
24
+ '<%= config.bin %> <%= command.id %> <name>',
25
+ '<%= config.bin %> <%= command.id %> <name> --json',
26
+ '<%= config.bin %> <%= command.id %> <name> --limit 100',
27
+ ];
28
+ static flags = {
29
+ limit: Flags.integer({
30
+ char: 'l',
31
+ description: 'Total number of log entries to retrieve',
32
+ required: false,
33
+ default: 50,
34
+ }),
35
+ json: Flags.boolean({
36
+ char: 'j',
37
+ description: 'Return logs in JSON format',
38
+ required: false,
39
+ }),
40
+ };
24
41
  async run() {
25
- const { args } = await this.parse(Logs);
42
+ const { args, flags } = await this.parse(Logs);
26
43
  const spinner = Spinner({ text: `Finding logs for function "${args.name}"` }).start();
27
44
  const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token: config.token });
28
45
  if (!deployedStack)
29
46
  this.error('Stack not found'); // returns
30
- const { name, projectId } = deployedStack;
47
+ const { projectId } = deployedStack;
31
48
  const { externalId } = findFunctionByName(deployedStack, args.name);
32
- const { ok, error, logs } = await logsAction(externalId, { token: config.token, projectId });
49
+ const { ok, error, logs, total } = await logsAction(externalId, { limit: flags.limit }, { token: config.token, projectId });
33
50
  if (!ok) {
34
51
  spinner.error(`${red('Failed')} to retrieve logs`);
35
52
  this.log(`Error: ${error || 'Unknown error'}`);
@@ -41,11 +58,20 @@ export default class Logs extends Command {
41
58
  return;
42
59
  }
43
60
  spinner.success(`${formatTitle('Function', args.name)} Logs`);
44
- this.log(`Found ${bold(filteredLogs.length.toString())} log entries for function ${yellow(args.name)}\n`);
45
- for (const log of filteredLogs) {
46
- const { time, level, message } = log;
47
- const date = new Date(time);
48
- this.log(`${bold(date.toLocaleDateString())} ${bold(blue(date.toLocaleTimeString()))} ${logLevel(level)} ${message}`);
61
+ if (!flags.json) {
62
+ this.log(`Found ${bold(total)} log entries for function ${yellow(args.name)}`);
63
+ if (logs.length < total) {
64
+ this.log(`Here are the last ${bold(filteredLogs.length.toString())} entries`);
65
+ }
66
+ this.log('\n');
67
+ for (const log of filteredLogs) {
68
+ const { time, level, message } = log;
69
+ const date = new Date(time);
70
+ this.log(`${bold(date.toLocaleDateString())} ${bold(blue(date.toLocaleTimeString()))} ${logLevel(level)} ${message}`);
71
+ }
72
+ }
73
+ else {
74
+ this.log(JSON.stringify(filteredLogs, null, 2));
49
75
  }
50
76
  }
51
77
  }
@@ -8,9 +8,9 @@ export default class Test extends Command {
8
8
  };
9
9
  static description = 'Invoke a local Sanity Function';
10
10
  static examples = [
11
- `<%= config.bin %> <%= command.id %> echo-fn --data '{ "id": 1 }'`,
12
- `<%= config.bin %> <%= command.id %> echo-fn --file 'payload.json'`,
13
- `<%= config.bin %> <%= command.id %> echo-fn --data '{ "id": 1 }' --timeout 60`,
11
+ `<%= config.bin %> <%= command.id %> <name> --data '{ "id": 1 }'`,
12
+ `<%= config.bin %> <%= command.id %> <name> --file 'payload.json'`,
13
+ `<%= config.bin %> <%= command.id %> <name> --data '{ "id": 1 }' --timeout 60`,
14
14
  ];
15
15
  static flags = {
16
16
  data: Flags.string({ char: 'd', description: 'Data to send to the function', required: false }),
@@ -0,0 +1,4 @@
1
+ import type { BlueprintError } from './types.js';
2
+ export default function formatError(response: Response, json: {
3
+ error: BlueprintError;
4
+ }): string | null;
@@ -0,0 +1,9 @@
1
+ export default function formatError(response, json) {
2
+ if (response.ok) {
3
+ return null;
4
+ }
5
+ if (response.status === 401 || response.status === 403) {
6
+ return 'Please login to the Sanity CLI to run this command';
7
+ }
8
+ return json?.error?.message || 'Unknown Error';
9
+ }
@@ -274,8 +274,8 @@
274
274
  },
275
275
  "description": "Invoke a remote Sanity Function",
276
276
  "examples": [
277
- "<%= config.bin %> <%= command.id %> <ID> --data '{ \"id\": 1 }'",
278
- "<%= config.bin %> <%= command.id %> <ID> --file 'payload.json'"
277
+ "<%= config.bin %> <%= command.id %> <name> --data '{ \"id\": 1 }'",
278
+ "<%= config.bin %> <%= command.id %> <name> --file 'payload.json'"
279
279
  ],
280
280
  "flags": {
281
281
  "data": {
@@ -324,9 +324,30 @@
324
324
  },
325
325
  "description": "Retrieve logs for a Sanity Function",
326
326
  "examples": [
327
- "<%= config.bin %> <%= command.id %> <ID>"
327
+ "<%= config.bin %> <%= command.id %> <name>",
328
+ "<%= config.bin %> <%= command.id %> <name> --json",
329
+ "<%= config.bin %> <%= command.id %> <name> --limit 100"
328
330
  ],
329
- "flags": {},
331
+ "flags": {
332
+ "limit": {
333
+ "char": "l",
334
+ "description": "Total number of log entries to retrieve",
335
+ "name": "limit",
336
+ "required": false,
337
+ "default": 50,
338
+ "hasDynamicHelp": false,
339
+ "multiple": false,
340
+ "type": "option"
341
+ },
342
+ "json": {
343
+ "char": "j",
344
+ "description": "Return logs in JSON format",
345
+ "name": "json",
346
+ "required": false,
347
+ "allowNo": false,
348
+ "type": "boolean"
349
+ }
350
+ },
330
351
  "hasDynamicHelp": false,
331
352
  "hiddenAliases": [],
332
353
  "id": "functions:logs",
@@ -354,9 +375,9 @@
354
375
  },
355
376
  "description": "Invoke a local Sanity Function",
356
377
  "examples": [
357
- "<%= config.bin %> <%= command.id %> echo-fn --data '{ \"id\": 1 }'",
358
- "<%= config.bin %> <%= command.id %> echo-fn --file 'payload.json'",
359
- "<%= config.bin %> <%= command.id %> echo-fn --data '{ \"id\": 1 }' --timeout 60"
378
+ "<%= config.bin %> <%= command.id %> <name> --data '{ \"id\": 1 }'",
379
+ "<%= config.bin %> <%= command.id %> <name> --file 'payload.json'",
380
+ "<%= config.bin %> <%= command.id %> <name> --data '{ \"id\": 1 }' --timeout 60"
360
381
  ],
361
382
  "flags": {
362
383
  "data": {
@@ -481,5 +502,5 @@
481
502
  ]
482
503
  }
483
504
  },
484
- "version": "2.2.0"
505
+ "version": "2.3.0"
485
506
  }
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": "2.2.0",
4
+ "version": "2.3.0",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",