@sanity/runtime-cli 2.0.2 → 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 +58 -13
- package/dist/actions/functions/env/index.d.ts +6 -0
- package/dist/actions/functions/env/index.js +6 -0
- package/dist/actions/functions/env/remove.d.ts +5 -0
- package/dist/actions/functions/env/remove.js +14 -0
- package/dist/actions/functions/env/update.d.ts +5 -0
- package/dist/actions/functions/env/update.js +15 -0
- package/dist/actions/functions/index.d.ts +4 -0
- package/dist/actions/functions/index.js +2 -0
- package/dist/actions/functions/logs.js +3 -3
- package/dist/commands/functions/env/add.d.ts +11 -0
- package/dist/commands/functions/env/add.js +40 -0
- package/dist/commands/functions/env/remove.d.ts +10 -0
- package/dist/commands/functions/env/remove.js +37 -0
- package/dist/commands/functions/logs.js +28 -24
- package/dist/utils/types.d.ts +3 -9
- package/oclif.manifest.json +78 -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.
|
|
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
|
|
@@ -38,6 +38,8 @@ USAGE
|
|
|
38
38
|
* [`sanity-run blueprints plan`](#sanity-run-blueprints-plan)
|
|
39
39
|
* [`sanity-run blueprints stacks`](#sanity-run-blueprints-stacks)
|
|
40
40
|
* [`sanity-run functions dev`](#sanity-run-functions-dev)
|
|
41
|
+
* [`sanity-run functions env add NAME KEY VALUE`](#sanity-run-functions-env-add-name-key-value)
|
|
42
|
+
* [`sanity-run functions env remove NAME KEY`](#sanity-run-functions-env-remove-name-key)
|
|
41
43
|
* [`sanity-run functions invoke NAME`](#sanity-run-functions-invoke-name)
|
|
42
44
|
* [`sanity-run functions logs NAME`](#sanity-run-functions-logs-name)
|
|
43
45
|
* [`sanity-run functions test NAME`](#sanity-run-functions-test-name)
|
|
@@ -61,7 +63,7 @@ EXAMPLES
|
|
|
61
63
|
$ sanity-run blueprints add function
|
|
62
64
|
```
|
|
63
65
|
|
|
64
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
66
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/blueprints/add.ts)_
|
|
65
67
|
|
|
66
68
|
## `sanity-run blueprints config`
|
|
67
69
|
|
|
@@ -83,7 +85,7 @@ EXAMPLES
|
|
|
83
85
|
$ sanity-run blueprints config --edit
|
|
84
86
|
```
|
|
85
87
|
|
|
86
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
88
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/blueprints/config.ts)_
|
|
87
89
|
|
|
88
90
|
## `sanity-run blueprints deploy`
|
|
89
91
|
|
|
@@ -100,7 +102,7 @@ EXAMPLES
|
|
|
100
102
|
$ sanity-run blueprints deploy
|
|
101
103
|
```
|
|
102
104
|
|
|
103
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
105
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/blueprints/deploy.ts)_
|
|
104
106
|
|
|
105
107
|
## `sanity-run blueprints info`
|
|
106
108
|
|
|
@@ -122,7 +124,7 @@ EXAMPLES
|
|
|
122
124
|
$ sanity-run blueprints info --id abc123
|
|
123
125
|
```
|
|
124
126
|
|
|
125
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
127
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/blueprints/info.ts)_
|
|
126
128
|
|
|
127
129
|
## `sanity-run blueprints init`
|
|
128
130
|
|
|
@@ -139,7 +141,7 @@ EXAMPLES
|
|
|
139
141
|
$ sanity-run blueprints init
|
|
140
142
|
```
|
|
141
143
|
|
|
142
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
144
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/blueprints/init.ts)_
|
|
143
145
|
|
|
144
146
|
## `sanity-run blueprints logs`
|
|
145
147
|
|
|
@@ -161,7 +163,7 @@ EXAMPLES
|
|
|
161
163
|
$ sanity-run blueprints logs --watch
|
|
162
164
|
```
|
|
163
165
|
|
|
164
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
166
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/blueprints/logs.ts)_
|
|
165
167
|
|
|
166
168
|
## `sanity-run blueprints plan`
|
|
167
169
|
|
|
@@ -178,7 +180,7 @@ EXAMPLES
|
|
|
178
180
|
$ sanity-run blueprints plan
|
|
179
181
|
```
|
|
180
182
|
|
|
181
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
183
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/blueprints/plan.ts)_
|
|
182
184
|
|
|
183
185
|
## `sanity-run blueprints stacks`
|
|
184
186
|
|
|
@@ -195,7 +197,7 @@ EXAMPLES
|
|
|
195
197
|
$ sanity-run blueprints stacks
|
|
196
198
|
```
|
|
197
199
|
|
|
198
|
-
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
200
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/blueprints/stacks.ts)_
|
|
199
201
|
|
|
200
202
|
## `sanity-run functions dev`
|
|
201
203
|
|
|
@@ -215,7 +217,50 @@ EXAMPLES
|
|
|
215
217
|
$ sanity-run functions dev --port 8974
|
|
216
218
|
```
|
|
217
219
|
|
|
218
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
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
|
+
|
|
222
|
+
## `sanity-run functions env add NAME KEY VALUE`
|
|
223
|
+
|
|
224
|
+
Add or set the value of an environment variable for a Sanity function
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
USAGE
|
|
228
|
+
$ sanity-run functions env add NAME KEY VALUE
|
|
229
|
+
|
|
230
|
+
ARGUMENTS
|
|
231
|
+
NAME The name of the Sanity Function
|
|
232
|
+
KEY The name of the environment variable
|
|
233
|
+
VALUE The value of the environment variable
|
|
234
|
+
|
|
235
|
+
DESCRIPTION
|
|
236
|
+
Add or set the value of an environment variable for a Sanity function
|
|
237
|
+
|
|
238
|
+
EXAMPLES
|
|
239
|
+
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
240
|
+
```
|
|
241
|
+
|
|
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
|
+
|
|
244
|
+
## `sanity-run functions env remove NAME KEY`
|
|
245
|
+
|
|
246
|
+
Remove an environment variable for a Sanity function
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
USAGE
|
|
250
|
+
$ sanity-run functions env remove NAME KEY
|
|
251
|
+
|
|
252
|
+
ARGUMENTS
|
|
253
|
+
NAME The name of the Sanity Function
|
|
254
|
+
KEY The name of the environment variable
|
|
255
|
+
|
|
256
|
+
DESCRIPTION
|
|
257
|
+
Remove an environment variable for a Sanity function
|
|
258
|
+
|
|
259
|
+
EXAMPLES
|
|
260
|
+
$ sanity-run functions env remove MyFunction API_URL
|
|
261
|
+
```
|
|
262
|
+
|
|
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)_
|
|
219
264
|
|
|
220
265
|
## `sanity-run functions invoke NAME`
|
|
221
266
|
|
|
@@ -241,7 +286,7 @@ EXAMPLES
|
|
|
241
286
|
$ sanity-run functions invoke <ID> --file 'payload.json'
|
|
242
287
|
```
|
|
243
288
|
|
|
244
|
-
_See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
289
|
+
_See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/functions/invoke.ts)_
|
|
245
290
|
|
|
246
291
|
## `sanity-run functions logs NAME`
|
|
247
292
|
|
|
@@ -261,7 +306,7 @@ EXAMPLES
|
|
|
261
306
|
$ sanity-run functions logs <ID>
|
|
262
307
|
```
|
|
263
308
|
|
|
264
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
309
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/functions/logs.ts)_
|
|
265
310
|
|
|
266
311
|
## `sanity-run functions test NAME`
|
|
267
312
|
|
|
@@ -290,7 +335,7 @@ EXAMPLES
|
|
|
290
335
|
$ sanity-run functions test echo-fn --data '{ "id": 1 }' --timeout 60
|
|
291
336
|
```
|
|
292
337
|
|
|
293
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
338
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v2.1.1/src/commands/functions/test.ts)_
|
|
294
339
|
|
|
295
340
|
## `sanity-run help [COMMAND]`
|
|
296
341
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import config from '../../../config.js';
|
|
2
|
+
import getHeaders from '../../../utils/get-headers.js';
|
|
3
|
+
const { functions } = config.server;
|
|
4
|
+
export async function remove(id, key, auth) {
|
|
5
|
+
const response = await fetch(`${functions}vX/functions/${id}/envvars/${key}`, {
|
|
6
|
+
headers: getHeaders(auth),
|
|
7
|
+
method: 'DELETE',
|
|
8
|
+
});
|
|
9
|
+
const json = response.ok ? undefined : await response.json();
|
|
10
|
+
return {
|
|
11
|
+
ok: response.ok,
|
|
12
|
+
error: response.ok ? null : json?.error?.message,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import config from '../../../config.js';
|
|
2
|
+
import getHeaders from '../../../utils/get-headers.js';
|
|
3
|
+
const { functions } = config.server;
|
|
4
|
+
export async function update(id, key, value, auth) {
|
|
5
|
+
const response = await fetch(`${functions}vX/functions/${id}/envvars/${key}`, {
|
|
6
|
+
body: JSON.stringify({ value }),
|
|
7
|
+
headers: getHeaders(auth),
|
|
8
|
+
method: 'PUT',
|
|
9
|
+
});
|
|
10
|
+
const json = response.ok ? undefined : await response.json();
|
|
11
|
+
return {
|
|
12
|
+
ok: response.ok,
|
|
13
|
+
error: response.ok ? null : json?.error?.message,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -4,6 +4,10 @@ import * as logs from './logs.js';
|
|
|
4
4
|
import * as test from './test.js';
|
|
5
5
|
export declare const functionsActions: {
|
|
6
6
|
dev: typeof dev;
|
|
7
|
+
env: {
|
|
8
|
+
remove: typeof import("./env/remove.js");
|
|
9
|
+
update: typeof import("./env/update.js");
|
|
10
|
+
};
|
|
7
11
|
invoke: typeof invoke;
|
|
8
12
|
logs: typeof logs;
|
|
9
13
|
test: typeof test;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as dev from './dev.js';
|
|
2
|
+
import * as env from './env/index.js';
|
|
2
3
|
import * as invoke from './invoke.js';
|
|
3
4
|
import * as logs from './logs.js';
|
|
4
5
|
import * as test from './test.js';
|
|
5
6
|
export const functionsActions = {
|
|
6
7
|
dev,
|
|
8
|
+
env: env.envActions,
|
|
7
9
|
invoke,
|
|
8
10
|
logs,
|
|
9
11
|
test,
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Add extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
|
+
key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
+
value: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
static description: string;
|
|
9
|
+
static examples: string[];
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Args, Command } from '@oclif/core';
|
|
2
|
+
import Spinner from 'yocto-spinner';
|
|
3
|
+
import { readBlueprintOnDisk } from '../../../actions/blueprints/blueprint.js';
|
|
4
|
+
import { update } from '../../../actions/functions/env/update.js';
|
|
5
|
+
import config from '../../../config.js';
|
|
6
|
+
import { red } from '../../../utils/display/colors.js';
|
|
7
|
+
import { findFunctionByName } from '../../../utils/find-function.js';
|
|
8
|
+
export default class Add extends Command {
|
|
9
|
+
static args = {
|
|
10
|
+
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
11
|
+
key: Args.string({ description: 'The name of the environment variable', required: true }),
|
|
12
|
+
value: Args.string({ description: 'The value of the environment variable', required: true }),
|
|
13
|
+
};
|
|
14
|
+
static description = 'Add or set the value of an environment variable for a Sanity function';
|
|
15
|
+
static examples = [
|
|
16
|
+
'<%= config.bin %> <%= command.id %> MyFunction API_URL https://api.example.com/',
|
|
17
|
+
];
|
|
18
|
+
async run() {
|
|
19
|
+
const { args } = await this.parse(Add);
|
|
20
|
+
const spinner = Spinner({
|
|
21
|
+
text: `Updating "${args.key}" environment variable in "${args.name}"`,
|
|
22
|
+
}).start();
|
|
23
|
+
const { deployedStack } = await readBlueprintOnDisk({ getStack: true });
|
|
24
|
+
if (!deployedStack)
|
|
25
|
+
this.error('Stack not found'); // returns
|
|
26
|
+
const { projectId } = deployedStack;
|
|
27
|
+
const { externalId } = findFunctionByName(deployedStack, args.name);
|
|
28
|
+
const result = await update(externalId, args.key, args.value, {
|
|
29
|
+
token: config.token,
|
|
30
|
+
projectId,
|
|
31
|
+
});
|
|
32
|
+
if (result.ok) {
|
|
33
|
+
spinner.success(`Update of ${args.key} succeeded`);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
spinner.error(`${red('Failed')} to update ${args.key}`);
|
|
37
|
+
this.log(`Error: ${result.error || 'Unknown error'}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Remove extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
|
+
key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
+
};
|
|
7
|
+
static description: string;
|
|
8
|
+
static examples: string[];
|
|
9
|
+
run(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Args, Command } from '@oclif/core';
|
|
2
|
+
import Spinner from 'yocto-spinner';
|
|
3
|
+
import { readBlueprintOnDisk } from '../../../actions/blueprints/blueprint.js';
|
|
4
|
+
import { remove } from '../../../actions/functions/env/remove.js';
|
|
5
|
+
import config from '../../../config.js';
|
|
6
|
+
import { red } from '../../../utils/display/colors.js';
|
|
7
|
+
import { findFunctionByName } from '../../../utils/find-function.js';
|
|
8
|
+
export default class Remove extends Command {
|
|
9
|
+
static args = {
|
|
10
|
+
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
11
|
+
key: Args.string({ description: 'The name of the environment variable', required: true }),
|
|
12
|
+
};
|
|
13
|
+
static description = 'Remove an environment variable for a Sanity function';
|
|
14
|
+
static examples = ['<%= config.bin %> <%= command.id %> MyFunction API_URL'];
|
|
15
|
+
async run() {
|
|
16
|
+
const { args } = await this.parse(Remove);
|
|
17
|
+
const spinner = Spinner({
|
|
18
|
+
text: `Removing "${args.key}" environment variable in "${args.name}"`,
|
|
19
|
+
}).start();
|
|
20
|
+
const { deployedStack } = await readBlueprintOnDisk({ getStack: true });
|
|
21
|
+
if (!deployedStack)
|
|
22
|
+
this.error('Stack not found'); // returns
|
|
23
|
+
const { projectId } = deployedStack;
|
|
24
|
+
const { externalId } = findFunctionByName(deployedStack, args.name);
|
|
25
|
+
const result = await remove(externalId, args.key, {
|
|
26
|
+
token: config.token,
|
|
27
|
+
projectId,
|
|
28
|
+
});
|
|
29
|
+
if (result.ok) {
|
|
30
|
+
spinner.success(`Removal of ${args.key} succeeded`);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
spinner.error(`${red('Failed')} to remove ${args.key}`);
|
|
34
|
+
this.log(`Error: ${result.error || 'Unknown error'}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -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
|
@@ -402,7 +402,84 @@
|
|
|
402
402
|
"functions",
|
|
403
403
|
"test.js"
|
|
404
404
|
]
|
|
405
|
+
},
|
|
406
|
+
"functions:env:add": {
|
|
407
|
+
"aliases": [],
|
|
408
|
+
"args": {
|
|
409
|
+
"name": {
|
|
410
|
+
"description": "The name of the Sanity Function",
|
|
411
|
+
"name": "name",
|
|
412
|
+
"required": true
|
|
413
|
+
},
|
|
414
|
+
"key": {
|
|
415
|
+
"description": "The name of the environment variable",
|
|
416
|
+
"name": "key",
|
|
417
|
+
"required": true
|
|
418
|
+
},
|
|
419
|
+
"value": {
|
|
420
|
+
"description": "The value of the environment variable",
|
|
421
|
+
"name": "value",
|
|
422
|
+
"required": true
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
"description": "Add or set the value of an environment variable for a Sanity function",
|
|
426
|
+
"examples": [
|
|
427
|
+
"<%= config.bin %> <%= command.id %> MyFunction API_URL https://api.example.com/"
|
|
428
|
+
],
|
|
429
|
+
"flags": {},
|
|
430
|
+
"hasDynamicHelp": false,
|
|
431
|
+
"hiddenAliases": [],
|
|
432
|
+
"id": "functions:env:add",
|
|
433
|
+
"pluginAlias": "@sanity/runtime-cli",
|
|
434
|
+
"pluginName": "@sanity/runtime-cli",
|
|
435
|
+
"pluginType": "core",
|
|
436
|
+
"strict": true,
|
|
437
|
+
"enableJsonFlag": false,
|
|
438
|
+
"isESM": true,
|
|
439
|
+
"relativePath": [
|
|
440
|
+
"dist",
|
|
441
|
+
"commands",
|
|
442
|
+
"functions",
|
|
443
|
+
"env",
|
|
444
|
+
"add.js"
|
|
445
|
+
]
|
|
446
|
+
},
|
|
447
|
+
"functions:env:remove": {
|
|
448
|
+
"aliases": [],
|
|
449
|
+
"args": {
|
|
450
|
+
"name": {
|
|
451
|
+
"description": "The name of the Sanity Function",
|
|
452
|
+
"name": "name",
|
|
453
|
+
"required": true
|
|
454
|
+
},
|
|
455
|
+
"key": {
|
|
456
|
+
"description": "The name of the environment variable",
|
|
457
|
+
"name": "key",
|
|
458
|
+
"required": true
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
"description": "Remove an environment variable for a Sanity function",
|
|
462
|
+
"examples": [
|
|
463
|
+
"<%= config.bin %> <%= command.id %> MyFunction API_URL"
|
|
464
|
+
],
|
|
465
|
+
"flags": {},
|
|
466
|
+
"hasDynamicHelp": false,
|
|
467
|
+
"hiddenAliases": [],
|
|
468
|
+
"id": "functions:env:remove",
|
|
469
|
+
"pluginAlias": "@sanity/runtime-cli",
|
|
470
|
+
"pluginName": "@sanity/runtime-cli",
|
|
471
|
+
"pluginType": "core",
|
|
472
|
+
"strict": true,
|
|
473
|
+
"enableJsonFlag": false,
|
|
474
|
+
"isESM": true,
|
|
475
|
+
"relativePath": [
|
|
476
|
+
"dist",
|
|
477
|
+
"commands",
|
|
478
|
+
"functions",
|
|
479
|
+
"env",
|
|
480
|
+
"remove.js"
|
|
481
|
+
]
|
|
405
482
|
}
|
|
406
483
|
},
|
|
407
|
-
"version": "2.
|
|
484
|
+
"version": "2.1.1"
|
|
408
485
|
}
|