@sanity/runtime-cli 2.1.0 → 2.1.1
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 +15 -15
- package/dist/actions/functions/logs.js +3 -3
- package/dist/commands/functions/logs.js +28 -24
- package/dist/utils/types.d.ts +3 -9
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
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.1.
|
|
23
|
+
@sanity/runtime-cli/2.1.1 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.1.
|
|
66
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/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.1.
|
|
88
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/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.1.
|
|
105
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/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.1.
|
|
127
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/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.1.
|
|
144
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/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.1.
|
|
166
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/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.1.
|
|
183
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/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.1.
|
|
200
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/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.1.
|
|
220
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/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.1.
|
|
242
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/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.1.
|
|
263
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/functions/env/remove.ts)_
|
|
264
264
|
|
|
265
265
|
## `sanity-run functions invoke NAME`
|
|
266
266
|
|
|
@@ -286,7 +286,7 @@ EXAMPLES
|
|
|
286
286
|
$ sanity-run functions invoke <ID> --file 'payload.json'
|
|
287
287
|
```
|
|
288
288
|
|
|
289
|
-
_See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.
|
|
289
|
+
_See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/functions/invoke.ts)_
|
|
290
290
|
|
|
291
291
|
## `sanity-run functions logs NAME`
|
|
292
292
|
|
|
@@ -306,7 +306,7 @@ EXAMPLES
|
|
|
306
306
|
$ sanity-run functions logs <ID>
|
|
307
307
|
```
|
|
308
308
|
|
|
309
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.
|
|
309
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/functions/logs.ts)_
|
|
310
310
|
|
|
311
311
|
## `sanity-run functions test NAME`
|
|
312
312
|
|
|
@@ -335,7 +335,7 @@ EXAMPLES
|
|
|
335
335
|
$ sanity-run functions test echo-fn --data '{ "id": 1 }' --timeout 60
|
|
336
336
|
```
|
|
337
337
|
|
|
338
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.
|
|
338
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/functions/test.ts)_
|
|
339
339
|
|
|
340
340
|
## `sanity-run help [COMMAND]`
|
|
341
341
|
|
|
@@ -6,10 +6,10 @@ export async function logs(id, auth) {
|
|
|
6
6
|
headers: getHeaders(auth),
|
|
7
7
|
method: 'GET',
|
|
8
8
|
});
|
|
9
|
-
const
|
|
9
|
+
const json = await response.json();
|
|
10
10
|
return {
|
|
11
11
|
ok: response.ok,
|
|
12
|
-
error: response.ok ? null :
|
|
13
|
-
logs: response.ok ? logs : [],
|
|
12
|
+
error: response.ok ? null : json?.error?.message,
|
|
13
|
+
logs: response.ok ? json.logs : [],
|
|
14
14
|
};
|
|
15
15
|
}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { Args, Command } from '@oclif/core';
|
|
2
2
|
import Spinner from 'yocto-spinner';
|
|
3
3
|
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
4
|
-
import { logs } from '../../actions/functions/logs.js';
|
|
4
|
+
import { logs as logsAction } from '../../actions/functions/logs.js';
|
|
5
5
|
import config from '../../config.js';
|
|
6
|
-
import {
|
|
6
|
+
import { formatTitle } from '../../utils/display/blueprints-formatting.js';
|
|
7
|
+
import { blue, bold, green, red, yellow } from '../../utils/display/colors.js';
|
|
7
8
|
import { findFunctionByName } from '../../utils/find-function.js';
|
|
9
|
+
function logLevel(level) {
|
|
10
|
+
if (level === 'ERROR') {
|
|
11
|
+
return red(level);
|
|
12
|
+
}
|
|
13
|
+
if (level === 'ERROR') {
|
|
14
|
+
return yellow(level);
|
|
15
|
+
}
|
|
16
|
+
return green(level);
|
|
17
|
+
}
|
|
8
18
|
export default class Logs extends Command {
|
|
9
19
|
static args = {
|
|
10
20
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
@@ -19,29 +29,23 @@ export default class Logs extends Command {
|
|
|
19
29
|
this.error('Stack not found'); // returns
|
|
20
30
|
const { name, projectId } = deployedStack;
|
|
21
31
|
const { externalId } = findFunctionByName(deployedStack, args.name);
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
spinner.success(`Found logs ${args.name} for blueprint "${name}"`);
|
|
25
|
-
for (const logGroup of result.logs) {
|
|
26
|
-
for (const log of logGroup.events) {
|
|
27
|
-
const { message, timestamp } = log;
|
|
28
|
-
// INFO log format: year month date hr min sec ms req uuid
|
|
29
|
-
const logPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\s+[0-9a-f-]+/;
|
|
30
|
-
if (logPattern.test(message)) {
|
|
31
|
-
const content = message.replace(logPattern, '').trim().replace(/^INFO/, '').trim();
|
|
32
|
-
if (content) {
|
|
33
|
-
const date = new Date(timestamp);
|
|
34
|
-
const time = date.toLocaleTimeString();
|
|
35
|
-
const day = date.toLocaleDateString();
|
|
36
|
-
this.log(` ${bold(day)} ${yellow(time)} ${content}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
32
|
+
const { ok, error, logs } = await logsAction(externalId, { token: config.token, projectId });
|
|
33
|
+
if (!ok) {
|
|
43
34
|
spinner.error(`${red('Failed')} to retrieve logs`);
|
|
44
|
-
this.log(`Error: ${
|
|
35
|
+
this.log(`Error: ${error || 'Unknown error'}`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const filteredLogs = logs.filter((entry) => entry.level && entry.message);
|
|
39
|
+
if (filteredLogs.length === 0) {
|
|
40
|
+
spinner.info(`No logs found for function ${args.name}`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
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}`);
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
}
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -84,15 +84,9 @@ export interface AuthParams {
|
|
|
84
84
|
}
|
|
85
85
|
/** @internal */
|
|
86
86
|
export interface FunctionLog {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
time: string;
|
|
88
|
+
requestId: string;
|
|
89
|
+
level: string;
|
|
90
90
|
message: string;
|
|
91
91
|
}
|
|
92
|
-
/** @internal */
|
|
93
|
-
export interface FunctionLogGroup {
|
|
94
|
-
events: Array<FunctionLog>;
|
|
95
|
-
nextBackwardToken: string;
|
|
96
|
-
nextForwardToken: string;
|
|
97
|
-
}
|
|
98
92
|
export {};
|
package/oclif.manifest.json
CHANGED