@sanity/cli 3.85.2-media-library.14 → 3.86.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.
@@ -18,7 +18,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
18
18
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
19
19
  mod
20
20
  ));
21
- var fs$1 = require("node:fs"), os = require("node:os"), path$3 = require("node:path"), chalk = require("chalk"), loadEnv = require("./loadEnv.js"), require$$0$5 = require("path"), require$$1$2 = require("module"), require$$0$4 = require("fs"), telemetry = require("@sanity/telemetry"), childProcess = require("node:child_process"), fs = require("node:fs/promises"), util$4 = require("node:util"), require$$0$6 = require("os"), require$$5$1 = require("url"), require$$1$3 = require("get-it"), require$$2$1 = require("get-it/middleware"), require$$0$7 = require("constants"), require$$0$8 = require("stream"), require$$0$9 = require("util"), require$$0$a = require("assert"), require$$0$b = require("events"), require$$6$1 = require("http"), semver = require("semver"), pkgDir = require("pkg-dir"), client$1 = require("@sanity/client"), require$$3$1 = require("crypto"), require$$1$4 = require("child_process"), require$$0$c = require("fs/promises"), require$$0$d = require("buffer"), getCliConfig = require("./getCliConfig.js"), journeyConfig = require("./journeyConfig.js"), Stream = require("node:stream"), promises$1 = require("node:stream/promises"), templateValidator = require("@sanity/template-validator"), require$$2$2 = require("string_decoder"), require$$0$e = require("zlib"), require$$7$1 = require("process"), http = require("node:http"), traverse = require("@babel/traverse"), node_url = require("node:url"), node_events = require("node:events"), node_string_decoder = require("node:string_decoder"), process$2 = require("node:process"), require$$2$3 = require("readline"), require$$0$f = require("tty");
21
+ var fs$1 = require("node:fs"), os = require("node:os"), path$3 = require("node:path"), chalk = require("chalk"), loadEnv = require("./loadEnv.js"), require$$0$5 = require("path"), require$$1$2 = require("module"), require$$0$4 = require("fs"), telemetry = require("@sanity/telemetry"), process$2 = require("node:process"), childProcess = require("node:child_process"), fs = require("node:fs/promises"), util$4 = require("node:util"), require$$0$6 = require("os"), require$$5$1 = require("url"), require$$1$3 = require("get-it"), require$$2$1 = require("get-it/middleware"), require$$0$7 = require("constants"), require$$0$8 = require("stream"), require$$0$9 = require("util"), require$$0$a = require("assert"), require$$0$b = require("events"), require$$6$1 = require("http"), semver = require("semver"), pkgDir = require("pkg-dir"), client$1 = require("@sanity/client"), require$$3$1 = require("crypto"), require$$1$4 = require("child_process"), require$$0$c = require("fs/promises"), require$$0$d = require("buffer"), getCliConfig = require("./getCliConfig.js"), journeyConfig = require("./journeyConfig.js"), Stream = require("node:stream"), promises$1 = require("node:stream/promises"), templateValidator = require("@sanity/template-validator"), require$$2$2 = require("string_decoder"), require$$0$e = require("zlib"), require$$7$1 = require("process"), http = require("node:http"), traverse = require("@babel/traverse"), node_url = require("node:url"), node_events = require("node:events"), node_string_decoder = require("node:string_decoder"), require$$2$3 = require("readline"), require$$0$f = require("tty");
22
22
  function _interopDefaultCompat(e) {
23
23
  return e && typeof e == "object" && "default" in e ? e : { default: e };
24
24
  }
@@ -52,7 +52,7 @@ function _mergeNamespaces(n, m) {
52
52
  });
53
53
  }), Object.freeze(n);
54
54
  }
