@sanity/runtime-cli 4.5.0 → 5.0.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 +61 -84
- package/dist/actions/blueprints/blueprint.d.ts +6 -12
- package/dist/actions/blueprints/blueprint.js +55 -45
- package/dist/actions/blueprints/index.d.ts +33 -0
- package/dist/actions/blueprints/index.js +32 -0
- package/dist/actions/blueprints/projects.d.ts +9 -0
- package/dist/actions/blueprints/projects.js +12 -0
- package/dist/actions/blueprints/resources.d.ts +1 -0
- package/dist/actions/blueprints/resources.js +24 -11
- package/dist/actions/blueprints/stacks.d.ts +0 -12
- package/dist/actions/blueprints/stacks.js +1 -30
- package/dist/baseCommands.d.ts +24 -0
- package/dist/baseCommands.js +69 -0
- package/dist/commands/blueprints/add.d.ts +7 -3
- package/dist/commands/blueprints/add.js +51 -14
- package/dist/commands/blueprints/config.d.ts +9 -2
- package/dist/commands/blueprints/config.js +68 -18
- package/dist/commands/blueprints/deploy.d.ts +2 -2
- package/dist/commands/blueprints/deploy.js +18 -33
- package/dist/commands/blueprints/destroy.d.ts +4 -3
- package/dist/commands/blueprints/destroy.js +32 -35
- package/dist/commands/blueprints/info.d.ts +2 -2
- package/dist/commands/blueprints/info.js +16 -36
- package/dist/commands/blueprints/init.d.ts +15 -6
- package/dist/commands/blueprints/init.js +99 -47
- package/dist/commands/blueprints/logs.d.ts +2 -2
- package/dist/commands/blueprints/logs.js +18 -32
- package/dist/commands/blueprints/plan.d.ts +2 -2
- package/dist/commands/blueprints/plan.js +10 -16
- package/dist/commands/blueprints/stacks.d.ts +3 -2
- package/dist/commands/blueprints/stacks.js +10 -29
- package/dist/commands/functions/env/add.d.ts +2 -2
- package/dist/commands/functions/env/add.js +6 -17
- package/dist/commands/functions/env/list.d.ts +2 -2
- package/dist/commands/functions/env/list.js +10 -17
- package/dist/commands/functions/env/remove.d.ts +2 -2
- package/dist/commands/functions/env/remove.js +6 -17
- package/dist/commands/functions/invoke.d.ts +2 -2
- package/dist/commands/functions/invoke.js +7 -14
- package/dist/commands/functions/logs.d.ts +3 -7
- package/dist/commands/functions/logs.js +21 -37
- package/dist/commands/functions/test.d.ts +3 -3
- package/dist/commands/functions/test.js +10 -8
- package/dist/server/app.js +3 -3
- package/dist/server/static/vendor/vendor.bundle.d.ts +2 -2
- package/dist/utils/display/blueprints-formatting.js +2 -2
- package/dist/utils/display/colors.js +2 -0
- package/dist/utils/display/errors.d.ts +4 -0
- package/dist/utils/display/errors.js +27 -0
- package/dist/utils/display/index.d.ts +1 -0
- package/dist/utils/display/index.js +1 -0
- package/dist/utils/types.d.ts +15 -3
- package/dist/utils/types.js +9 -3
- package/oclif.manifest.json +93 -45
- package/package.json +2 -1
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
2
|
import Spinner from 'yocto-spinner';
|
|
3
|
-
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
4
3
|
import { findNewestLogTimestamp, getLogs, getRecentLogs, isNewerLog, streamLogs, } from '../../actions/blueprints/logs.js';
|
|
4
|
+
import { DeployedBlueprintCommand } from '../../baseCommands.js';
|
|
5
5
|
import { formatTitle } from '../../utils/display/blueprints-formatting.js';
|
|
6
6
|
import { bold, niceId, red } from '../../utils/display/colors.js';
|
|
7
7
|
import { formatLogEntry, formatLogsByDay, organizeLogsByDay, } from '../../utils/display/logs-formatting.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
static description = 'Display logs for a Blueprint stack';
|
|
8
|
+
export default class LogsCommand extends DeployedBlueprintCommand {
|
|
9
|
+
static description = 'Display logs for a Blueprint deployment';
|
|
11
10
|
static examples = [
|
|
12
11
|
'<%= config.bin %> <%= command.id %>',
|
|
13
12
|
'<%= config.bin %> <%= command.id %> --watch',
|
|
@@ -21,32 +20,20 @@ export default class Logs extends Command {
|
|
|
21
20
|
}),
|
|
22
21
|
};
|
|
23
22
|
async run() {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
const watchMode = flags.watch;
|
|
23
|
+
const flags = this.flags;
|
|
24
|
+
const spinner = Spinner({
|
|
25
|
+
text: `Fetching recent logs for deployment ${niceId(this.stackId)}`,
|
|
26
|
+
}).start();
|
|
29
27
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.log('Blueprint parse errors:');
|
|
33
|
-
console.dir(errors, { depth: null });
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (!deployedStack)
|
|
37
|
-
this.error('Stack not found'); // returns
|
|
38
|
-
const { id: stackId, projectId, name } = deployedStack;
|
|
39
|
-
const auth = { token, projectId };
|
|
40
|
-
const spinner = Spinner({ text: `Fetching logs for stack ${niceId(stackId)}` }).start();
|
|
41
|
-
if (watchMode) {
|
|
42
|
-
const { ok, logs, error } = await getLogs(stackId, auth);
|
|
28
|
+
if (flags.watch) {
|
|
29
|
+
const { ok, logs, error } = await getLogs(this.stackId, this.auth);
|
|
43
30
|
if (!ok) {
|
|
44
31
|
spinner.error(`${red('Failed')} to retrieve logs`);
|
|
45
32
|
this.log(`Error: ${error || 'Unknown error'}`);
|
|
46
33
|
return;
|
|
47
34
|
}
|
|
48
|
-
spinner.stop().clear();
|
|
49
|
-
this.log(`${formatTitle('Blueprint', name)} ${niceId(stackId)} logs`);
|
|
35
|
+
spinner.stop().clear();
|
|
36
|
+
this.log(`${formatTitle('Blueprint', this.deployedStack.name)} ${niceId(this.stackId)} logs`);
|
|
50
37
|
if (logs.length > 0) {
|
|
51
38
|
this.log('\nMost recent logs:');
|
|
52
39
|
const recentLogs = getRecentLogs(logs);
|
|
@@ -55,7 +42,7 @@ export default class Logs extends Command {
|
|
|
55
42
|
}
|
|
56
43
|
}
|
|
57
44
|
else {
|
|
58
|
-
this.log(`No recent logs found for
|
|
45
|
+
this.log(`No recent logs found for deployment ${niceId(this.stackId)}`);
|
|
59
46
|
}
|
|
60
47
|
const onOpen = () => {
|
|
61
48
|
this.log(`Watching for new logs... ${bold('ctrl+c')} to stop`);
|
|
@@ -67,24 +54,23 @@ export default class Logs extends Command {
|
|
|
67
54
|
newestTimestamp = new Date(log.timestamp).getTime();
|
|
68
55
|
this.log(formatLogEntry(log, true));
|
|
69
56
|
};
|
|
70
|
-
this.
|
|
71
|
-
streamLogs(stackId, auth, renderLog, onOpen, (error) => this.log(`${red('Error:')} ${error}`));
|
|
57
|
+
streamLogs(this.stackId, this.auth, renderLog, onOpen, (error) => this.log(`${red('Error:')} ${error}`));
|
|
72
58
|
return new Promise(() => {
|
|
73
59
|
// hold the line until the user terminates with Ctrl+C
|
|
74
60
|
});
|
|
75
61
|
}
|
|
76
|
-
const { ok, logs, error } = await getLogs(stackId, auth);
|
|
62
|
+
const { ok, logs, error } = await getLogs(this.stackId, this.auth);
|
|
77
63
|
if (!ok) {
|
|
78
64
|
spinner.error(`${red('Failed')} to retrieve logs`);
|
|
79
65
|
this.log(`Error: ${error || 'Unknown error'}`);
|
|
80
66
|
return;
|
|
81
67
|
}
|
|
82
68
|
if (logs.length === 0) {
|
|
83
|
-
spinner.info(`No logs found for
|
|
69
|
+
spinner.info(`No logs found for deployment ${this.stackId}`);
|
|
84
70
|
return;
|
|
85
71
|
}
|
|
86
|
-
spinner.success(`${formatTitle('Blueprint', name)} Logs`);
|
|
87
|
-
this.log(`Found ${bold(logs.length.toString())} log entries for
|
|
72
|
+
spinner.success(`${formatTitle('Blueprint', this.deployedStack.name)} Logs`);
|
|
73
|
+
this.log(`Found ${bold(logs.length.toString())} log entries for deployment ${niceId(this.stackId)}\n`);
|
|
88
74
|
// Organize and format logs by day
|
|
89
75
|
const logsByDay = organizeLogsByDay(logs);
|
|
90
76
|
this.log(formatLogsByDay(logsByDay));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class
|
|
1
|
+
import { BlueprintCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class PlanCommand extends BlueprintCommand<typeof PlanCommand> {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
run(): Promise<void>;
|
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
1
|
+
import { BlueprintCommand } from '../../baseCommands.js';
|
|
3
2
|
import { formatResourceTree, formatTitle } from '../../utils/display/blueprints-formatting.js';
|
|
4
|
-
import {
|
|
5
|
-
export default class
|
|
3
|
+
import { presentBlueprintParserErrors } from '../../utils/display/errors.js';
|
|
4
|
+
export default class PlanCommand extends BlueprintCommand {
|
|
6
5
|
static description = 'Enumerate resources to be deployed - will not modify any resources';
|
|
7
6
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
8
7
|
async run() {
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
this.error(tokenErr.message);
|
|
12
|
-
const { errors, projectId, stackId, parsedBlueprint: { resources }, fileInfo, deployedStack, } = await readBlueprintOnDisk({ getStack: true, token });
|
|
8
|
+
const { parsedBlueprint, fileInfo, errors } = this.blueprint;
|
|
9
|
+
const { resources } = parsedBlueprint;
|
|
13
10
|
if (errors.length > 0) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
console.dir(errors, { depth: null });
|
|
11
|
+
this.log(presentBlueprintParserErrors(errors));
|
|
12
|
+
// continue to show plan
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const name = deployedStack?.name ?? stackId ?? 'Unknown';
|
|
21
|
-
this.log(`${formatTitle('Stack', name)} Plan`);
|
|
14
|
+
// TODO: compare local to existingStack
|
|
15
|
+
this.log(`${formatTitle('Deployment', 'Plan')}`);
|
|
22
16
|
this.log(`(${fileInfo.fileName})\n`);
|
|
23
17
|
this.log(formatResourceTree(resources));
|
|
24
|
-
this.log('\nRun `sanity blueprints deploy` to deploy these changes');
|
|
18
|
+
this.log('\nRun `sanity-run blueprints deploy` to deploy these changes');
|
|
25
19
|
}
|
|
26
20
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class
|
|
1
|
+
import { BlueprintCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class StacksCommand extends BlueprintCommand<typeof StacksCommand> {
|
|
3
|
+
static hidden: boolean;
|
|
3
4
|
static description: string;
|
|
4
5
|
static examples: string[];
|
|
5
6
|
static flags: {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
3
2
|
import { listStacks } from '../../actions/blueprints/stacks.js';
|
|
3
|
+
import { BlueprintCommand } from '../../baseCommands.js';
|
|
4
4
|
import { formatStacksListing } from '../../utils/display/blueprints-formatting.js';
|
|
5
5
|
import { bold, niceId } from '../../utils/display/colors.js';
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export default class StacksCommand extends BlueprintCommand {
|
|
7
|
+
// LAUNCH LIMIT: 1 Stack per Project - hide stacks command
|
|
8
|
+
static hidden = true;
|
|
8
9
|
static description = 'List all Blueprint stacks';
|
|
9
10
|
static examples = [
|
|
10
11
|
'<%= config.bin %> <%= command.id %>',
|
|
@@ -17,34 +18,14 @@ export default class Stacks extends Command {
|
|
|
17
18
|
}),
|
|
18
19
|
};
|
|
19
20
|
async run() {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
this.error(tokenErr.message);
|
|
23
|
-
const { flags } = await this.parse(Stacks);
|
|
24
|
-
let { projectId } = flags;
|
|
25
|
-
let stackId;
|
|
26
|
-
if (!projectId) {
|
|
27
|
-
try {
|
|
28
|
-
const { errors, projectId: projectIdFromBlueprint, stackId: stackIdFromBlueprint, } = await readBlueprintOnDisk();
|
|
29
|
-
if (errors.length > 0) {
|
|
30
|
-
this.log('Blueprint parse errors:');
|
|
31
|
-
console.dir(errors, { depth: null });
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
projectId = projectIdFromBlueprint;
|
|
35
|
-
stackId = stackIdFromBlueprint;
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
// continue to print error
|
|
39
|
-
}
|
|
40
|
-
}
|
|
21
|
+
const flags = this.flags;
|
|
22
|
+
const projectId = flags.projectId || this.blueprint.projectId;
|
|
41
23
|
if (!projectId) {
|
|
42
24
|
this.log('Unable to determine Project ID. Provide one with --projectId');
|
|
43
|
-
this.log('Or create a Blueprint with `sanity blueprints init`');
|
|
25
|
+
this.log('Or create a Blueprint with `sanity-run blueprints init`');
|
|
44
26
|
return;
|
|
45
27
|
}
|
|
46
|
-
const
|
|
47
|
-
const { ok, stacks, error } = await listStacks(auth);
|
|
28
|
+
const { ok, stacks, error } = await listStacks({ token: this.sanityToken, projectId });
|
|
48
29
|
if (!ok)
|
|
49
30
|
this.error(error || 'Failed to list stacks');
|
|
50
31
|
if (!stacks || stacks.length === 0) {
|
|
@@ -52,6 +33,6 @@ export default class Stacks extends Command {
|
|
|
52
33
|
return;
|
|
53
34
|
}
|
|
54
35
|
this.log(`${bold('Project')} ${niceId(projectId)} ${bold('Stacks')}:\n`);
|
|
55
|
-
this.log(formatStacksListing(stacks, stackId));
|
|
36
|
+
this.log(formatStacksListing(stacks, this.blueprint.stackId));
|
|
56
37
|
}
|
|
57
38
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class
|
|
1
|
+
import { DeployedBlueprintCommand } from '../../../baseCommands.js';
|
|
2
|
+
export default class EnvAddCommand extends DeployedBlueprintCommand<typeof EnvAddCommand> {
|
|
3
3
|
static args: {
|
|
4
4
|
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
5
|
key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Args
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
2
|
import Spinner from 'yocto-spinner';
|
|
3
|
-
import { readBlueprintOnDisk } from '../../../actions/blueprints/blueprint.js';
|
|
4
3
|
import { update } from '../../../actions/functions/env/update.js';
|
|
4
|
+
import { DeployedBlueprintCommand } from '../../../baseCommands.js';
|
|
5
5
|
import { red } from '../../../utils/display/colors.js';
|
|
6
6
|
import { findFunctionByName } from '../../../utils/find-function.js';
|
|
7
|
-
|
|
8
|
-
export default class Add extends Command {
|
|
7
|
+
export default class EnvAddCommand extends DeployedBlueprintCommand {
|
|
9
8
|
static args = {
|
|
10
9
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
11
10
|
key: Args.string({ description: 'The name of the environment variable', required: true }),
|
|
@@ -16,22 +15,12 @@ export default class Add extends Command {
|
|
|
16
15
|
'<%= config.bin %> <%= command.id %> MyFunction API_URL https://api.example.com/',
|
|
17
16
|
];
|
|
18
17
|
async run() {
|
|
19
|
-
const
|
|
20
|
-
if (tokenErr)
|
|
21
|
-
this.error(tokenErr.message);
|
|
22
|
-
const { args } = await this.parse(Add);
|
|
18
|
+
const args = this.args;
|
|
23
19
|
const spinner = Spinner({
|
|
24
20
|
text: `Updating "${args.key}" environment variable in "${args.name}"`,
|
|
25
21
|
}).start();
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
this.error('Stack not found'); // returns
|
|
29
|
-
const { projectId } = deployedStack;
|
|
30
|
-
const { externalId } = findFunctionByName(deployedStack, args.name);
|
|
31
|
-
const result = await update(externalId, args.key, args.value, {
|
|
32
|
-
token,
|
|
33
|
-
projectId,
|
|
34
|
-
});
|
|
22
|
+
const { externalId } = findFunctionByName(this.deployedStack, args.name);
|
|
23
|
+
const result = await update(externalId, args.key, args.value, this.auth);
|
|
35
24
|
if (result.ok) {
|
|
36
25
|
spinner.success(`Update of ${args.key} succeeded`);
|
|
37
26
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class
|
|
1
|
+
import { DeployedBlueprintCommand } from '../../../baseCommands.js';
|
|
2
|
+
export default class EnvListCommand extends DeployedBlueprintCommand<typeof EnvListCommand> {
|
|
3
3
|
static args: {
|
|
4
4
|
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
5
|
};
|
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
import { Args
|
|
2
|
-
import
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import Spinner from 'yocto-spinner';
|
|
3
3
|
import { list } from '../../../actions/functions/env/list.js';
|
|
4
|
+
import { DeployedBlueprintCommand } from '../../../baseCommands.js';
|
|
4
5
|
import { findFunctionByName } from '../../../utils/find-function.js';
|
|
5
|
-
|
|
6
|
-
export default class List extends Command {
|
|
6
|
+
export default class EnvListCommand extends DeployedBlueprintCommand {
|
|
7
7
|
static args = {
|
|
8
8
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
9
9
|
};
|
|
10
10
|
static description = 'List the environment variables for a Sanity function';
|
|
11
11
|
static examples = ['<%= config.bin %> <%= command.id %> MyFunction'];
|
|
12
12
|
async run() {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token });
|
|
18
|
-
if (!deployedStack)
|
|
19
|
-
this.error('Stack not found. Is it deployed?'); // returns
|
|
20
|
-
const { projectId } = deployedStack;
|
|
21
|
-
const { externalId } = findFunctionByName(deployedStack, args.name);
|
|
22
|
-
const result = await list(externalId, {
|
|
23
|
-
token,
|
|
24
|
-
projectId,
|
|
25
|
-
});
|
|
13
|
+
const args = this.args;
|
|
14
|
+
const spinner = Spinner({ text: `Listing environment variables for "${args.name}"` }).start();
|
|
15
|
+
const { externalId } = findFunctionByName(this.deployedStack, args.name);
|
|
16
|
+
const result = await list(externalId, this.auth);
|
|
26
17
|
if (!result.ok) {
|
|
18
|
+
spinner.stop().clear();
|
|
27
19
|
this.error(`Error: ${result.error || 'Unknown error'}`);
|
|
28
20
|
}
|
|
21
|
+
spinner.success(`Environment variables for "${args.name}"`);
|
|
29
22
|
for (const key of result.envvars) {
|
|
30
23
|
this.log(key);
|
|
31
24
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class
|
|
1
|
+
import { DeployedBlueprintCommand } from '../../../baseCommands.js';
|
|
2
|
+
export default class EnvRemoveCommand extends DeployedBlueprintCommand<typeof EnvRemoveCommand> {
|
|
3
3
|
static args: {
|
|
4
4
|
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
5
|
key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Args
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
2
|
import Spinner from 'yocto-spinner';
|
|
3
|
-
import { readBlueprintOnDisk } from '../../../actions/blueprints/blueprint.js';
|
|
4
3
|
import { remove } from '../../../actions/functions/env/remove.js';
|
|
4
|
+
import { DeployedBlueprintCommand } from '../../../baseCommands.js';
|
|
5
5
|
import { red } from '../../../utils/display/colors.js';
|
|
6
6
|
import { findFunctionByName } from '../../../utils/find-function.js';
|
|
7
|
-
|
|
8
|
-
export default class Remove extends Command {
|
|
7
|
+
export default class EnvRemoveCommand extends DeployedBlueprintCommand {
|
|
9
8
|
static args = {
|
|
10
9
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
11
10
|
key: Args.string({ description: 'The name of the environment variable', required: true }),
|
|
@@ -13,22 +12,12 @@ export default class Remove extends Command {
|
|
|
13
12
|
static description = 'Remove an environment variable for a Sanity function';
|
|
14
13
|
static examples = ['<%= config.bin %> <%= command.id %> MyFunction API_URL'];
|
|
15
14
|
async run() {
|
|
16
|
-
const
|
|
17
|
-
if (tokenErr)
|
|
18
|
-
this.error(tokenErr.message);
|
|
19
|
-
const { args } = await this.parse(Remove);
|
|
15
|
+
const args = this.args;
|
|
20
16
|
const spinner = Spinner({
|
|
21
17
|
text: `Removing "${args.key}" environment variable in "${args.name}"`,
|
|
22
18
|
}).start();
|
|
23
|
-
const {
|
|
24
|
-
|
|
25
|
-
this.error('Stack not found'); // returns
|
|
26
|
-
const { projectId } = deployedStack;
|
|
27
|
-
const { externalId } = findFunctionByName(deployedStack, args.name);
|
|
28
|
-
const result = await remove(externalId, args.key, {
|
|
29
|
-
token,
|
|
30
|
-
projectId,
|
|
31
|
-
});
|
|
19
|
+
const { externalId } = findFunctionByName(this.deployedStack, args.name);
|
|
20
|
+
const result = await remove(externalId, args.key, this.auth);
|
|
32
21
|
if (result.ok) {
|
|
33
22
|
spinner.success(`Removal of ${args.key} succeeded`);
|
|
34
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class
|
|
1
|
+
import { DeployedBlueprintCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class InvokeCommand extends DeployedBlueprintCommand<typeof InvokeCommand> {
|
|
3
3
|
static args: {
|
|
4
4
|
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
5
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Args,
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
2
|
import Spinner from 'yocto-spinner';
|
|
3
|
-
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
4
3
|
import { invoke } from '../../actions/functions/invoke.js';
|
|
4
|
+
import { DeployedBlueprintCommand } from '../../baseCommands.js';
|
|
5
5
|
import { red } from '../../utils/display/colors.js';
|
|
6
6
|
import { findFunctionByName } from '../../utils/find-function.js';
|
|
7
|
-
|
|
8
|
-
export default class Invoke extends Command {
|
|
7
|
+
export default class InvokeCommand extends DeployedBlueprintCommand {
|
|
9
8
|
static args = {
|
|
10
9
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
11
10
|
};
|
|
@@ -23,17 +22,11 @@ export default class Invoke extends Command {
|
|
|
23
22
|
}),
|
|
24
23
|
};
|
|
25
24
|
async run() {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
this.error(tokenErr.message);
|
|
29
|
-
const { args, flags } = await this.parse(Invoke);
|
|
25
|
+
const args = this.args;
|
|
26
|
+
const flags = this.flags;
|
|
30
27
|
const spinner = Spinner({ text: `Invoking function "${args.name}"` }).start();
|
|
31
|
-
const {
|
|
32
|
-
|
|
33
|
-
this.error('Stack not found'); // returns
|
|
34
|
-
const { projectId } = deployedStack;
|
|
35
|
-
const { externalId } = findFunctionByName(deployedStack, args.name);
|
|
36
|
-
const result = await invoke(externalId, { data: flags.data, file: flags.file }, { token, projectId });
|
|
28
|
+
const { externalId } = findFunctionByName(this.deployedStack, args.name);
|
|
29
|
+
const result = await invoke(externalId, { data: flags.data, file: flags.file }, this.auth);
|
|
37
30
|
if (result.ok) {
|
|
38
31
|
spinner.success(`Invocation of ${args.name} succeeded`);
|
|
39
32
|
if (result.json?.data?.type === 'Buffer') {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeployedBlueprintCommand } from '../../baseCommands.js';
|
|
2
2
|
type RunDeleteOptions = {
|
|
3
3
|
force: boolean;
|
|
4
4
|
};
|
|
@@ -6,7 +6,7 @@ type RunGetOptions = {
|
|
|
6
6
|
limit: number;
|
|
7
7
|
json?: boolean;
|
|
8
8
|
};
|
|
9
|
-
export default class
|
|
9
|
+
export default class LogsCommand extends DeployedBlueprintCommand<typeof LogsCommand> {
|
|
10
10
|
static args: {
|
|
11
11
|
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
12
12
|
};
|
|
@@ -18,13 +18,9 @@ export default class Logs extends Command {
|
|
|
18
18
|
delete: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
19
|
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
externalId: string | undefined;
|
|
22
22
|
run(): Promise<void>;
|
|
23
23
|
runDeleteLogs(name: string, options: RunDeleteOptions): Promise<void>;
|
|
24
24
|
runGetLogs(name: string, options: RunGetOptions): Promise<void>;
|
|
25
|
-
getProjectAndExternalId(name: string): Promise<{
|
|
26
|
-
projectId?: string;
|
|
27
|
-
externalId?: string;
|
|
28
|
-
}>;
|
|
29
25
|
}
|
|
30
26
|
export {};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Args,
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
3
|
import Spinner from 'yocto-spinner';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { deleteLogs as deleteLogsAction, logs as getLogsAction, } from '../../actions/functions/logs.js';
|
|
5
|
+
import { DeployedBlueprintCommand } from '../../baseCommands.js';
|
|
6
6
|
import { formatTitle } from '../../utils/display/blueprints-formatting.js';
|
|
7
7
|
import { blue, bold, green, red, yellow } from '../../utils/display/colors.js';
|
|
8
8
|
import { findFunctionByName } from '../../utils/find-function.js';
|
|
9
|
-
import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
|
|
10
9
|
function logLevel(level) {
|
|
11
10
|
if (level === 'ERROR') {
|
|
12
11
|
return red(level);
|
|
@@ -16,7 +15,7 @@ function logLevel(level) {
|
|
|
16
15
|
}
|
|
17
16
|
return green(level);
|
|
18
17
|
}
|
|
19
|
-
export default class
|
|
18
|
+
export default class LogsCommand extends DeployedBlueprintCommand {
|
|
20
19
|
static args = {
|
|
21
20
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
22
21
|
};
|
|
@@ -52,13 +51,12 @@ export default class Logs extends Command {
|
|
|
52
51
|
required: false,
|
|
53
52
|
}),
|
|
54
53
|
};
|
|
55
|
-
|
|
54
|
+
externalId;
|
|
56
55
|
async run() {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
const { args, flags } = await this.parse(Logs);
|
|
56
|
+
const args = this.args;
|
|
57
|
+
const flags = this.flags;
|
|
58
|
+
const { externalId } = findFunctionByName(this.deployedStack, args.name);
|
|
59
|
+
this.externalId = externalId;
|
|
62
60
|
if (flags.delete === true) {
|
|
63
61
|
await this.runDeleteLogs(args.name, flags);
|
|
64
62
|
}
|
|
@@ -67,6 +65,8 @@ export default class Logs extends Command {
|
|
|
67
65
|
}
|
|
68
66
|
}
|
|
69
67
|
async runDeleteLogs(name, options) {
|
|
68
|
+
if (!this.externalId)
|
|
69
|
+
this.error('Unable to delete logs. Unable to determine function ID.');
|
|
70
70
|
if (!options.force) {
|
|
71
71
|
const { certain } = await inquirer.prompt({
|
|
72
72
|
type: 'confirm',
|
|
@@ -77,14 +77,8 @@ export default class Logs extends Command {
|
|
|
77
77
|
if (!certain)
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
const { projectId, externalId } = await this.getProjectAndExternalId(name);
|
|
81
|
-
if (!projectId || !externalId) {
|
|
82
|
-
this.error('Stack not found');
|
|
83
|
-
}
|
|
84
|
-
if (!this.sanityToken)
|
|
85
|
-
this.error('Unable to delete logs. Missing API token.');
|
|
86
80
|
const spinner = Spinner({ text: `Deleting logs for function ${yellow(name)}` }).start();
|
|
87
|
-
const { ok, error } = await deleteLogsAction(externalId,
|
|
81
|
+
const { ok, error } = await deleteLogsAction(this.externalId, this.auth);
|
|
88
82
|
if (!ok) {
|
|
89
83
|
spinner.error(`${red('Failed')} to retrieve logs`);
|
|
90
84
|
this.log(`Error: ${error || 'Unknown error'}`);
|
|
@@ -93,14 +87,10 @@ export default class Logs extends Command {
|
|
|
93
87
|
spinner.success('Logs deleted');
|
|
94
88
|
}
|
|
95
89
|
async runGetLogs(name, options) {
|
|
90
|
+
if (!this.externalId)
|
|
91
|
+
this.error('Unable to retrieve logs. Unable to determine function ID.');
|
|
96
92
|
const spinner = Spinner({ text: `Finding logs for function "${name}"` }).start();
|
|
97
|
-
const {
|
|
98
|
-
if (!projectId || !externalId) {
|
|
99
|
-
this.error('Stack not found');
|
|
100
|
-
}
|
|
101
|
-
if (!this.sanityToken)
|
|
102
|
-
this.error('Unable to retrieve logs. Missing API token.');
|
|
103
|
-
const { ok, error, logs, total } = await logsAction(externalId, { limit: options.limit }, { token: this.sanityToken, projectId });
|
|
93
|
+
const { ok, error, logs, total } = await getLogsAction(this.externalId, { limit: options.limit }, this.auth);
|
|
104
94
|
if (!ok) {
|
|
105
95
|
spinner.error(`${red('Failed')} to retrieve logs`);
|
|
106
96
|
this.log(`Error: ${error || 'Unknown error'}`);
|
|
@@ -121,22 +111,16 @@ export default class Logs extends Command {
|
|
|
121
111
|
for (const log of filteredLogs) {
|
|
122
112
|
const { time, level, message } = log;
|
|
123
113
|
const date = new Date(time);
|
|
124
|
-
this.log(
|
|
114
|
+
this.log([
|
|
115
|
+
bold(date.toLocaleDateString()),
|
|
116
|
+
bold(blue(date.toLocaleTimeString())),
|
|
117
|
+
logLevel(level),
|
|
118
|
+
message,
|
|
119
|
+
].join(' '));
|
|
125
120
|
}
|
|
126
121
|
}
|
|
127
122
|
else {
|
|
128
123
|
this.log(JSON.stringify(filteredLogs, null, 2));
|
|
129
124
|
}
|
|
130
125
|
}
|
|
131
|
-
async getProjectAndExternalId(name) {
|
|
132
|
-
if (!this.sanityToken)
|
|
133
|
-
this.error('Missing API token.');
|
|
134
|
-
const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token: this.sanityToken });
|
|
135
|
-
if (!deployedStack) {
|
|
136
|
-
return {};
|
|
137
|
-
}
|
|
138
|
-
const { projectId } = deployedStack;
|
|
139
|
-
const { externalId } = findFunctionByName(deployedStack, name);
|
|
140
|
-
return { projectId, externalId };
|
|
141
|
-
}
|
|
142
126
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class
|
|
1
|
+
import { BlueprintCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class TestCommand extends BlueprintCommand<typeof TestCommand> {
|
|
3
3
|
static args: {
|
|
4
4
|
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
5
|
};
|
|
@@ -11,7 +11,7 @@ export default class Test extends Command {
|
|
|
11
11
|
timeout: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
12
|
api: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
13
|
dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
-
project: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
15
|
};
|
|
16
16
|
run(): Promise<void>;
|
|
17
17
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Args,
|
|
2
|
-
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
3
2
|
import { testAction } from '../../actions/functions/test.js';
|
|
3
|
+
import { BlueprintCommand } from '../../baseCommands.js';
|
|
4
4
|
import { findFunctionByName } from '../../utils/find-function.js';
|
|
5
|
-
export default class
|
|
5
|
+
export default class TestCommand extends BlueprintCommand {
|
|
6
6
|
static args = {
|
|
7
7
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
8
8
|
};
|
|
@@ -33,14 +33,16 @@ export default class Test extends Command {
|
|
|
33
33
|
description: 'The Sanity dataset to use',
|
|
34
34
|
required: false,
|
|
35
35
|
}),
|
|
36
|
-
project: Flags.string({
|
|
37
|
-
description: '
|
|
36
|
+
'project-id': Flags.string({
|
|
37
|
+
description: 'Sanity Project ID to use',
|
|
38
|
+
aliases: ['project', 'projectId'],
|
|
38
39
|
required: false,
|
|
39
40
|
}),
|
|
40
41
|
};
|
|
41
42
|
async run() {
|
|
42
|
-
const
|
|
43
|
-
const
|
|
43
|
+
const args = this.args;
|
|
44
|
+
const flags = this.flags;
|
|
45
|
+
const parsedBlueprint = this.blueprint.parsedBlueprint;
|
|
44
46
|
try {
|
|
45
47
|
const resource = findFunctionByName(parsedBlueprint, args.name);
|
|
46
48
|
const { json, logs, error } = await testAction(resource, {
|
|
@@ -51,7 +53,7 @@ export default class Test extends Command {
|
|
|
51
53
|
clientOptions: {
|
|
52
54
|
apiVersion: flags.api,
|
|
53
55
|
dataset: flags.dataset,
|
|
54
|
-
projectId: flags
|
|
56
|
+
projectId: flags['project-id'],
|
|
55
57
|
},
|
|
56
58
|
});
|
|
57
59
|
if (!error) {
|