@sanity/runtime-cli 12.3.0 → 13.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 +190 -76
- package/dist/actions/blueprints/assets.d.ts +3 -1
- package/dist/actions/blueprints/assets.js +15 -5
- package/dist/actions/blueprints/blueprint.d.ts +2 -1
- package/dist/actions/blueprints/blueprint.js +3 -1
- package/dist/actions/blueprints/config.d.ts +5 -2
- package/dist/actions/blueprints/config.js +4 -4
- package/dist/actions/blueprints/logs-streaming.d.ts +4 -2
- package/dist/actions/blueprints/logs-streaming.js +5 -2
- package/dist/actions/blueprints/logs.d.ts +2 -1
- package/dist/actions/blueprints/logs.js +4 -2
- package/dist/actions/blueprints/resources.d.ts +2 -1
- package/dist/actions/blueprints/resources.js +2 -2
- package/dist/actions/blueprints/stacks.d.ts +12 -6
- package/dist/actions/blueprints/stacks.js +18 -11
- package/dist/actions/functions/dev.d.ts +2 -1
- package/dist/actions/functions/dev.js +2 -2
- package/dist/actions/functions/env/list.d.ts +2 -1
- package/dist/actions/functions/env/list.js +4 -2
- package/dist/actions/functions/env/remove.d.ts +2 -1
- package/dist/actions/functions/env/remove.js +4 -2
- package/dist/actions/functions/env/update.d.ts +2 -1
- package/dist/actions/functions/env/update.js +4 -2
- package/dist/actions/functions/logs.d.ts +4 -3
- package/dist/actions/functions/logs.js +10 -6
- package/dist/actions/node.d.ts +2 -1
- package/dist/actions/node.js +2 -2
- package/dist/actions/sanity/examples.d.ts +5 -2
- package/dist/actions/sanity/examples.js +6 -6
- package/dist/actions/sanity/projects.d.ts +7 -3
- package/dist/actions/sanity/projects.js +11 -7
- package/dist/baseCommands.d.ts +47 -7
- package/dist/baseCommands.js +90 -12
- package/dist/commands/blueprints/add.d.ts +3 -2
- package/dist/commands/blueprints/add.js +14 -10
- package/dist/commands/blueprints/config.d.ts +3 -2
- package/dist/commands/blueprints/config.js +12 -6
- package/dist/commands/blueprints/deploy.d.ts +3 -2
- package/dist/commands/blueprints/deploy.js +10 -4
- package/dist/commands/blueprints/destroy.d.ts +3 -2
- package/dist/commands/blueprints/destroy.js +10 -4
- package/dist/commands/blueprints/doctor.d.ts +6 -4
- package/dist/commands/blueprints/doctor.js +17 -14
- package/dist/commands/blueprints/info.d.ts +3 -2
- package/dist/commands/blueprints/info.js +11 -5
- package/dist/commands/blueprints/init.d.ts +3 -2
- package/dist/commands/blueprints/init.js +26 -20
- package/dist/commands/blueprints/logs.d.ts +3 -2
- package/dist/commands/blueprints/logs.js +10 -4
- package/dist/commands/blueprints/plan.d.ts +3 -2
- package/dist/commands/blueprints/plan.js +8 -4
- package/dist/commands/blueprints/stacks.d.ts +3 -2
- package/dist/commands/blueprints/stacks.js +10 -6
- package/dist/commands/functions/add.d.ts +3 -2
- package/dist/commands/functions/add.js +10 -4
- package/dist/commands/functions/dev.d.ts +3 -2
- package/dist/commands/functions/dev.js +16 -5
- package/dist/commands/functions/env/add.d.ts +4 -3
- package/dist/commands/functions/env/add.js +8 -4
- package/dist/commands/functions/env/list.d.ts +4 -3
- package/dist/commands/functions/env/list.js +8 -4
- package/dist/commands/functions/env/remove.d.ts +4 -3
- package/dist/commands/functions/env/remove.js +8 -4
- package/dist/commands/functions/logs.d.ts +5 -4
- package/dist/commands/functions/logs.js +11 -5
- package/dist/commands/functions/test.d.ts +5 -4
- package/dist/commands/functions/test.js +13 -6
- package/dist/cores/blueprints/config.d.ts +2 -5
- package/dist/cores/blueprints/config.js +9 -9
- package/dist/cores/blueprints/deploy.js +14 -17
- package/dist/cores/blueprints/destroy.d.ts +2 -5
- package/dist/cores/blueprints/destroy.js +6 -6
- package/dist/cores/blueprints/doctor.js +32 -29
- package/dist/cores/blueprints/info.js +5 -5
- package/dist/cores/blueprints/init.d.ts +3 -3
- package/dist/cores/blueprints/init.js +15 -8
- package/dist/cores/blueprints/logs.js +6 -7
- package/dist/cores/blueprints/plan.js +1 -0
- package/dist/cores/blueprints/stacks.d.ts +2 -5
- package/dist/cores/blueprints/stacks.js +4 -4
- package/dist/cores/functions/add.js +8 -3
- package/dist/cores/functions/dev.js +2 -2
- package/dist/cores/functions/env/add.js +3 -4
- package/dist/cores/functions/env/list.js +3 -4
- package/dist/cores/functions/env/remove.js +3 -4
- package/dist/cores/functions/index.d.ts +3 -9
- package/dist/cores/functions/logs.d.ts +3 -1
- package/dist/cores/functions/logs.js +19 -11
- package/dist/cores/functions/test.d.ts +3 -1
- package/dist/cores/functions/test.js +18 -10
- package/dist/cores/index.d.ts +4 -7
- package/dist/cores/index.js +3 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/server/app.d.ts +2 -1
- package/dist/server/app.js +4 -4
- package/dist/server/handlers/invoke.d.ts +2 -1
- package/dist/server/handlers/invoke.js +2 -2
- package/dist/server/static/components/app.css +0 -116
- package/dist/server/static/components/clear-button.js +1 -1
- package/dist/server/static/components/console-panel.js +27 -6
- package/dist/server/static/components/fetch-button.js +1 -1
- package/dist/server/static/components/filter-api-version.js +39 -3
- package/dist/server/static/components/filter-document-id.js +39 -3
- package/dist/server/static/components/filter-with-token.js +27 -4
- package/dist/server/static/components/filters.js +127 -62
- package/dist/server/static/components/function-list.js +33 -13
- package/dist/server/static/components/network-spinner.js +6 -4
- package/dist/server/static/components/payload-panel.js +46 -24
- package/dist/server/static/components/response-panel.js +33 -6
- package/dist/server/static/components/rule-panel.js +13 -4
- package/dist/server/static/components/run-panel.js +14 -7
- package/dist/server/static/components/select-dropdown.js +34 -5
- package/dist/server/static/components/shared-styles.js +31 -0
- package/dist/server/static/components/toggle-switch.js +11 -2
- package/dist/utils/display/blueprints-formatting.d.ts +2 -2
- package/dist/utils/display/blueprints-formatting.js +31 -26
- package/dist/utils/display/prompt.d.ts +5 -2
- package/dist/utils/display/prompt.js +5 -4
- package/dist/utils/find-function.d.ts +4 -0
- package/dist/utils/find-function.js +6 -0
- package/dist/utils/functions/fetch-document.d.ts +3 -2
- package/dist/utils/functions/fetch-document.js +7 -6
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.js +61 -0
- package/dist/utils/other/github.d.ts +2 -1
- package/dist/utils/other/github.js +4 -2
- package/dist/utils/other/npmjs.d.ts +2 -1
- package/dist/utils/other/npmjs.js +4 -2
- package/dist/utils/traced-fetch.d.ts +35 -0
- package/dist/utils/traced-fetch.js +238 -0
- package/dist/utils/validated-token.d.ts +3 -2
- package/dist/utils/validated-token.js +6 -4
- package/oclif.manifest.json +455 -75
- package/package.json +14 -6
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import { Args,
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { baseFlags, RuntimeCommand, unhide } from '../../baseCommands.js';
|
|
2
3
|
import { blueprintInitCore } from '../../cores/blueprints/init.js';
|
|
4
|
+
import { Logger } from '../../utils/logger.js';
|
|
3
5
|
import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
|
|
4
|
-
export default class InitCommand extends
|
|
5
|
-
static
|
|
6
|
+
export default class InitCommand extends RuntimeCommand {
|
|
7
|
+
static summary = 'Initialize a local Blueprint and optionally provision a remote Stack deployment';
|
|
8
|
+
static description = `A Blueprint is your local infrastructure-as-code configuration that defines Sanity resources (datasets, functions, etc.). A Stack is the remote deployment target where your Blueprint is applied.
|
|
9
|
+
[NOTE: Currently, accounts are limited to three (3) Stacks per project scope.]
|
|
10
|
+
|
|
11
|
+
This is typically the first command you run in a new project. It creates a local Blueprint manifest file (sanity.blueprint.ts, .js, or .json) and provisions a new remote Stack.
|
|
12
|
+
Additionally, a Blueprint configuration file is created in .sanity/ containing the scope and Stack IDs. This is .gitignored by default.
|
|
13
|
+
|
|
14
|
+
After initialization, use 'blueprints plan' to preview changes, then 'blueprints deploy' to apply them.`;
|
|
6
15
|
static examples = [
|
|
7
16
|
'<%= config.bin %> <%= command.id %>',
|
|
8
17
|
'<%= config.bin %> <%= command.id %> [directory]',
|
|
@@ -12,58 +21,55 @@ export default class InitCommand extends Command {
|
|
|
12
21
|
];
|
|
13
22
|
static args = {
|
|
14
23
|
dir: Args.string({
|
|
15
|
-
description: 'Directory to create the Blueprint in',
|
|
24
|
+
description: 'Directory to create the local Blueprint in',
|
|
16
25
|
}),
|
|
17
26
|
};
|
|
18
27
|
static flags = {
|
|
19
28
|
dir: Flags.string({
|
|
20
|
-
description: 'Directory to create the Blueprint in',
|
|
29
|
+
description: 'Directory to create the local Blueprint in',
|
|
21
30
|
}),
|
|
22
31
|
example: Flags.string({
|
|
23
|
-
description: 'Example to use for the Blueprint',
|
|
32
|
+
description: 'Example to use for the local Blueprint',
|
|
24
33
|
aliases: ['recipe'],
|
|
25
34
|
exclusive: ['blueprint-type', 'stack-id', 'stack-name'], // set automatically
|
|
26
35
|
}),
|
|
27
36
|
'blueprint-type': Flags.string({
|
|
28
|
-
description: 'Blueprint manifest type to use for the Blueprint',
|
|
37
|
+
description: 'Blueprint manifest type to use for the local Blueprint',
|
|
29
38
|
options: ['json', 'js', 'ts'],
|
|
30
39
|
aliases: ['type'],
|
|
31
40
|
}),
|
|
32
41
|
'project-id': Flags.string({
|
|
33
|
-
description: 'Sanity
|
|
42
|
+
description: 'Sanity project ID used to scope local Blueprint and remote Stack',
|
|
34
43
|
aliases: ['project', 'projectId'],
|
|
35
44
|
}),
|
|
36
45
|
'organization-id': Flags.string({
|
|
37
|
-
description: 'Sanity
|
|
46
|
+
description: 'Sanity organization ID used to scope local Blueprint and remote Stack',
|
|
38
47
|
aliases: ['organization', 'organizationId', 'org'],
|
|
39
48
|
}),
|
|
40
49
|
'stack-id': Flags.string({
|
|
41
|
-
description: 'Existing Stack ID to
|
|
50
|
+
description: 'Existing Stack ID used to scope local Blueprint',
|
|
42
51
|
aliases: ['stack', 'stackId'],
|
|
43
52
|
dependsOn: ['project-id'],
|
|
44
53
|
exclusive: ['stack-name'],
|
|
45
54
|
}),
|
|
46
55
|
'stack-name': Flags.string({
|
|
47
|
-
description: 'Name to use for a
|
|
56
|
+
description: 'Name to use for a new Stack provisioned during initialization',
|
|
48
57
|
aliases: ['name'],
|
|
49
58
|
exclusive: ['stack-id'],
|
|
50
59
|
}),
|
|
51
|
-
verbose:
|
|
52
|
-
description: 'Verbose output',
|
|
53
|
-
default: false,
|
|
54
|
-
}),
|
|
60
|
+
verbose: unhide(baseFlags.verbose),
|
|
55
61
|
};
|
|
56
62
|
async run() {
|
|
57
|
-
const
|
|
58
|
-
const result = await validTokenOrErrorMessage();
|
|
63
|
+
const log = Logger(this.log.bind(this), this.flags);
|
|
64
|
+
const result = await validTokenOrErrorMessage(log);
|
|
59
65
|
if (!result.ok)
|
|
60
66
|
this.error(result.error.message);
|
|
61
67
|
const { success, error } = await blueprintInitCore({
|
|
62
68
|
bin: this.config.bin,
|
|
63
|
-
log
|
|
69
|
+
log,
|
|
64
70
|
token: result.value,
|
|
65
|
-
args,
|
|
66
|
-
flags,
|
|
71
|
+
args: this.args,
|
|
72
|
+
flags: this.flags,
|
|
67
73
|
});
|
|
68
74
|
if (!success)
|
|
69
75
|
this.error(error);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class LogsCommand extends
|
|
1
|
+
import { DeployedStackCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class LogsCommand extends DeployedStackCommand<typeof LogsCommand> {
|
|
3
|
+
static summary: string;
|
|
3
4
|
static description: string;
|
|
4
5
|
static examples: string[];
|
|
5
6
|
static flags: {
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
-
import {
|
|
2
|
+
import { DeployedStackCommand } from '../../baseCommands.js';
|
|
3
3
|
import { blueprintLogsCore } from '../../cores/blueprints/logs.js';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { Logger } from '../../utils/logger.js';
|
|
5
|
+
export default class LogsCommand extends DeployedStackCommand {
|
|
6
|
+
static summary = "Display logs for the current Blueprint's Stack deployment";
|
|
7
|
+
static description = `Retrieves Stack deployment logs, useful for debugging and monitoring deployment activity.
|
|
8
|
+
|
|
9
|
+
Use --watch (-w) to stream logs in real-time.
|
|
10
|
+
|
|
11
|
+
If you're not seeing expected logs, verify your Stack is deployed with 'blueprints info'.`;
|
|
6
12
|
static examples = [
|
|
7
13
|
'<%= config.bin %> <%= command.id %>',
|
|
8
14
|
'<%= config.bin %> <%= command.id %> --watch',
|
|
@@ -17,7 +23,7 @@ export default class LogsCommand extends DeployedBlueprintCommand {
|
|
|
17
23
|
async run() {
|
|
18
24
|
const { success, streaming, error } = await blueprintLogsCore({
|
|
19
25
|
bin: this.config.bin,
|
|
20
|
-
log: (
|
|
26
|
+
log: Logger(this.log.bind(this), this.flags),
|
|
21
27
|
auth: this.auth,
|
|
22
28
|
stackId: this.stackId,
|
|
23
29
|
deployedStack: this.deployedStack,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class PlanCommand extends
|
|
1
|
+
import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class PlanCommand extends LocalBlueprintCommand<typeof PlanCommand> {
|
|
3
|
+
static summary: string;
|
|
3
4
|
static description: string;
|
|
4
5
|
static examples: string[];
|
|
5
6
|
run(): Promise<void>;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
2
2
|
import { blueprintPlanCore } from '../../cores/blueprints/plan.js';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { Logger } from '../../utils/logger.js';
|
|
4
|
+
export default class PlanCommand extends LocalBlueprintCommand {
|
|
5
|
+
static summary = 'Enumerate resources to be deployed to the remote Stack - will not modify any resources';
|
|
6
|
+
static description = `Use this command to preview what changes will be applied to your remote Stack before deploying. This is a safe, read-only operation—no resources are created, modified, or deleted.
|
|
7
|
+
|
|
8
|
+
Run 'blueprints plan' after making local changes to your Blueprint manifest to verify the expected diff. When ready, run 'blueprints deploy' to apply changes.`;
|
|
5
9
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
6
10
|
async run() {
|
|
7
11
|
const { success, error } = await blueprintPlanCore({
|
|
8
12
|
bin: this.config.bin,
|
|
9
|
-
log: (
|
|
13
|
+
log: Logger(this.log.bind(this), this.flags),
|
|
10
14
|
token: this.sanityToken,
|
|
11
15
|
blueprint: this.blueprint,
|
|
12
16
|
flags: this.flags,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class StacksCommand extends
|
|
1
|
+
import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class StacksCommand extends LocalBlueprintCommand<typeof StacksCommand> {
|
|
3
|
+
static summary: string;
|
|
3
4
|
static description: string;
|
|
4
5
|
static examples: string[];
|
|
5
6
|
static flags: {
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
-
import {
|
|
2
|
+
import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
3
3
|
import { blueprintStacksCore } from '../../cores/blueprints/stacks.js';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { Logger } from '../../utils/logger.js';
|
|
5
|
+
export default class StacksCommand extends LocalBlueprintCommand {
|
|
6
|
+
static summary = "List all remote Stack deployments (defaults to the current Blueprint's project scope)";
|
|
7
|
+
static description = `Shows all Stacks associated with a project or organization. By default, lists Stacks scoped to the local Blueprint.
|
|
8
|
+
|
|
9
|
+
Use this to discover existing Stacks you can scope a local Blueprint to (using 'blueprints config --edit'), or to audit what's deployed across your project.`;
|
|
6
10
|
static examples = [
|
|
7
11
|
'<%= config.bin %> <%= command.id %>',
|
|
8
12
|
'<%= config.bin %> <%= command.id %> --project-id <projectId>',
|
|
@@ -10,12 +14,12 @@ export default class StacksCommand extends BlueprintCommand {
|
|
|
10
14
|
];
|
|
11
15
|
static flags = {
|
|
12
16
|
'project-id': Flags.string({
|
|
13
|
-
description: 'Project ID to show
|
|
17
|
+
description: 'Project ID to show Stack deployments for',
|
|
14
18
|
aliases: ['projectId', 'project'],
|
|
15
19
|
exclusive: ['organization-id'],
|
|
16
20
|
}),
|
|
17
21
|
'organization-id': Flags.string({
|
|
18
|
-
description: 'Organization ID to show
|
|
22
|
+
description: 'Organization ID to show Stack deployments for',
|
|
19
23
|
aliases: ['organizationId', 'organization', 'org'],
|
|
20
24
|
exclusive: ['project-id'],
|
|
21
25
|
}),
|
|
@@ -23,7 +27,7 @@ export default class StacksCommand extends BlueprintCommand {
|
|
|
23
27
|
async run() {
|
|
24
28
|
const { success, error } = await blueprintStacksCore({
|
|
25
29
|
bin: this.config.bin,
|
|
26
|
-
log: (
|
|
30
|
+
log: Logger(this.log.bind(this), this.flags),
|
|
27
31
|
token: this.sanityToken,
|
|
28
32
|
blueprint: this.blueprint,
|
|
29
33
|
flags: this.flags,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class AddCommand extends
|
|
1
|
+
import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class AddCommand extends LocalBlueprintCommand<typeof AddCommand> {
|
|
3
|
+
static summary: string;
|
|
3
4
|
static description: string;
|
|
4
5
|
static examples: string[];
|
|
5
6
|
static flags: {
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
-
import {
|
|
2
|
+
import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
3
3
|
import { functionAddCore } from '../../cores/functions/index.js';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { Logger } from '../../utils/logger.js';
|
|
5
|
+
export default class AddCommand extends LocalBlueprintCommand {
|
|
6
|
+
static summary = 'Add a Function to your Blueprint';
|
|
7
|
+
static description = `Scaffolds a new Function in the functions/ folder and templates a resource for your Blueprint manifest.
|
|
8
|
+
|
|
9
|
+
Functions are serverless handlers triggered by document events (create, update, delete, publish) or media library events.
|
|
10
|
+
|
|
11
|
+
After adding, use 'functions dev' to test locally, then 'blueprints deploy' to publish.`;
|
|
6
12
|
static examples = [
|
|
7
13
|
'<%= config.bin %> <%= command.id %>',
|
|
8
14
|
'<%= config.bin %> <%= command.id %> --helpers',
|
|
@@ -63,7 +69,7 @@ export default class AddCommand extends BlueprintCommand {
|
|
|
63
69
|
async run() {
|
|
64
70
|
const { success, error } = await functionAddCore({
|
|
65
71
|
bin: this.config.bin,
|
|
66
|
-
log: (
|
|
72
|
+
log: Logger(this.log.bind(this), this.flags),
|
|
67
73
|
blueprint: this.blueprint,
|
|
68
74
|
flags: this.flags,
|
|
69
75
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class DevCommand extends
|
|
1
|
+
import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class DevCommand extends LocalBlueprintCommand<typeof DevCommand> {
|
|
3
|
+
static summary: string;
|
|
3
4
|
static description: string;
|
|
4
5
|
static examples: string[];
|
|
5
6
|
static flags: {
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
-
import {
|
|
2
|
+
import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
3
3
|
import { functionDevCore } from '../../cores/functions/dev.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
static
|
|
4
|
+
import { Logger } from '../../utils/logger.js';
|
|
5
|
+
export default class DevCommand extends LocalBlueprintCommand {
|
|
6
|
+
static summary = 'Start the Sanity Function emulator';
|
|
7
|
+
static description = `Runs a local, web-based development server to test your functions before deploying.
|
|
8
|
+
|
|
9
|
+
Open the emulator in your browser to interactively test your functions with the payload editor.
|
|
10
|
+
|
|
11
|
+
Optionally, set the host and port with the --host and --port flags. Function timeout can be configured with the --timeout flag.
|
|
12
|
+
|
|
13
|
+
To invoke a function with the CLI, use 'functions test'.`;
|
|
14
|
+
static examples = [
|
|
15
|
+
'<%= config.bin %> <%= command.id %> --host 127.0.0.1 --port 8974',
|
|
16
|
+
'<%= config.bin %> <%= command.id %> --timeout 60',
|
|
17
|
+
];
|
|
7
18
|
static flags = {
|
|
8
19
|
host: Flags.string({
|
|
9
20
|
char: 'h',
|
|
@@ -25,7 +36,7 @@ export default class DevCommand extends BlueprintCommand {
|
|
|
25
36
|
const { flags } = await this.parse(DevCommand);
|
|
26
37
|
const { success, error, streaming } = await functionDevCore({
|
|
27
38
|
bin: this.config.bin,
|
|
28
|
-
log: (
|
|
39
|
+
log: Logger(this.log.bind(this), this.flags),
|
|
29
40
|
flags,
|
|
30
41
|
});
|
|
31
42
|
if (!success)
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class EnvAddCommand extends
|
|
1
|
+
import { DeployedStackCommand } from '../../../baseCommands.js';
|
|
2
|
+
export default class EnvAddCommand extends DeployedStackCommand<typeof EnvAddCommand> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
3
5
|
static args: {
|
|
4
6
|
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
7
|
key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
8
|
value: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
7
9
|
};
|
|
8
|
-
static description: string;
|
|
9
10
|
static examples: string[];
|
|
10
11
|
run(): Promise<void>;
|
|
11
12
|
}
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { Args } from '@oclif/core';
|
|
2
|
-
import {
|
|
2
|
+
import { DeployedStackCommand } from '../../../baseCommands.js';
|
|
3
3
|
import { functionEnvAddCore } from '../../../cores/functions/env/add.js';
|
|
4
|
-
|
|
4
|
+
import { Logger } from '../../../utils/logger.js';
|
|
5
|
+
export default class EnvAddCommand extends DeployedStackCommand {
|
|
6
|
+
static summary = 'Add or set an environment variable for a deployed function';
|
|
7
|
+
static description = `Sets an environment variable in a deployed Sanity Function. If the variable already exists, its value is updated.
|
|
8
|
+
|
|
9
|
+
Environment variables are useful for API keys, configuration values, and other secrets that shouldn't be hardcoded. Changes take effect on the next function invocation.`;
|
|
5
10
|
static args = {
|
|
6
11
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
7
12
|
key: Args.string({ description: 'The name of the environment variable', required: true }),
|
|
8
13
|
value: Args.string({ description: 'The value of the environment variable', required: true }),
|
|
9
14
|
};
|
|
10
|
-
static description = 'Add or set the value of an environment variable for a Sanity function';
|
|
11
15
|
static examples = [
|
|
12
16
|
'<%= config.bin %> <%= command.id %> MyFunction API_URL https://api.example.com/',
|
|
13
17
|
];
|
|
14
18
|
async run() {
|
|
15
19
|
const { success, error } = await functionEnvAddCore({
|
|
16
20
|
bin: this.config.bin,
|
|
17
|
-
log: (
|
|
21
|
+
log: Logger(this.log.bind(this), this.flags),
|
|
18
22
|
args: this.args,
|
|
19
23
|
auth: this.auth,
|
|
20
24
|
blueprint: this.blueprint,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class EnvListCommand extends
|
|
1
|
+
import { DeployedStackCommand } from '../../../baseCommands.js';
|
|
2
|
+
export default class EnvListCommand extends DeployedStackCommand<typeof EnvListCommand> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
3
5
|
static args: {
|
|
4
6
|
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
7
|
};
|
|
6
|
-
static description: string;
|
|
7
8
|
static examples: string[];
|
|
8
9
|
run(): Promise<void>;
|
|
9
10
|
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { Args } from '@oclif/core';
|
|
2
|
-
import {
|
|
2
|
+
import { DeployedStackCommand } from '../../../baseCommands.js';
|
|
3
3
|
import { functionEnvListCore } from '../../../cores/functions/env/list.js';
|
|
4
|
-
|
|
4
|
+
import { Logger } from '../../../utils/logger.js';
|
|
5
|
+
export default class EnvListCommand extends DeployedStackCommand {
|
|
6
|
+
static summary = 'List environment variables for a deployed function';
|
|
7
|
+
static description = `Displays all environment variables (keys only) configured in a deployed Sanity Function.
|
|
8
|
+
|
|
9
|
+
Use 'functions env add' to set variables or 'functions env remove' to delete them.`;
|
|
5
10
|
static args = {
|
|
6
11
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
7
12
|
};
|
|
8
|
-
static description = 'List the environment variables for a Sanity function';
|
|
9
13
|
static examples = ['<%= config.bin %> <%= command.id %> MyFunction'];
|
|
10
14
|
async run() {
|
|
11
15
|
const { success, error } = await functionEnvListCore({
|
|
12
16
|
bin: this.config.bin,
|
|
13
|
-
log: (
|
|
17
|
+
log: Logger(this.log.bind(this), this.flags),
|
|
14
18
|
args: this.args,
|
|
15
19
|
auth: this.auth,
|
|
16
20
|
blueprint: this.blueprint,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class EnvRemoveCommand extends
|
|
1
|
+
import { DeployedStackCommand } from '../../../baseCommands.js';
|
|
2
|
+
export default class EnvRemoveCommand extends DeployedStackCommand<typeof EnvRemoveCommand> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
3
5
|
static args: {
|
|
4
6
|
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
7
|
key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
8
|
};
|
|
7
|
-
static description: string;
|
|
8
9
|
static examples: string[];
|
|
9
10
|
run(): Promise<void>;
|
|
10
11
|
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { Args } from '@oclif/core';
|
|
2
|
-
import {
|
|
2
|
+
import { DeployedStackCommand } from '../../../baseCommands.js';
|
|
3
3
|
import { functionEnvRemoveCore } from '../../../cores/functions/env/remove.js';
|
|
4
|
-
|
|
4
|
+
import { Logger } from '../../../utils/logger.js';
|
|
5
|
+
export default class EnvRemoveCommand extends DeployedStackCommand {
|
|
6
|
+
static summary = 'Remove an environment variable from a deployed function';
|
|
7
|
+
static description = `Deletes an environment variable from a deployed Sanity Function. The change takes effect on the next function invocation.
|
|
8
|
+
|
|
9
|
+
Use 'functions env list' to see current variables before removing.`;
|
|
5
10
|
static args = {
|
|
6
11
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
7
12
|
key: Args.string({ description: 'The name of the environment variable', required: true }),
|
|
8
13
|
};
|
|
9
|
-
static description = 'Remove an environment variable for a Sanity function';
|
|
10
14
|
static examples = ['<%= config.bin %> <%= command.id %> MyFunction API_URL'];
|
|
11
15
|
async run() {
|
|
12
16
|
const { success, error } = await functionEnvRemoveCore({
|
|
13
17
|
bin: this.config.bin,
|
|
14
|
-
log: (
|
|
18
|
+
log: Logger(this.log.bind(this), this.flags),
|
|
15
19
|
args: this.args,
|
|
16
20
|
auth: this.auth,
|
|
17
21
|
blueprint: this.blueprint,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class LogsCommand extends
|
|
1
|
+
import { DeployedStackCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class LogsCommand extends DeployedStackCommand<typeof LogsCommand> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
3
5
|
static args: {
|
|
4
|
-
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
+
name: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
7
|
};
|
|
6
|
-
static description: string;
|
|
7
8
|
static examples: string[];
|
|
8
9
|
static flags: {
|
|
9
10
|
limit: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import {
|
|
2
|
+
import { DeployedStackCommand } from '../../baseCommands.js';
|
|
3
3
|
import { functionLogsCore } from '../../cores/functions/logs.js';
|
|
4
|
-
|
|
4
|
+
import { Logger } from '../../utils/logger.js';
|
|
5
|
+
export default class LogsCommand extends DeployedStackCommand {
|
|
6
|
+
static summary = 'Retrieve or delete logs for a Sanity Function';
|
|
7
|
+
static description = `Fetches execution logs from a deployed function, useful for debugging production issues or monitoring activity.
|
|
8
|
+
|
|
9
|
+
Use --watch (-w) to stream logs in real-time. Use --delete to clear all logs for a function (requires confirmation unless --force is specified).`;
|
|
5
10
|
static args = {
|
|
6
|
-
name: Args.string({ description: 'The name of the Sanity Function', required:
|
|
11
|
+
name: Args.string({ description: 'The name of the Sanity Function', required: false }),
|
|
7
12
|
};
|
|
8
|
-
static description = 'Retrieve or delete logs for a Sanity Function';
|
|
9
13
|
static examples = [
|
|
10
14
|
'<%= config.bin %> <%= command.id %> <name>',
|
|
11
15
|
'<%= config.bin %> <%= command.id %> <name> --json',
|
|
@@ -50,7 +54,8 @@ export default class LogsCommand extends DeployedBlueprintCommand {
|
|
|
50
54
|
async run() {
|
|
51
55
|
const { success, error } = await functionLogsCore({
|
|
52
56
|
bin: this.config.bin,
|
|
53
|
-
log: (
|
|
57
|
+
log: Logger(this.log.bind(this), this.flags),
|
|
58
|
+
error: (msg, options) => this.error(msg, options),
|
|
54
59
|
args: this.args,
|
|
55
60
|
flags: this.flags,
|
|
56
61
|
auth: this.auth,
|
|
@@ -60,6 +65,7 @@ export default class LogsCommand extends DeployedBlueprintCommand {
|
|
|
60
65
|
scopeId: this.scopeId,
|
|
61
66
|
token: this.sanityToken,
|
|
62
67
|
stackId: this.stackId,
|
|
68
|
+
helpText: LogsCommand.getHelpText(this.config.bin, 'functions logs'),
|
|
63
69
|
});
|
|
64
70
|
if (!success)
|
|
65
71
|
this.error(error);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class TestCommand extends
|
|
1
|
+
import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class TestCommand extends LocalBlueprintCommand<typeof TestCommand> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
3
5
|
static args: {
|
|
4
|
-
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
+
name: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
7
|
};
|
|
6
|
-
static description: string;
|
|
7
8
|
static examples: string[];
|
|
8
9
|
static flags: {
|
|
9
10
|
data: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import {
|
|
2
|
+
import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
3
3
|
import { functionTestCore } from '../../cores/functions/test.js';
|
|
4
|
-
|
|
4
|
+
import { Logger } from '../../utils/logger.js';
|
|
5
|
+
export default class TestCommand extends LocalBlueprintCommand {
|
|
6
|
+
static summary = 'Invoke a local Sanity Function';
|
|
7
|
+
static description = `Executes a function locally with the provided payload, simulating how it would run when deployed. Use this to test your function logic before deploying.
|
|
8
|
+
|
|
9
|
+
Provide test data via --data (inline JSON), --file (JSON file), or --document-id (fetch from Sanity). For update events, use the before/after flag pairs to simulate document changes.`;
|
|
5
10
|
static args = {
|
|
6
|
-
name: Args.string({ description: 'The name of the Sanity Function', required:
|
|
11
|
+
name: Args.string({ description: 'The name of the Sanity Function', required: false }),
|
|
7
12
|
};
|
|
8
|
-
static description = 'Invoke a local Sanity Function';
|
|
9
13
|
static examples = [
|
|
10
14
|
`<%= config.bin %> <%= command.id %> <name> --data '{ "id": 1 }'`,
|
|
11
15
|
`<%= config.bin %> <%= command.id %> <name> --file 'payload.json'`,
|
|
@@ -151,6 +155,7 @@ export default class TestCommand extends BlueprintCommand {
|
|
|
151
155
|
}),
|
|
152
156
|
};
|
|
153
157
|
async run() {
|
|
158
|
+
const { name } = this.args;
|
|
154
159
|
if (this.flags.event === 'update') {
|
|
155
160
|
const hasDataPair = this.flags['data-before'] && this.flags['data-after'];
|
|
156
161
|
const hasFilePair = this.flags['file-before'] && this.flags['file-after'];
|
|
@@ -164,10 +169,12 @@ export default class TestCommand extends BlueprintCommand {
|
|
|
164
169
|
}
|
|
165
170
|
const { success, error } = await functionTestCore({
|
|
166
171
|
bin: this.config.bin,
|
|
167
|
-
log: (
|
|
168
|
-
|
|
172
|
+
log: Logger(this.log.bind(this), this.flags),
|
|
173
|
+
error: (msg, options) => this.error(msg, options),
|
|
174
|
+
args: { ...this.args, name },
|
|
169
175
|
flags: this.flags,
|
|
170
176
|
blueprint: this.blueprint,
|
|
177
|
+
helpText: TestCommand.getHelpText(this.config.bin, 'functions test'),
|
|
171
178
|
});
|
|
172
179
|
if (!success)
|
|
173
180
|
this.error(error);
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export interface BlueprintConfigOptions extends CoreConfig {
|
|
4
|
-
token: string;
|
|
5
|
-
blueprint: ReadBlueprintResult;
|
|
1
|
+
import type { BlueprintConfig, CoreResult } from '../index.js';
|
|
2
|
+
export interface BlueprintConfigOptions extends BlueprintConfig {
|
|
6
3
|
flags: {
|
|
7
4
|
edit?: boolean;
|
|
8
5
|
'project-id'?: string;
|
|
@@ -4,7 +4,7 @@ import { filePathRelativeToCwd, labeledId, warn } from '../../utils/display/pres
|
|
|
4
4
|
import { promptForProject, promptForStack } from '../../utils/display/prompt.js';
|
|
5
5
|
export async function blueprintConfigCore(options) {
|
|
6
6
|
const { bin = 'sanity', blueprint, log, token, flags } = options;
|
|
7
|
-
const { edit: editConfig = false, 'project-id': flagProjectId, 'organization-id': flagOrganizationId, 'stack-id': flagStackId, verbose:
|
|
7
|
+
const { edit: editConfig = false, 'project-id': flagProjectId, 'organization-id': flagOrganizationId, 'stack-id': flagStackId, verbose: _v = false, } = flags;
|
|
8
8
|
const providedConfigFlag = [flagProjectId, flagStackId, flagOrganizationId].some(Boolean);
|
|
9
9
|
const { stackId: configStackId, scopeType: configScopeType, scopeId: configScopeId, blueprintConfig, fileInfo, } = blueprint;
|
|
10
10
|
const blueprintFilePath = fileInfo.blueprintFilePath;
|
|
@@ -17,7 +17,7 @@ export async function blueprintConfigCore(options) {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
if (blueprintConfig)
|
|
20
|
-
printConfig({ configLabel: 'Current', log, config: blueprintConfig
|
|
20
|
+
printConfig({ configLabel: 'Current', log, config: blueprintConfig });
|
|
21
21
|
// passing new config without --edit flag is not allowed
|
|
22
22
|
if (providedConfigFlag && !editConfig) {
|
|
23
23
|
log('To update the configuration, use the --edit flag.');
|
|
@@ -40,7 +40,7 @@ export async function blueprintConfigCore(options) {
|
|
|
40
40
|
configUpdate.organizationId = flagOrganizationId;
|
|
41
41
|
try {
|
|
42
42
|
const newConfig = patchConfigFile(blueprintFilePath, configUpdate);
|
|
43
|
-
printConfig({ configLabel: 'Updated', log, config: newConfig
|
|
43
|
+
printConfig({ configLabel: 'Updated', log, config: newConfig });
|
|
44
44
|
return { success: true };
|
|
45
45
|
}
|
|
46
46
|
catch {
|
|
@@ -54,6 +54,7 @@ export async function blueprintConfigCore(options) {
|
|
|
54
54
|
const pickedProject = await promptForProject({
|
|
55
55
|
token,
|
|
56
56
|
knownProjectId: configScopeId,
|
|
57
|
+
logger: log,
|
|
57
58
|
});
|
|
58
59
|
updatedProjectId = pickedProject.projectId;
|
|
59
60
|
}
|
|
@@ -61,18 +62,18 @@ export async function blueprintConfigCore(options) {
|
|
|
61
62
|
return { success: false, error: 'Project ID is required.' };
|
|
62
63
|
let updatedStackId = flagStackId;
|
|
63
64
|
if (!updatedStackId) {
|
|
64
|
-
const pickedStack = await promptForStack({ projectId: updatedProjectId, token });
|
|
65
|
+
const pickedStack = await promptForStack({ projectId: updatedProjectId, token, logger: log });
|
|
65
66
|
updatedStackId = pickedStack.stackId;
|
|
66
67
|
}
|
|
67
68
|
if (!updatedStackId)
|
|
68
69
|
return { success: false, error: 'Stack is required.' };
|
|
69
70
|
try {
|
|
70
71
|
// update or create config JSON
|
|
71
|
-
const newConfig =
|
|
72
|
+
const newConfig = writeConfigFile(blueprintFilePath, {
|
|
72
73
|
projectId: updatedProjectId,
|
|
73
74
|
stackId: updatedStackId,
|
|
74
75
|
});
|
|
75
|
-
printConfig({ configLabel: 'Updated', log, config: newConfig
|
|
76
|
+
printConfig({ configLabel: 'Updated', log, config: newConfig });
|
|
76
77
|
return { success: true };
|
|
77
78
|
}
|
|
78
79
|
catch {
|
|
@@ -81,12 +82,11 @@ export async function blueprintConfigCore(options) {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
function printConfig(options) {
|
|
84
|
-
const { configLabel, log, config
|
|
85
|
+
const { configLabel, log, config } = options;
|
|
85
86
|
const { projectId, organizationId, stackId, updatedAt } = config;
|
|
86
87
|
const scopeType = projectId ? 'project' : 'organization';
|
|
87
88
|
const scopeId = projectId ? projectId : organizationId;
|
|
88
|
-
|
|
89
|
-
log(JSON.stringify(config));
|
|
89
|
+
log.verbose(JSON.stringify(config));
|
|
90
90
|
log(`${chalk.bold(`${configLabel} configuration:`)}`);
|
|
91
91
|
log(` Deployment: ${labeledId('stack', stackId)}`);
|
|
92
92
|
log(` Scoped to: ${labeledId(scopeType, scopeId)}`);
|