55
- var fs__namespace = /* @__PURE__ */ _interopNamespaceCompat(fs$1), os__default = /* @__PURE__ */ _interopDefaultCompat(os), path__default = /* @__PURE__ */ _interopDefaultCompat(path$3), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk), require$$0__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$0$5), require$$1__default = /* @__PURE__ */ _interopDefaultCompat(require$$1$2), require$$0__default = /* @__PURE__ */ _interopDefaultCompat(require$$0$4), childProcess__default = /* @__PURE__ */ _interopDefaultCompat(childProcess), fs__default = /* @__PURE__ */ _interopDefaultCompat(fs), util__default = /* @__PURE__ */ _interopDefaultCompat(util$4), require$$0__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$0$6), require$$5__default = /* @__PURE__ */ _interopDefaultCompat(require$$5$1), require$$1__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$1$3), require$$2__default = /* @__PURE__ */ _interopDefaultCompat(require$$2$1), require$$0__default$3 = /* @__PURE__ */ _interopDefaultCompat(require$$0$7), require$$0__default$4 = /* @__PURE__ */ _interopDefaultCompat(require$$0$8), require$$0__default$5 = /* @__PURE__ */ _interopDefaultCompat(require$$0$9), require$$0__default$6 = /* @__PURE__ */ _interopDefaultCompat(require$$0$a), require$$0__default$7 = /* @__PURE__ */ _interopDefaultCompat(require$$0$b), require$$6__default = /* @__PURE__ */ _interopDefaultCompat(require$$6$1), semver__default = /* @__PURE__ */ _interopDefaultCompat(semver), pkgDir__default = /* @__PURE__ */ _interopDefaultCompat(pkgDir), require$$3__default = /* @__PURE__ */ _interopDefaultCompat(require$$3$1), require$$1__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$1$4), require$$0__default$8 = /* @__PURE__ */ _interopDefaultCompat(require$$0$c), require$$0__default$9 = /* @__PURE__ */ _interopDefaultCompat(require$$0$d), Stream__default = /* @__PURE__ */ _interopDefaultCompat(Stream), require$$2__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$2$2), require$$0__default$a = /* @__PURE__ */ _interopDefaultCompat(require$$0$e), require$$7__default = /* @__PURE__ */ _interopDefaultCompat(require$$7$1), http__default = /* @__PURE__ */ _interopDefaultCompat(http), traverse__default = /* @__PURE__ */ _interopDefaultCompat(traverse), process__default = /* @__PURE__ */ _interopDefaultCompat(process$2), require$$2__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$2$3), require$$0__default$b = /* @__PURE__ */ _interopDefaultCompat(require$$0$f), resolveFrom$1 = { exports: {} }, hasRequiredResolveFrom;
55
+ var fs__namespace = /* @__PURE__ */ _interopNamespaceCompat(fs$1), os__default = /* @__PURE__ */ _interopDefaultCompat(os), path__default = /* @__PURE__ */ _interopDefaultCompat(path$3), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk), require$$0__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$0$5), require$$1__default = /* @__PURE__ */ _interopDefaultCompat(require$$1$2), require$$0__default = /* @__PURE__ */ _interopDefaultCompat(require$$0$4), process__default = /* @__PURE__ */ _interopDefaultCompat(process$2), childProcess__default = /* @__PURE__ */ _interopDefaultCompat(childProcess), fs__default = /* @__PURE__ */ _interopDefaultCompat(fs), util__default = /* @__PURE__ */ _interopDefaultCompat(util$4), require$$0__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$0$6), require$$5__default = /* @__PURE__ */ _interopDefaultCompat(require$$5$1), require$$1__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$1$3), require$$2__default = /* @__PURE__ */ _interopDefaultCompat(require$$2$1), require$$0__default$3 = /* @__PURE__ */ _interopDefaultCompat(require$$0$7), require$$0__default$4 = /* @__PURE__ */ _interopDefaultCompat(require$$0$8), require$$0__default$5 = /* @__PURE__ */ _interopDefaultCompat(require$$0$9), require$$0__default$6 = /* @__PURE__ */ _interopDefaultCompat(require$$0$a), require$$0__default$7 = /* @__PURE__ */ _interopDefaultCompat(require$$0$b), require$$6__default = /* @__PURE__ */ _interopDefaultCompat(require$$6$1), semver__default = /* @__PURE__ */ _interopDefaultCompat(semver), pkgDir__default = /* @__PURE__ */ _interopDefaultCompat(pkgDir), require$$3__default = /* @__PURE__ */ _interopDefaultCompat(require$$3$1), require$$1__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$1$4), require$$0__default$8 = /* @__PURE__ */ _interopDefaultCompat(require$$0$c), require$$0__default$9 = /* @__PURE__ */ _interopDefaultCompat(require$$0$d), Stream__default = /* @__PURE__ */ _interopDefaultCompat(Stream), require$$2__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$2$2), require$$0__default$a = /* @__PURE__ */ _interopDefaultCompat(require$$0$e), require$$7__default = /* @__PURE__ */ _interopDefaultCompat(require$$7$1), http__default = /* @__PURE__ */ _interopDefaultCompat(http), traverse__default = /* @__PURE__ */ _interopDefaultCompat(traverse), require$$2__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$2$3), require$$0__default$b = /* @__PURE__ */ _interopDefaultCompat(require$$0$f), resolveFrom$1 = { exports: {} }, hasRequiredResolveFrom;
56
56
  function requireResolveFrom() {
57
57
  if (hasRequiredResolveFrom) return resolveFrom$1.exports;
58
58
  hasRequiredResolveFrom = 1;
@@ -3767,7 +3767,500 @@ function print() { __p += __j.call(arguments, '') }
3767
3767
  }(lodash$1, lodash$1.exports)), lodash$1.exports;
3768
3768
  }
3769
3769
  var lodashExports = requireLodash();
3770
- const purpose$2 = "Transform `sanity/desk` imports to `sanity/structure`", description$3 = `
3770
+ const helpText$l = `
3771
+ Arguments
3772
+ [type] Type of Resource to add (currently only 'function' is supported)
3773
+
3774
+ Examples
3775
+ # Add a Function Resource
3776
+ sanity blueprints add function
3777
+ `, addBlueprintsCommand = {
3778
+ name: "add",
3779
+ group: "blueprints",
3780
+ helpText: helpText$l,
3781
+ signature: "<type>",
3782
+ description: "Add a Resource to a Blueprint",
3783
+ hideFromHelp: !0,
3784
+ async action(args, context) {
3785
+ const { output, prompt: prompt2 } = context, { print } = output, [resourceType] = args.argsWithoutOptions;
3786
+ if (!resourceType) {
3787
+ print("Resource type is required. Available types: function");
3788
+ return;
3789
+ }
3790
+ const { blueprint: blueprintAction, resources: resourcesAction } = await import("@sanity/runtime-cli/actions/blueprints");
3791
+ if (!blueprintAction.findBlueprintFile()) {
3792
+ print("No blueprint file found. Run `sanity blueprints init` first.");
3793
+ return;
3794
+ }
3795
+ if (resourceType === "function") {
3796
+ const functionName = await prompt2.single({
3797
+ type: "input",
3798
+ message: "Enter function name:",
3799
+ validate: (input2) => input2.length > 0 || "Function name is required"
3800
+ }), functionType = await prompt2.single({
3801
+ type: "list",
3802
+ message: "Choose function type:",
3803
+ choices: [
3804
+ { value: "document-publish", name: "Document Publish" },
3805
+ { value: "document-create", name: "Document Create (Available soon)", disabled: !0 },
3806
+ { value: "document-delete", name: "Document Delete (Available soon)", disabled: !0 }
3807
+ ]
3808
+ }), { filePath, resourceAdded, resource } = resourcesAction.createFunctionResource({
3809
+ name: functionName,
3810
+ type: functionType,
3811
+ displayName: functionName
3812
+ });
3813
+ print(`
3814
+ Created function: ${filePath}`), resourceAdded ? print("Function Resource added to Blueprint") : (print(`
3815
+ Add this Function Resource to your Blueprint:`), print(JSON.stringify(resource, null, 2)));
3816
+ return;
3817
+ }
3818
+ print(`Unsupported resource type: ${resourceType}. Available types: function`);
3819
+ }
3820
+ }, blueprintsGroup = {
3821
+ name: "blueprints",
3822
+ signature: "[COMMAND]",
3823
+ isGroupRoot: !0,
3824
+ description: "Deploy and manage Sanity Blueprints and Stacks (IaC)",
3825
+ hideFromHelp: !0
3826
+ }, helpText$k = `
3827
+ Options
3828
+ --edit Edit the configuration
3829
+
3830
+ Examples
3831
+ # View current configuration
3832
+ sanity blueprints config
3833
+
3834
+ # Edit configuration
3835
+ sanity blueprints config --edit
3836
+ `, defaultFlags$6 = {
3837
+ edit: !1
3838
+ }, configBlueprintsCommand = {
3839
+ name: "config",
3840
+ group: "blueprints",
3841
+ helpText: helpText$k,
3842
+ signature: "[--edit]",
3843
+ description: "View or edit local Blueprints configuration",
3844
+ hideFromHelp: !0,
3845
+ async action(args, context) {
3846
+ const { apiClient, output, prompt: prompt2 } = context, { print } = output, flags = { ...defaultFlags$6, ...args.extOptions }, client2 = apiClient({
3847
+ requireUser: !0,
3848
+ requireProject: !1
3849
+ }), { token: token2 } = client2.config(), {
3850
+ blueprint: blueprintAction,
3851
+ projects: projectsAction,
3852
+ stacks: stacksAction
3853
+ } = await import("@sanity/runtime-cli/actions/blueprints"), config2 = blueprintAction.readConfigFile();
3854
+ if (!config2) {
3855
+ print("No configuration found. Run `sanity blueprints init` first.");
3856
+ return;
3857
+ }
3858
+ if (print(`
3859
+ Current configuration:`), print(JSON.stringify(config2, null, 2)), !flags.edit)
3860
+ return;
3861
+ if (!token2) {
3862
+ print("No API token found. Please run `sanity login` first.");
3863
+ return;
3864
+ }
3865
+ const { ok, projects, error: error2 } = await projectsAction.listProjects({ token: token2 });
3866
+ if (!ok) {
3867
+ print(error2);
3868
+ return;
3869
+ }
3870
+ if (!projects || projects.length === 0) {
3871
+ print("No Projects found. Please create a Project in Sanity.io first.");
3872
+ return;
3873
+ }
3874
+ const projectChoices = projects.map(({ displayName, id }) => ({
3875
+ value: id,
3876
+ name: `${displayName} <${id}>`
3877
+ })), projectId = await prompt2.single({
3878
+ type: "list",
3879
+ message: "Select your Sanity Project:",
3880
+ choices: projectChoices,
3881
+ default: config2.projectId
3882
+ }), auth = { token: token2, projectId }, { ok: stacksOk, stacks, error: stacksError } = await stacksAction.listStacks(auth);
3883
+ if (!stacksOk) {
3884
+ print(stacksError);
3885
+ return;
3886
+ }
3887
+ let stackId;
3888
+ if (stacks && stacks.length > 0) {
3889
+ const stackChoices = stacks.map(({ name, id }) => ({
3890
+ value: id,
3891
+ name: `${name} <${id}>`
3892
+ }));
3893
+ stackId = await prompt2.single({
3894
+ type: "list",
3895
+ message: "Select a Stack:",
3896
+ choices: stackChoices,
3897
+ default: config2.stackId
3898
+ });
3899
+ }
3900
+ blueprintAction.writeConfigFile({ projectId, stackId }), print(`
3901
+ Configuration updated successfully.`);
3902
+ }
3903
+ }, helpText$j = `
3904
+ Examples
3905
+ # Deploy the current blueprint
3906
+ sanity blueprints deploy
3907
+ `, deployBlueprintsCommand = {
3908
+ name: "deploy",
3909
+ group: "blueprints",
3910
+ helpText: helpText$j,
3911
+ signature: "",
3912
+ description: "Deploy a Blueprint to create or update a Stack",
3913
+ hideFromHelp: !0,
3914
+ /* eslint-disable-next-line complexity, max-statements */
3915
+ async action(args, context) {
3916
+ const { apiClient, output, prompt: prompt2 } = context, { print } = output, client2 = apiClient({
3917
+ requireUser: !0,
3918
+ requireProject: !1
3919
+ }), { token: token2 } = client2.config(), {
3920
+ blueprint: blueprintAction,
3921
+ stacks: stacksAction,
3922
+ assets: assetsAction
3923
+ } = await import("@sanity/runtime-cli/actions/blueprints"), { display } = await import("@sanity/runtime-cli/utils");
3924
+ if (!token2) {
3925
+ print("No API token found. Please run `sanity login` first.");
3926
+ return;
3927
+ }
3928
+ let blueprint = null;
3929
+ try {
3930
+ blueprint = await blueprintAction.readBlueprintOnDisk({ getStack: !0, token: token2 });
3931
+ } catch {
3932
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
3933
+ return;
3934
+ }
3935
+ if (!blueprint) {
3936
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
3937
+ return;
3938
+ }
3939
+ const {
3940
+ errors,
3941
+ projectId: configuredProjectId,
3942
+ stackId,
3943
+ parsedBlueprint,
3944
+ deployedStack
3945
+ } = blueprint;
3946
+ if (errors && errors.length > 0) {
3947
+ print(errors);
3948
+ return;
3949
+ }
3950
+ if (stackId && !deployedStack) {
3951
+ print("Stack specified in config, but deployed Stack not found.");
3952
+ return;
3953
+ }
3954
+ const resources = parsedBlueprint.resources || [];
3955
+ let projectId = configuredProjectId;
3956
+ if (projectId || (print("No Sanity Project context found in Blueprint configuration."), projectId = await prompt2.single({
3957
+ type: "input",
3958
+ message: "Enter Sanity Project ID:"
3959
+ })), !projectId) {
3960
+ print("Sanity Project context is required"), print("To configure this Blueprint, run `sanity blueprints config`");
3961
+ return;
3962
+ }
3963
+ const auth = { token: token2, projectId };
3964
+ let name = deployedStack?.name;
3965
+ if (name || (name = await prompt2.single({
3966
+ type: "input",
3967
+ message: "Enter stack name:",
3968
+ validate: (input2) => input2.length > 0 || "Stack name is required"
3969
+ })), !name) {
3970
+ print("Stack name is required");
3971
+ return;
3972
+ }
3973
+ const validResources = resources?.filter((r) => r.type), functionResources = validResources?.filter((r) => r.type.startsWith("sanity.function."));
3974
+ if (functionResources?.length)
3975
+ for (const resource of functionResources) {
3976
+ print(`Processing ${resource.name}...`);
3977
+ const result = await assetsAction.stashAsset({ resource, auth });
3978
+ if (result.success && result.assetId) {
3979
+ const src2 = resource.src;
3980
+ resource.src = result.assetId;
3981
+ const { yellow } = display.colors;
3982
+ print(`${resource.name} <${yellow(result.assetId)}>`), print(` Source: ${src2}`);
3983
+ } else
3984
+ throw print(` Error: ${result.error}`), new Error(`Failed to process ${resource.name}`);
3985
+ }
3986
+ const stackPayload = {
3987
+ name,
3988
+ projectId,
3989
+ document: { resources: validResources }
3990
+ };
3991
+ print("Deploying stack...");
3992
+ const {
3993
+ ok: deployOk,
3994
+ stack: stack2,
3995
+ error: deployError
3996
+ } = deployedStack ? await stacksAction.updateStack({ stackId: deployedStack.id, stackPayload, auth }) : await stacksAction.createStack({ stackPayload, auth });
3997
+ if (deployOk) {
3998
+ const { green, bold: bold2, yellow } = display.colors;
3999
+ print(
4000
+ `${green("Success!")} Stack "${bold2(stack2.name)}" ${deployedStack ? "updated" : "created"} <${yellow(stack2.id)}>`
4001
+ ), blueprintAction.writeConfigFile({
4002
+ projectId,
4003
+ stackId: stack2.id
4004
+ }), print("\nUse `sanity blueprints info` to check deployment status");
4005
+ } else {
4006
+ const { red } = display.colors;
4007
+ print(`${red("Failed")} to ${deployedStack ? "update" : "create"} stack`), print(`Error: ${deployError || JSON.stringify(stack2, null, 2) || "Unknown error"}`);
4008
+ }
4009
+ }
4010
+ }, helpText$i = `
4011
+ Options
4012
+ --id, -i Stack ID
4013
+
4014
+ Examples
4015
+ # Retrieve information about the current Stack
4016
+ sanity blueprints info
4017
+
4018
+ # Retrieve information about a specific Stack
4019
+ sanity blueprints info --id <stack-id>
4020
+ `, defaultFlags$5 = { id: void 0 }, infoBlueprintsCommand = {
4021
+ name: "info",
4022
+ group: "blueprints",
4023
+ helpText: helpText$i,
4024
+ signature: "",
4025
+ description: "Retrieve information about a Blueprint Stack",
4026
+ hideFromHelp: !0,
4027
+ async action(args, context) {
4028
+ const { apiClient, output } = context, { print } = output, flags = { ...defaultFlags$5, ...args.extOptions }, client2 = apiClient({
4029
+ requireUser: !0,
4030
+ requireProject: !1
4031
+ }), { token: token2 } = client2.config(), { blueprint: blueprintAction, stacks: stacksAction } = await import("@sanity/runtime-cli/actions/blueprints"), { display } = await import("@sanity/runtime-cli/utils");
4032
+ let blueprint = null;
4033
+ try {
4034
+ blueprint = await blueprintAction.readBlueprintOnDisk({ token: token2 });
4035
+ } catch {
4036
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4037
+ return;
4038
+ }
4039
+ if (!blueprint) {
4040
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4041
+ return;
4042
+ }
4043
+ const { errors, deployedStack, projectId } = blueprint;
4044
+ if (errors && errors.length > 0) {
4045
+ print(errors);
4046
+ return;
4047
+ }
4048
+ if (token2 && projectId) {
4049
+ const auth = { token: token2, projectId };
4050
+ let result;
4051
+ if (flags.id) {
4052
+ const { stack: stack2, error: error2, ok } = await stacksAction.getStack({ stackId: flags.id, auth });
4053
+ ok ? result = stack2 : print(error2);
4054
+ } else
4055
+ result = deployedStack;
4056
+ print(result ? display.blueprintsFormatting.formatStackInfo(result) : "No Stack found");
4057
+ } else
4058
+ print("Cannot retrieve information for Blueprint: missing API token or Project ID");
4059
+ }
4060
+ }, helpText$h = `
4061
+ Examples
4062
+ # Create a new Blueprint manifest file
4063
+ sanity blueprints init
4064
+ `, initBlueprintsCommand = {
4065
+ name: "init",
4066
+ group: "blueprints",
4067
+ helpText: helpText$h,
4068
+ signature: "",
4069
+ description: "Initialize a new Blueprint manifest file",
4070
+ hideFromHelp: !0,
4071
+ async action(args, context) {
4072
+ const { apiClient, output, prompt: prompt2 } = context, { print } = output, client2 = apiClient({
4073
+ requireUser: !0,
4074
+ requireProject: !1
4075
+ }), { token: token2 } = client2.config();
4076
+ if (!token2) {
4077
+ print("No API token found. Please run `sanity login` first.");
4078
+ return;
4079
+ }
4080
+ const { blueprint: blueprintAction, projects: projectsAction } = await import("@sanity/runtime-cli/actions/blueprints"), existingBlueprint = blueprintAction.findBlueprintFile();
4081
+ if (existingBlueprint) {
4082
+ print(`A blueprint file already exists: ${existingBlueprint.fileName}`);
4083
+ return;
4084
+ }
4085
+ const blueprintExtension = await prompt2.single({
4086
+ type: "list",
4087
+ message: "Choose a Blueprint manifest file type:",
4088
+ choices: [
4089
+ { value: "json", name: "JSON (Recommended)" },
4090
+ { value: "js", name: "JavaScript (Available soon)", disabled: !0 },
4091
+ { value: "ts", name: "TypeScript (Available soon)", disabled: !0 }
4092
+ ]
4093
+ }), { ok, projects, error: error2 } = await projectsAction.listProjects({ token: token2 });
4094
+ if (!ok) {
4095
+ print(error2);
4096
+ return;
4097
+ }
4098
+ if (!projects || projects.length === 0) {
4099
+ print("No Projects found. Please create a Project in Sanity.io first.");
4100
+ return;
4101
+ }
4102
+ const projectChoices = projects.map(({ displayName, id }) => ({
4103
+ value: id,
4104
+ name: `${displayName} <${id}>`
4105
+ })), projectId = await prompt2.single({
4106
+ type: "list",
4107
+ message: "Select your Sanity Project:",
4108
+ choices: projectChoices
4109
+ }), fileName = `blueprint.${blueprintExtension}`, filePath = path$3.join(process$2.cwd(), fileName);
4110
+ blueprintAction.writeBlueprintToDisk({
4111
+ path: filePath,
4112
+ fileType: blueprintExtension
4113
+ }), blueprintAction.writeConfigFile({ projectId }), print(`Created new blueprint: ./${fileName}`), blueprintExtension === "ts" && print(`
4114
+ Note: TypeScript support requires "tsx" to be installed. Run: npm install -D tsx`);
4115
+ }
4116
+ }, helpText$g = `
4117
+
4118
+ Examples
4119
+ # Show logs for the current Stack
4120
+ sanity blueprints logs
4121
+
4122
+ `, logsBlueprintsCommand = {
4123
+ name: "logs",
4124
+ group: "blueprints",
4125
+ helpText: helpText$g,
4126
+ signature: "[--watch]",
4127
+ description: "Display logs for the current Blueprint Stack",
4128
+ hideFromHelp: !0,
4129
+ async action(args, context) {
4130
+ const { apiClient, output } = context, { print } = output, client2 = apiClient({ requireUser: !0, requireProject: !1 }), { token: token2 } = client2.config();
4131
+ if (!token2) {
4132
+ print("No API token found. Please run `sanity login` first.");
4133
+ return;
4134
+ }
4135
+ const { blueprint: blueprintAction, logs: logsAction } = await import("@sanity/runtime-cli/actions/blueprints"), { display } = await import("@sanity/runtime-cli/utils");
4136
+ let blueprint = null;
4137
+ try {
4138
+ blueprint = await blueprintAction.readBlueprintOnDisk({ token: token2 });
4139
+ } catch {
4140
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4141
+ return;
4142
+ }
4143
+ if (!blueprint) {
4144
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4145
+ return;
4146
+ }
4147
+ const { errors, deployedStack } = blueprint;
4148
+ if (errors && errors.length > 0) {
4149
+ print(errors);
4150
+ return;
4151
+ }
4152
+ if (!deployedStack) {
4153
+ print("Stack not found");
4154
+ return;
4155
+ }
4156
+ const { id: stackId, projectId, name } = deployedStack, auth = { token: token2, projectId };
4157
+ print(`Fetching logs for stack ${display.colors.yellow(`<${stackId}>`)}`);
4158
+ try {
4159
+ const { ok, logs, error: error2 } = await logsAction.getLogs(stackId, auth);
4160
+ if (!ok) {
4161
+ print(`${display.colors.red("Failed")} to retrieve logs`), print(`Error: ${error2 || "Unknown error"}`);
4162
+ return;
4163
+ }
4164
+ if (logs.length === 0) {
4165
+ print(`No logs found for Stack ${stackId}`);
4166
+ return;
4167
+ }
4168
+ print(`${display.blueprintsFormatting.formatTitle("Blueprint", name)} Logs`), print(
4169
+ `Found ${display.colors.bold(logs.length.toString())} log entries for stack ${display.colors.yellow(stackId)}
4170
+ `
4171
+ );
4172
+ const logsByDay = display.logsFormatting.organizeLogsByDay(logs);
4173
+ print(display.logsFormatting.formatLogsByDay(logsByDay));
4174
+ } catch (err) {
4175
+ print("Failed to retrieve logs"), err instanceof Error && print(`Error: ${err.message}`);
4176
+ }
4177
+ }
4178
+ }, helpText$f = `
4179
+ Safe to run at any time. Will not modify any Resources.
4180
+
4181
+ Examples
4182
+ # Show deployment plan
4183
+ sanity blueprints plan
4184
+ `, planBlueprintsCommand = {
4185
+ name: "plan",
4186
+ group: "blueprints",
4187
+ helpText: helpText$f,
4188
+ signature: "",
4189
+ description: "Enumerate Resources to be deployed",
4190
+ hideFromHelp: !0,
4191
+ async action(args, context) {
4192
+ const { apiClient, output } = context, { print } = output, client2 = apiClient({ requireUser: !0, requireProject: !1 }), { token: token2 } = client2.config(), { blueprint: blueprintAction } = await import("@sanity/runtime-cli/actions/blueprints"), { display } = await import("@sanity/runtime-cli/utils");
4193
+ let blueprint = null;
4194
+ try {
4195
+ blueprint = await blueprintAction.readBlueprintOnDisk({ token: token2 });
4196
+ } catch {
4197
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4198
+ return;
4199
+ }
4200
+ if (!blueprint) {
4201
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4202
+ return;
4203
+ }
4204
+ const { errors, projectId, stackId, parsedBlueprint, fileInfo } = blueprint;
4205
+ errors && errors.length > 0 && print(errors);
4206
+ const resources = parsedBlueprint.resources || [];
4207
+ projectId || (print("Unable to determine Project ID."), print("To configure this Blueprint, run `sanity blueprints config`"));
4208
+ const name = stackId || "Unknown";
4209
+ print(`${display.blueprintsFormatting.formatTitle("Blueprint", name)} Plan
4210
+ `), print(`Blueprint document: (${fileInfo.fileName})`), print(""), print(display.blueprintsFormatting.formatResourceTree(resources)), print("\nRun `sanity blueprints deploy` to deploy these changes");
4211
+ }
4212
+ }, helpText$e = `
4213
+ Examples
4214
+ # List all Stacks for the current Project
4215
+ sanity blueprints stacks
4216
+ `, stacksBlueprintsCommand = {
4217
+ name: "stacks",
4218
+ group: "blueprints",
4219
+ helpText: helpText$e,
4220
+ signature: "",
4221
+ description: "List all Blueprint Stacks for the current Project",
4222
+ hideFromHelp: !0,
4223
+ async action(args, context) {
4224
+ const { apiClient, output } = context, { print } = output, client2 = apiClient({ requireUser: !0, requireProject: !1 }), { token: token2 } = client2.config();
4225
+ if (!token2) {
4226
+ print("No API token found. Please run `sanity login` first.");
4227
+ return;
4228
+ }
4229
+ const { blueprint: blueprintAction, stacks: stacksAction } = await import("@sanity/runtime-cli/actions/blueprints"), { display } = await import("@sanity/runtime-cli/utils");
4230
+ let blueprint = null;
4231
+ try {
4232
+ blueprint = await blueprintAction.readBlueprintOnDisk({ token: token2 });
4233
+ } catch {
4234
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4235
+ return;
4236
+ }
4237
+ if (!blueprint) {
4238
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4239
+ return;
4240
+ }
4241
+ const { errors, projectId, stackId } = blueprint;
4242
+ if (errors && errors.length > 0) {
4243
+ print(errors);
4244
+ return;
4245
+ }
4246
+ if (!projectId) {
4247
+ print("Blueprint is not configured for a Project. Run `sanity blueprints config`");
4248
+ return;
4249
+ }
4250
+ const auth = { token: token2, projectId }, { ok, stacks, error: error2 } = await stacksAction.listStacks(auth);
4251
+ if (!ok) {
4252
+ print(error2 || "Failed to list Stacks");
4253
+ return;
4254
+ }
4255
+ if (!stacks || stacks.length === 0) {
4256
+ print("No Stacks found");
4257
+ return;
4258
+ }
4259
+ const { bold: bold2, yellow } = display.colors;
4260
+ print(`${bold2("Project")} <${yellow(projectId)}> ${bold2("Stacks")}:
4261
+ `), print(display.blueprintsFormatting.formatStacksListing(stacks, stackId));
4262
+ }
4263
+ }, purpose$2 = "Transform `sanity/desk` imports to `sanity/structure`", description$3 = `
3771
4264
  Modifies all code paths that are found to import from 'sanity/desk' to instead import from
3772
4265
  'sanity/structure', and renames any renamed members.
3773
4266
 
@@ -7491,28 +7984,28 @@ Examples
7491
7984
  description: "Start the Sanity Function emulator",
7492
7985
  hideFromHelp: !0,
7493
7986
  async action(args, context) {
7494
- const { output } = context, { print } = output, flags = { ...defaultFlags$4, ...args.extOptions }, { functionsActions } = await import("@sanity/runtime-cli");
7495
- functionsActions.dev.dev(flags.port), print(`Server is running on port ${flags.port}
7987
+ const { output } = context, { print } = output, flags = { ...defaultFlags$4, ...args.extOptions }, { dev: devAction } = await import("@sanity/runtime-cli/actions/functions");
7988
+ devAction.dev(flags.port), print(`Server is running on port ${flags.port}
7496
7989
  `), open(`http://localhost:${flags.port}`);
7497
7990
  }
7498
7991
  }, helpText$b = `
7992
+ Arguments
7993
+ [add] Add or update an environment variable
7994
+ [remove] Remove an environment variable
7995
+
7499
7996
  Options
7500
7997
  --name <name> The name of the function
7501
- --add Add or update an environment variable
7502
- --remove Remove an environment variable
7503
7998
  --key <key> The name of the environment variable
7504
7999
  --value <value> The value of the environment variable
7505
8000
 
7506
8001
  Examples
7507
8002
  # Add or update an environment variable
7508
- sanity functions env --name echo --add --key API_URL --value https://api.example.com/
8003
+ sanity functions env add --name echo --key API_URL --value https://api.example.com/
7509
8004
 
7510
8005
  # Remove an environment variable
7511
- sanity functions env --name echo --remove --key API_URL
8006
+ sanity functions env remove --name echo --key API_URL
7512
8007
  `, defaultFlags$3 = {
7513
8008
  name: "",
7514
- add: !1,
7515
- remove: !1,
7516
8009
  key: "",
7517
8010
  value: ""
7518
8011
  }, envFunctionsCommand = {
@@ -7523,42 +8016,36 @@ Examples
7523
8016
  description: "Add or remove an environment variable for a Sanity function",
7524
8017
  hideFromHelp: !0,
7525
8018
  async action(args, context) {
7526
- const { apiClient, output } = context, { print } = output, flags = { ...defaultFlags$3, ...args.extOptions }, client2 = apiClient({
8019
+ const { apiClient, output } = context, { print } = output, [subCommand] = args.argsWithoutOptions, flags = { ...defaultFlags$3, ...args.extOptions };
8020
+ if (!subCommand || !["add", "remove"].includes(subCommand))
8021
+ throw new Error("You must specify if you wish to add or remove an environment variable");
8022
+ const client2 = apiClient({
7527
8023
  requireUser: !0,
7528
8024
  requireProject: !1
7529
8025
  });
7530
- if (flags.name === "") {
7531
- print("You must provide a function name");
7532
- return;
7533
- }
7534
- const token2 = client2.config().token, { blueprintsActions, functionsActions, utils: utils2 } = await import("@sanity/runtime-cli"), { deployedStack } = await blueprintsActions.blueprint.readBlueprintOnDisk({
8026
+ if (flags.name === "")
8027
+ throw new Error("You must provide a function name via the --name flag");
8028
+ const token2 = client2.config().token, { env } = await import("@sanity/runtime-cli/actions/functions"), { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), { findFunction } = await import("@sanity/runtime-cli/utils"), { deployedStack } = await blueprint.readBlueprintOnDisk({
7535
8029
  getStack: !0,
7536
8030
  token: token2
7537
8031
  });
7538
- if (!deployedStack) {
7539
- print("Stack not found");
7540
- return;
7541
- }
7542
- const projectId = blueprintsActions.blueprint.readConfigFile()?.projectId, { externalId } = utils2.findFunctions.findFunctionByName(
8032
+ if (!deployedStack)
8033
+ throw new Error("Stack not found");
8034
+ const projectId = blueprint.readConfigFile()?.projectId, { externalId } = findFunction.findFunctionByName(
7543
8035
  deployedStack,
7544
8036
  flags.name
7545
8037
  );
7546
8038
  if (token2 && projectId) {
7547
- if (flags.add) {
8039
+ if (subCommand === "add") {
7548
8040
  print(`Updating "${flags.key}" environment variable in "${flags.name}"`);
7549
- const result = await functionsActions.env.update.update(
7550
- externalId,
7551
- flags.key,
7552
- flags.value,
7553
- {
7554
- token: token2,
7555
- projectId
7556
- }
7557
- );
8041
+ const result = await env.update.update(externalId, flags.key, flags.value, {
8042
+ token: token2,
8043
+ projectId
8044
+ });
7558
8045
  result.ok ? print(`Update of ${flags.key} succeeded`) : (print(`Failed to update ${flags.key}`), print(`Error: ${result.error || "Unknown error"}`));
7559
- } else if (flags.remove) {
8046
+ } else if (subCommand === "remove") {
7560
8047
  print(`Removing "${flags.key}" environment variable in "${flags.name}"`);
7561
- const result = await functionsActions.env.remove.remove(externalId, flags.key, {
8048
+ const result = await env.remove.remove(externalId, flags.key, {
7562
8049
  token: token2,
7563
8050
  projectId
7564
8051
  });
@@ -7576,8 +8063,9 @@ Examples
7576
8063
  }, helpText$a = `
7577
8064
  Options
7578
8065
  --name <name> The name of the function to retrieve logs for
7579
- --limit <limit> The number of log entries to retrieve
8066
+ --limit <limit> The number of log entries to retrieve [default 50]
7580
8067
  --json If set return json
8068
+ --utc Use UTC dates in logs
7581
8069
 
7582
8070
  Examples
7583
8071
  # Retrieve logs for Sanity Function abcd1234
@@ -7591,7 +8079,8 @@ Examples
7591
8079
  `, defaultFlags$2 = {
7592
8080
  name: "",
7593
8081
  limit: 50,
7594
- json: !1
8082
+ json: !1,
8083
+ utc: !1
7595
8084
  }, logsFunctionsCommand = {
7596
8085
  name: "logs",
7597
8086
  group: "functions",
@@ -7604,24 +8093,20 @@ Examples
7604
8093
  requireUser: !0,
7605
8094
  requireProject: !1
7606
8095
  });
7607
- if (flags.name === "") {
7608
- print("You must provide a function name");
7609
- return;
7610
- }
7611
- const token2 = client2.config().token, { blueprintsActions, utils: utils2 } = await import("@sanity/runtime-cli"), { deployedStack } = await blueprintsActions.blueprint.readBlueprintOnDisk({
8096
+ if (flags.name === "")
8097
+ throw new Error("You must provide a function name via the --name flag");
8098
+ const token2 = client2.config().token, { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), { findFunction } = await import("@sanity/runtime-cli/utils"), { deployedStack } = await blueprint.readBlueprintOnDisk({
7612
8099
  getStack: !0,
7613
8100
  token: token2
7614
8101
  });
7615
- if (!deployedStack) {
7616
- print("Stack not found");
7617
- return;
7618
- }
7619
- const projectId = blueprintsActions.blueprint.readConfigFile()?.projectId, { externalId } = utils2.findFunctions.findFunctionByName(
8102
+ if (!deployedStack)
8103
+ throw new Error("Stack not found");
8104
+ const projectId = blueprint.readConfigFile()?.projectId, { externalId } = findFunction.findFunctionByName(
7620
8105
  deployedStack,
7621
8106
  flags.name
7622
8107
  );
7623
8108
  if (token2 && projectId) {
7624
- const { functionsActions } = await import("@sanity/runtime-cli"), { ok, error: error2, logs, total } = await functionsActions.logs.logs(
8109
+ const { logs: logsAction } = await import("@sanity/runtime-cli/actions/functions"), { ok, error: error2, logs, total } = await logsAction.logs(
7625
8110
  externalId,
7626
8111
  { limit: flags.limit },
7627
8112
  { token: token2, projectId }
@@ -7643,8 +8128,8 @@ Examples
7643
8128
  print(`Found ${total} log entries for function ${flags.name}`), logs.length < total && print(`Here are the last ${filteredLogs.length} entries`), print(`
7644
8129
  `);
7645
8130
  for (const log of filteredLogs) {
7646
- const { time, level, message } = log, date = new Date(time);
7647
- print(`${date.toLocaleDateString()} ${date.toLocaleTimeString()} ${level} ${message}`);
8131
+ const { time, level, message } = log, date = new Date(time), dateString = flags.utc ? date.toISOString().slice(0, 19).split("T").join(" ") : `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
8132
+ print(`${dateString} ${level} ${message}`);
7648
8133
  }
7649
8134
  }
7650
8135
  } else
@@ -7681,19 +8166,23 @@ Examples
7681
8166
  hideFromHelp: !0,
7682
8167
  async action(args, context) {
7683
8168
  const { output } = context, { print } = output, flags = { ...defaultFlags$1, ...args.extOptions };
7684
- if (flags.name === "") {
7685
- print("You must provide a function name");
7686
- return;
7687
- }
7688
- const { blueprintsActions, functionsActions, utils: utils2 } = await import("@sanity/runtime-cli"), { parsedBlueprint } = await blueprintsActions.blueprint.readBlueprintOnDisk({
8169
+ if (flags.name === "")
8170
+ throw new Error("You must provide a function name via the --name flag");
8171
+ const { test } = await import("@sanity/runtime-cli/actions/functions"), { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), { findFunction } = await import("@sanity/runtime-cli/utils"), { parsedBlueprint } = await blueprint.readBlueprintOnDisk({
7689
8172
  getStack: !1
7690
- }), src2 = utils2.findFunctions.getFunctionSource(parsedBlueprint, flags.name);
7691
- src2 || print(`Error: Function ${flags.name} has no source code`);
7692
- const { json: json2, logs, error: error2 } = await functionsActions.test.testAction(src2, {
7693
- data: flags.data,
7694
- file: flags.file,
7695
- timeout: flags.timeout
7696
- });
8173
+ }), src2 = findFunction.getFunctionSource(parsedBlueprint, flags.name);
8174
+ if (!src2)
8175
+ throw new Error(`Error: Function ${flags.name} has no source code`);
8176
+ const { json: json2, logs, error: error2 } = await test.testAction(
8177
+ src2,
8178
+ {
8179
+ data: flags.data,
8180
+ file: flags.file,
8181
+ timeout: flags.timeout
8182
+ },
8183
+ {}
8184
+ // @TODO: Add context
8185
+ );
7697
8186
  error2 ? print(error2.toString()) : (print("Logs:"), print(logs), print("Response:"), print(JSON.stringify(json2, null, 2)));
7698
8187
  }
7699
8188
  };
@@ -54123,7 +54612,16 @@ const baseCommands = [
54123
54612
  devFunctionsCommand,
54124
54613
  logsFunctionsCommand,
54125
54614
  testFunctionsCommand,
54126
- envFunctionsCommand
54615
+ envFunctionsCommand,
54616
+ blueprintsGroup,
54617
+ infoBlueprintsCommand,
54618
+ stacksBlueprintsCommand,
54619
+ initBlueprintsCommand,
54620
+ deployBlueprintsCommand,
54621
+ logsBlueprintsCommand,
54622
+ addBlueprintsCommand,
54623
+ configBlueprintsCommand,
54624
+ planBlueprintsCommand
54127
54625
  ], copyProperty = (to, from2, property, ignoreNonConfigurable) => {
54128
54626
  if (property === "length" || property === "prototype" || property === "arguments" || property === "caller")
54129
54627
  return;