@sanity/cli-core 2.2.0 → 2.3.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.
@@ -17,7 +17,7 @@ export declare function clearCliTokenCache(): void;
17
17
  /**
18
18
  * @public
19
19
  */
20
- declare interface CliConfig {
20
+ export declare interface CliConfig {
21
21
  /** The project ID and dataset the Sanity CLI should use to run its commands */
22
22
  api?: {
23
23
  dataset?: string;
@@ -157,7 +157,7 @@ declare interface CliConfig {
157
157
  *
158
158
  * @public
159
159
  */
160
- declare interface ConfigStore {
160
+ export declare interface ConfigStore {
161
161
  /** Remove a key from the config file. */
162
162
  delete: (key: string) => void;
163
163
  /** Read a value by key. Returns `undefined` if the key does not exist. */
@@ -632,7 +632,7 @@ export declare function tryFindStudioConfigPath(
632
632
  basePath: string,
633
633
  ): Promise<string | undefined>;
634
634
 
635
- declare interface TypeGenConfig {
635
+ export declare interface TypeGenConfig {
636
636
  formatGeneratedCode: boolean;
637
637
  generates: string;
638
638
  overloadClientMethods: boolean;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/_exports/config.ts"],"sourcesContent":["// Exports related to retrieving CLI, studio, app or workbench configuration or paths.\n\nexport {\n clearCliTokenCache,\n getCliToken,\n getCliUserConfig,\n getUserConfig,\n setCliUserConfig,\n} from '../config/cli/cliUserConfig.js'\nexport {getCliConfig, getCliConfigUncached} from '../config/cli/getCliConfig.js'\nexport {getCliConfigSync} from '../config/cli/getCliConfigSync.js'\nexport {isWorkbenchApp, parseWorkbenchCliConfig} from '../config/cli/workbenchApp.js'\nexport {findProjectRoot} from '../config/findProjectRoot.js'\nexport {findProjectRootSync} from '../config/findProjectRootSync.js'\nexport {getStudioConfig} from '../config/studio/getStudioConfig.js'\nexport {getStudioWorkspaces} from '../config/studio/getStudioWorkspaces.js'\nexport {isStudioConfig} from '../config/studio/isStudioConfig.js'\nexport {findPathForFiles} from '../config/util/findConfigsPaths.js'\nexport {findStudioConfigPath, tryFindStudioConfigPath} from '../config/util/findStudioConfigPath.js'\nexport {getSanityConfigDir, getSanityDataDir} from '../util/getSanityConfigDir.js'\nexport {getSanityEnvVar} from '../util/getSanityEnvVar.js'\nexport {getSanityUrl} from '../util/getSanityUrl.js'\nexport {getWorkspace} from '../util/getWorkspace.js'\n"],"names":["clearCliTokenCache","getCliToken","getCliUserConfig","getUserConfig","setCliUserConfig","getCliConfig","getCliConfigUncached","getCliConfigSync","isWorkbenchApp","parseWorkbenchCliConfig","findProjectRoot","findProjectRootSync","getStudioConfig","getStudioWorkspaces","isStudioConfig","findPathForFiles","findStudioConfigPath","tryFindStudioConfigPath","getSanityConfigDir","getSanityDataDir","getSanityEnvVar","getSanityUrl","getWorkspace"],"mappings":"AAAA,sFAAsF;AAEtF,SACEA,kBAAkB,EAClBC,WAAW,EACXC,gBAAgB,EAChBC,aAAa,EACbC,gBAAgB,QACX,iCAAgC;AACvC,SAAQC,YAAY,EAAEC,oBAAoB,QAAO,gCAA+B;AAChF,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,cAAc,EAAEC,uBAAuB,QAAO,gCAA+B;AACrF,SAAQC,eAAe,QAAO,+BAA8B;AAC5D,SAAQC,mBAAmB,QAAO,mCAAkC;AACpE,SAAQC,eAAe,QAAO,sCAAqC;AACnE,SAAQC,mBAAmB,QAAO,0CAAyC;AAC3E,SAAQC,cAAc,QAAO,qCAAoC;AACjE,SAAQC,gBAAgB,QAAO,qCAAoC;AACnE,SAAQC,oBAAoB,EAAEC,uBAAuB,QAAO,yCAAwC;AACpG,SAAQC,kBAAkB,EAAEC,gBAAgB,QAAO,gCAA+B;AAClF,SAAQC,eAAe,QAAO,6BAA4B;AAC1D,SAAQC,YAAY,QAAO,0BAAyB;AACpD,SAAQC,YAAY,QAAO,0BAAyB"}
1
+ {"version":3,"sources":["../../src/_exports/config.ts"],"sourcesContent":["// Exports related to retrieving CLI, studio, app or workbench configuration or paths.\n\nexport {\n clearCliTokenCache,\n getCliToken,\n getCliUserConfig,\n getUserConfig,\n setCliUserConfig,\n} from '../config/cli/cliUserConfig.js'\nexport {getCliConfig, getCliConfigUncached} from '../config/cli/getCliConfig.js'\nexport {getCliConfigSync} from '../config/cli/getCliConfigSync.js'\nexport {\n type CliConfig,\n type ConfigStore,\n type TypeGenConfig,\n} from '../config/cli/types/cliConfig.js'\nexport {isWorkbenchApp, parseWorkbenchCliConfig} from '../config/cli/workbenchApp.js'\nexport {findProjectRoot} from '../config/findProjectRoot.js'\nexport {findProjectRootSync} from '../config/findProjectRootSync.js'\nexport {getStudioConfig} from '../config/studio/getStudioConfig.js'\nexport {getStudioWorkspaces} from '../config/studio/getStudioWorkspaces.js'\nexport {isStudioConfig} from '../config/studio/isStudioConfig.js'\nexport {findPathForFiles} from '../config/util/findConfigsPaths.js'\nexport {findStudioConfigPath, tryFindStudioConfigPath} from '../config/util/findStudioConfigPath.js'\nexport {getSanityConfigDir, getSanityDataDir} from '../util/getSanityConfigDir.js'\nexport {getSanityEnvVar} from '../util/getSanityEnvVar.js'\nexport {getSanityUrl} from '../util/getSanityUrl.js'\nexport {getWorkspace} from '../util/getWorkspace.js'\n"],"names":["clearCliTokenCache","getCliToken","getCliUserConfig","getUserConfig","setCliUserConfig","getCliConfig","getCliConfigUncached","getCliConfigSync","isWorkbenchApp","parseWorkbenchCliConfig","findProjectRoot","findProjectRootSync","getStudioConfig","getStudioWorkspaces","isStudioConfig","findPathForFiles","findStudioConfigPath","tryFindStudioConfigPath","getSanityConfigDir","getSanityDataDir","getSanityEnvVar","getSanityUrl","getWorkspace"],"mappings":"AAAA,sFAAsF;AAEtF,SACEA,kBAAkB,EAClBC,WAAW,EACXC,gBAAgB,EAChBC,aAAa,EACbC,gBAAgB,QACX,iCAAgC;AACvC,SAAQC,YAAY,EAAEC,oBAAoB,QAAO,gCAA+B;AAChF,SAAQC,gBAAgB,QAAO,oCAAmC;AAMlE,SAAQC,cAAc,EAAEC,uBAAuB,QAAO,gCAA+B;AACrF,SAAQC,eAAe,QAAO,+BAA8B;AAC5D,SAAQC,mBAAmB,QAAO,mCAAkC;AACpE,SAAQC,eAAe,QAAO,sCAAqC;AACnE,SAAQC,mBAAmB,QAAO,0CAAyC;AAC3E,SAAQC,cAAc,QAAO,qCAAoC;AACjE,SAAQC,gBAAgB,QAAO,qCAAoC;AACnE,SAAQC,oBAAoB,EAAEC,uBAAuB,QAAO,yCAAwC;AACpG,SAAQC,kBAAkB,EAAEC,gBAAgB,QAAO,gCAA+B;AAClF,SAAQC,eAAe,QAAO,6BAA4B;AAC1D,SAAQC,YAAY,QAAO,0BAAyB;AACpD,SAAQC,YAAY,QAAO,0BAAyB"}
@@ -1,5 +1,14 @@
1
1
  import { CLIError } from "@oclif/core/errors";
2
2
 
3
+ /**
4
+ * Get the error message from an error object
5
+ *
6
+ * @param err - The error object
7
+ * @returns The error message
8
+ * @internal
9
+ */
10
+ export declare function getErrorMessage(err: unknown): string;
11
+
3
12
  /**
4
13
  * Returns whether or not the given error is a `NotFoundError`
5
14
  *
@@ -64,4 +73,13 @@ export declare class ProjectRootNotFoundError extends CLIError {
64
73
  );
65
74
  }
66
75
 
76
+ /**
77
+ * Coerce an unknown thrown value into an Error instance.
78
+ *
79
+ * @param value - The thrown value
80
+ * @returns An Error instance (the original if already an Error, otherwise a new one)
81
+ * @internal
82
+ */
83
+ export declare function toError(value: unknown): Error;
84
+
67
85
  export {};
@@ -1,3 +1,4 @@
1
+ export { getErrorMessage, toError } from '../errors/getErrorMessage.js';
1
2
  export { NonInteractiveError } from '../errors/NonInteractiveError.js';
2
3
  export { isNotFoundError, NotFoundError } from '../errors/NotFoundError.js';
3
4
  export { isProjectRootNotFoundError, ProjectRootNotFoundError } from '../errors/ProjectRootNotFoundError.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/_exports/errors.ts"],"sourcesContent":["export {NonInteractiveError} from '../errors/NonInteractiveError.js'\nexport {isNotFoundError, NotFoundError} from '../errors/NotFoundError.js'\nexport {\n isProjectRootNotFoundError,\n ProjectRootNotFoundError,\n} from '../errors/ProjectRootNotFoundError.js'\n"],"names":["NonInteractiveError","isNotFoundError","NotFoundError","isProjectRootNotFoundError","ProjectRootNotFoundError"],"mappings":"AAAA,SAAQA,mBAAmB,QAAO,mCAAkC;AACpE,SAAQC,eAAe,EAAEC,aAAa,QAAO,6BAA4B;AACzE,SACEC,0BAA0B,EAC1BC,wBAAwB,QACnB,wCAAuC"}
1
+ {"version":3,"sources":["../../src/_exports/errors.ts"],"sourcesContent":["export {getErrorMessage, toError} from '../errors/getErrorMessage.js'\nexport {NonInteractiveError} from '../errors/NonInteractiveError.js'\nexport {isNotFoundError, NotFoundError} from '../errors/NotFoundError.js'\nexport {\n isProjectRootNotFoundError,\n ProjectRootNotFoundError,\n} from '../errors/ProjectRootNotFoundError.js'\n"],"names":["getErrorMessage","toError","NonInteractiveError","isNotFoundError","NotFoundError","isProjectRootNotFoundError","ProjectRootNotFoundError"],"mappings":"AAAA,SAAQA,eAAe,EAAEC,OAAO,QAAO,+BAA8B;AACrE,SAAQC,mBAAmB,QAAO,mCAAkC;AACpE,SAAQC,eAAe,EAAEC,aAAa,QAAO,6BAA4B;AACzE,SACEC,0BAA0B,EAC1BC,wBAAwB,QACnB,wCAAuC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/_exports/index.ts"],"sourcesContent":["// DO NOT ADD NEW EXPORTS TO THIS FILE!\n// These are left here for backwards compatibility.\n// If you came here looking to add new exports, instead take a look through the `exports` in package.json and think about which of those groups your new export belongs to. You may want to consider adding a _new_ export if there is no clean conceptual fit.\n// This is all in the name of minimizing 'barrel' export files and keeping `import`s fast. See the following for context: https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7/\nexport {\n getGlobalCliClient,\n getProjectCliClient,\n type GlobalCliClientOptions,\n type ProjectCliClientOptions,\n} from '../apiClient.js'\nexport {\n clearCliTokenCache,\n type ConfigStore,\n getCliToken,\n getCliUserConfig,\n getUserConfig,\n setCliUserConfig,\n} from '../config/cli/cliUserConfig.js'\nexport {getCliConfig, getCliConfigUncached} from '../config/cli/getCliConfig.js'\nexport {getCliConfigSync} from '../config/cli/getCliConfigSync.js'\nexport {type CliConfig} from '../config/cli/types/cliConfig.js'\nexport {type UserViteConfig} from '../config/cli/types/userViteConfig.js'\nexport {type ApplicationType, isWorkbenchApp} from '../config/cli/workbenchApp.js'\nexport {findProjectRoot} from '../config/findProjectRoot.js'\nexport {findProjectRootSync} from '../config/findProjectRootSync.js'\nexport {getStudioConfig} from '../config/studio/getStudioConfig.js'\nexport {getStudioWorkspaces} from '../config/studio/getStudioWorkspaces.js'\nexport {isStudioConfig} from '../config/studio/isStudioConfig.js'\nexport {findPathForFiles} from '../config/util/findConfigsPaths.js'\nexport {findStudioConfigPath, tryFindStudioConfigPath} from '../config/util/findStudioConfigPath.js'\nexport {type ProjectRootResult} from '../config/util/recursivelyResolveProjectRoot.js'\nexport {NonInteractiveError} from '../errors/NonInteractiveError.js'\nexport {isNotFoundError, NotFoundError} from '../errors/NotFoundError.js'\nexport {\n isProjectRootNotFoundError,\n ProjectRootNotFoundError,\n} from '../errors/ProjectRootNotFoundError.js'\nexport {exitCodes} from '../exitCodes.js'\nexport {createStudioWorker, studioWorkerTask} from '../loaders/studio/studioWorkerTask.js'\nexport {tsxWorkerTask} from '../loaders/tsx/tsxWorkerTask.js'\nexport {SanityCommand, type SanityCommandInterface} from '../SanityCommand.js'\nexport {\n clearCliTelemetry,\n CLI_TELEMETRY_SYMBOL,\n getCliTelemetry,\n reportCliTraceError,\n setCliTelemetry,\n} from '../telemetry/getCliTelemetry.js'\nexport {getTelemetryBaseInfo} from '../telemetry/getTelemetryBaseInfo.js'\nexport {noopLogger} from '../telemetry/noopTelemetry.js'\nexport {\n type CLITelemetryStore,\n type ConsentInformation,\n type TelemetryUserProperties,\n} from '../telemetry/types.js'\nexport {type Output, type RequireProps, type SanityOrgUser} from '../types.js'\nexport {doImport} from '../util/doImport.js'\nexport {mockBrowserEnvironment} from '../util/environment/mockBrowserEnvironment.js'\nexport {getLocalPackageDir, getLocalPackageVersion} from '../util/getLocalPackageVersion.js'\nexport {getSanityConfigDir, getSanityDataDir} from '../util/getSanityConfigDir.js'\nexport {getSanityEnvVar} from '../util/getSanityEnvVar.js'\nexport {getSanityUrl} from '../util/getSanityUrl.js'\nexport {getWorkspace} from '../util/getWorkspace.js'\nexport {importModule} from '../util/importModule.js'\nexport {isCi} from '../util/isCi.js'\nexport {isInteractive} from '../util/isInteractive.js'\nexport {isStaging} from '../util/isStaging.js'\nexport {normalizePath} from '../util/normalizePath.js'\nexport {promisifyWorker} from '../util/promisifyWorker.js'\nexport {\n type PackageJson,\n readPackageJson,\n type ReadPackageJsonOptions,\n} from '../util/readPackageJson.js'\nexport {\n resolveLocalPackage,\n resolveLocalPackageFrom,\n resolveLocalPackagePath,\n} from '../util/resolveLocalPackage.js'\nexport {safeStructuredClone} from '../util/safeStructuredClone.js'\nexport {colorizeJson} from '../ux/colorizeJson.js'\nexport {getTimer} from '../ux/timer.js'\nexport {debug, subdebug} from './debug.js'\nexport {\n type CoreAppManifest,\n coreAppManifestSchema,\n type StudioManifest,\n studioManifestSchema,\n} from './schemas.js'\n"],"names":["getGlobalCliClient","getProjectCliClient","clearCliTokenCache","getCliToken","getCliUserConfig","getUserConfig","setCliUserConfig","getCliConfig","getCliConfigUncached","getCliConfigSync","isWorkbenchApp","findProjectRoot","findProjectRootSync","getStudioConfig","getStudioWorkspaces","isStudioConfig","findPathForFiles","findStudioConfigPath","tryFindStudioConfigPath","NonInteractiveError","isNotFoundError","NotFoundError","isProjectRootNotFoundError","ProjectRootNotFoundError","exitCodes","createStudioWorker","studioWorkerTask","tsxWorkerTask","SanityCommand","clearCliTelemetry","CLI_TELEMETRY_SYMBOL","getCliTelemetry","reportCliTraceError","setCliTelemetry","getTelemetryBaseInfo","noopLogger","doImport","mockBrowserEnvironment","getLocalPackageDir","getLocalPackageVersion","getSanityConfigDir","getSanityDataDir","getSanityEnvVar","getSanityUrl","getWorkspace","importModule","isCi","isInteractive","isStaging","normalizePath","promisifyWorker","readPackageJson","resolveLocalPackage","resolveLocalPackageFrom","resolveLocalPackagePath","safeStructuredClone","colorizeJson","getTimer","debug","subdebug","coreAppManifestSchema","studioManifestSchema"],"mappings":"AAAA,uCAAuC;AACvC,mDAAmD;AACnD,+PAA+P;AAC/P,2LAA2L;AAC3L,SACEA,kBAAkB,EAClBC,mBAAmB,QAGd,kBAAiB;AACxB,SACEC,kBAAkB,EAElBC,WAAW,EACXC,gBAAgB,EAChBC,aAAa,EACbC,gBAAgB,QACX,iCAAgC;AACvC,SAAQC,YAAY,EAAEC,oBAAoB,QAAO,gCAA+B;AAChF,SAAQC,gBAAgB,QAAO,oCAAmC;AAGlE,SAA8BC,cAAc,QAAO,gCAA+B;AAClF,SAAQC,eAAe,QAAO,+BAA8B;AAC5D,SAAQC,mBAAmB,QAAO,mCAAkC;AACpE,SAAQC,eAAe,QAAO,sCAAqC;AACnE,SAAQC,mBAAmB,QAAO,0CAAyC;AAC3E,SAAQC,cAAc,QAAO,qCAAoC;AACjE,SAAQC,gBAAgB,QAAO,qCAAoC;AACnE,SAAQC,oBAAoB,EAAEC,uBAAuB,QAAO,yCAAwC;AAEpG,SAAQC,mBAAmB,QAAO,mCAAkC;AACpE,SAAQC,eAAe,EAAEC,aAAa,QAAO,6BAA4B;AACzE,SACEC,0BAA0B,EAC1BC,wBAAwB,QACnB,wCAAuC;AAC9C,SAAQC,SAAS,QAAO,kBAAiB;AACzC,SAAQC,kBAAkB,EAAEC,gBAAgB,QAAO,wCAAuC;AAC1F,SAAQC,aAAa,QAAO,kCAAiC;AAC7D,SAAQC,aAAa,QAAoC,sBAAqB;AAC9E,SACEC,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,mBAAmB,EACnBC,eAAe,QACV,kCAAiC;AACxC,SAAQC,oBAAoB,QAAO,uCAAsC;AACzE,SAAQC,UAAU,QAAO,gCAA+B;AAOxD,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,sBAAsB,QAAO,gDAA+C;AACpF,SAAQC,kBAAkB,EAAEC,sBAAsB,QAAO,oCAAmC;AAC5F,SAAQC,kBAAkB,EAAEC,gBAAgB,QAAO,gCAA+B;AAClF,SAAQC,eAAe,QAAO,6BAA4B;AAC1D,SAAQC,YAAY,QAAO,0BAAyB;AACpD,SAAQC,YAAY,QAAO,0BAAyB;AACpD,SAAQC,YAAY,QAAO,0BAAyB;AACpD,SAAQC,IAAI,QAAO,kBAAiB;AACpC,SAAQC,aAAa,QAAO,2BAA0B;AACtD,SAAQC,SAAS,QAAO,uBAAsB;AAC9C,SAAQC,aAAa,QAAO,2BAA0B;AACtD,SAAQC,eAAe,QAAO,6BAA4B;AAC1D,SAEEC,eAAe,QAEV,6BAA4B;AACnC,SACEC,mBAAmB,EACnBC,uBAAuB,EACvBC,uBAAuB,QAClB,iCAAgC;AACvC,SAAQC,mBAAmB,QAAO,iCAAgC;AAClE,SAAQC,YAAY,QAAO,wBAAuB;AAClD,SAAQC,QAAQ,QAAO,iBAAgB;AACvC,SAAQC,KAAK,EAAEC,QAAQ,QAAO,aAAY;AAC1C,SAEEC,qBAAqB,EAErBC,oBAAoB,QACf,eAAc"}
1
+ {"version":3,"sources":["../../src/_exports/index.ts"],"sourcesContent":["// DO NOT ADD NEW EXPORTS TO THIS FILE!\n// These are left here for backwards compatibility.\n// If you came here looking to add new exports, instead take a look through the `exports` in package.json and think about which of those groups your new export belongs to. You may want to consider adding a _new_ export if there is no clean conceptual fit.\n// This is all in the name of minimizing 'barrel' export files and keeping `import`s fast. See the following for context: https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7/\nexport {\n getGlobalCliClient,\n getProjectCliClient,\n type GlobalCliClientOptions,\n type ProjectCliClientOptions,\n} from '../apiClient.js'\nexport {\n clearCliTokenCache,\n getCliToken,\n getCliUserConfig,\n getUserConfig,\n setCliUserConfig,\n} from '../config/cli/cliUserConfig.js'\nexport {getCliConfig, getCliConfigUncached} from '../config/cli/getCliConfig.js'\nexport {getCliConfigSync} from '../config/cli/getCliConfigSync.js'\nexport {type CliConfig, type ConfigStore} from '../config/cli/types/cliConfig.js'\nexport {type UserViteConfig} from '../config/cli/types/userViteConfig.js'\nexport {type ApplicationType, isWorkbenchApp} from '../config/cli/workbenchApp.js'\nexport {findProjectRoot} from '../config/findProjectRoot.js'\nexport {findProjectRootSync} from '../config/findProjectRootSync.js'\nexport {getStudioConfig} from '../config/studio/getStudioConfig.js'\nexport {getStudioWorkspaces} from '../config/studio/getStudioWorkspaces.js'\nexport {isStudioConfig} from '../config/studio/isStudioConfig.js'\nexport {findPathForFiles} from '../config/util/findConfigsPaths.js'\nexport {findStudioConfigPath, tryFindStudioConfigPath} from '../config/util/findStudioConfigPath.js'\nexport {type ProjectRootResult} from '../config/util/recursivelyResolveProjectRoot.js'\nexport {NonInteractiveError} from '../errors/NonInteractiveError.js'\nexport {isNotFoundError, NotFoundError} from '../errors/NotFoundError.js'\nexport {\n isProjectRootNotFoundError,\n ProjectRootNotFoundError,\n} from '../errors/ProjectRootNotFoundError.js'\nexport {exitCodes} from '../exitCodes.js'\nexport {createStudioWorker, studioWorkerTask} from '../loaders/studio/studioWorkerTask.js'\nexport {tsxWorkerTask} from '../loaders/tsx/tsxWorkerTask.js'\nexport {SanityCommand, type SanityCommandInterface} from '../SanityCommand.js'\nexport {\n clearCliTelemetry,\n CLI_TELEMETRY_SYMBOL,\n getCliTelemetry,\n reportCliTraceError,\n setCliTelemetry,\n} from '../telemetry/getCliTelemetry.js'\nexport {getTelemetryBaseInfo} from '../telemetry/getTelemetryBaseInfo.js'\nexport {noopLogger} from '../telemetry/noopTelemetry.js'\nexport {\n type CLITelemetryStore,\n type ConsentInformation,\n type TelemetryUserProperties,\n} from '../telemetry/types.js'\nexport {type Output, type RequireProps, type SanityOrgUser} from '../types.js'\nexport {doImport} from '../util/doImport.js'\nexport {mockBrowserEnvironment} from '../util/environment/mockBrowserEnvironment.js'\nexport {getLocalPackageDir, getLocalPackageVersion} from '../util/getLocalPackageVersion.js'\nexport {getSanityConfigDir, getSanityDataDir} from '../util/getSanityConfigDir.js'\nexport {getSanityEnvVar} from '../util/getSanityEnvVar.js'\nexport {getSanityUrl} from '../util/getSanityUrl.js'\nexport {getWorkspace} from '../util/getWorkspace.js'\nexport {importModule} from '../util/importModule.js'\nexport {isCi} from '../util/isCi.js'\nexport {isInteractive} from '../util/isInteractive.js'\nexport {isStaging} from '../util/isStaging.js'\nexport {normalizePath} from '../util/normalizePath.js'\nexport {promisifyWorker} from '../util/promisifyWorker.js'\nexport {\n type PackageJson,\n readPackageJson,\n type ReadPackageJsonOptions,\n} from '../util/readPackageJson.js'\nexport {\n resolveLocalPackage,\n resolveLocalPackageFrom,\n resolveLocalPackagePath,\n} from '../util/resolveLocalPackage.js'\nexport {safeStructuredClone} from '../util/safeStructuredClone.js'\nexport {colorizeJson} from '../ux/colorizeJson.js'\nexport {getTimer} from '../ux/timer.js'\nexport {debug, subdebug} from './debug.js'\nexport {\n type CoreAppManifest,\n coreAppManifestSchema,\n type StudioManifest,\n studioManifestSchema,\n} from './schemas.js'\n"],"names":["getGlobalCliClient","getProjectCliClient","clearCliTokenCache","getCliToken","getCliUserConfig","getUserConfig","setCliUserConfig","getCliConfig","getCliConfigUncached","getCliConfigSync","isWorkbenchApp","findProjectRoot","findProjectRootSync","getStudioConfig","getStudioWorkspaces","isStudioConfig","findPathForFiles","findStudioConfigPath","tryFindStudioConfigPath","NonInteractiveError","isNotFoundError","NotFoundError","isProjectRootNotFoundError","ProjectRootNotFoundError","exitCodes","createStudioWorker","studioWorkerTask","tsxWorkerTask","SanityCommand","clearCliTelemetry","CLI_TELEMETRY_SYMBOL","getCliTelemetry","reportCliTraceError","setCliTelemetry","getTelemetryBaseInfo","noopLogger","doImport","mockBrowserEnvironment","getLocalPackageDir","getLocalPackageVersion","getSanityConfigDir","getSanityDataDir","getSanityEnvVar","getSanityUrl","getWorkspace","importModule","isCi","isInteractive","isStaging","normalizePath","promisifyWorker","readPackageJson","resolveLocalPackage","resolveLocalPackageFrom","resolveLocalPackagePath","safeStructuredClone","colorizeJson","getTimer","debug","subdebug","coreAppManifestSchema","studioManifestSchema"],"mappings":"AAAA,uCAAuC;AACvC,mDAAmD;AACnD,+PAA+P;AAC/P,2LAA2L;AAC3L,SACEA,kBAAkB,EAClBC,mBAAmB,QAGd,kBAAiB;AACxB,SACEC,kBAAkB,EAClBC,WAAW,EACXC,gBAAgB,EAChBC,aAAa,EACbC,gBAAgB,QACX,iCAAgC;AACvC,SAAQC,YAAY,EAAEC,oBAAoB,QAAO,gCAA+B;AAChF,SAAQC,gBAAgB,QAAO,oCAAmC;AAGlE,SAA8BC,cAAc,QAAO,gCAA+B;AAClF,SAAQC,eAAe,QAAO,+BAA8B;AAC5D,SAAQC,mBAAmB,QAAO,mCAAkC;AACpE,SAAQC,eAAe,QAAO,sCAAqC;AACnE,SAAQC,mBAAmB,QAAO,0CAAyC;AAC3E,SAAQC,cAAc,QAAO,qCAAoC;AACjE,SAAQC,gBAAgB,QAAO,qCAAoC;AACnE,SAAQC,oBAAoB,EAAEC,uBAAuB,QAAO,yCAAwC;AAEpG,SAAQC,mBAAmB,QAAO,mCAAkC;AACpE,SAAQC,eAAe,EAAEC,aAAa,QAAO,6BAA4B;AACzE,SACEC,0BAA0B,EAC1BC,wBAAwB,QACnB,wCAAuC;AAC9C,SAAQC,SAAS,QAAO,kBAAiB;AACzC,SAAQC,kBAAkB,EAAEC,gBAAgB,QAAO,wCAAuC;AAC1F,SAAQC,aAAa,QAAO,kCAAiC;AAC7D,SAAQC,aAAa,QAAoC,sBAAqB;AAC9E,SACEC,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,mBAAmB,EACnBC,eAAe,QACV,kCAAiC;AACxC,SAAQC,oBAAoB,QAAO,uCAAsC;AACzE,SAAQC,UAAU,QAAO,gCAA+B;AAOxD,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,sBAAsB,QAAO,gDAA+C;AACpF,SAAQC,kBAAkB,EAAEC,sBAAsB,QAAO,oCAAmC;AAC5F,SAAQC,kBAAkB,EAAEC,gBAAgB,QAAO,gCAA+B;AAClF,SAAQC,eAAe,QAAO,6BAA4B;AAC1D,SAAQC,YAAY,QAAO,0BAAyB;AACpD,SAAQC,YAAY,QAAO,0BAAyB;AACpD,SAAQC,YAAY,QAAO,0BAAyB;AACpD,SAAQC,IAAI,QAAO,kBAAiB;AACpC,SAAQC,aAAa,QAAO,2BAA0B;AACtD,SAAQC,SAAS,QAAO,uBAAsB;AAC9C,SAAQC,aAAa,QAAO,2BAA0B;AACtD,SAAQC,eAAe,QAAO,6BAA4B;AAC1D,SAEEC,eAAe,QAEV,6BAA4B;AACnC,SACEC,mBAAmB,EACnBC,uBAAuB,EACvBC,uBAAuB,QAClB,iCAAgC;AACvC,SAAQC,mBAAmB,QAAO,iCAAgC;AAClE,SAAQC,YAAY,QAAO,wBAAuB;AAClD,SAAQC,QAAQ,QAAO,iBAAgB;AACvC,SAAQC,KAAK,EAAEC,QAAQ,QAAO,aAAY;AAC1C,SAEEC,qBAAqB,EAErBC,oBAAoB,QACf,eAAc"}
@@ -157,6 +157,22 @@ export declare interface CliConfig {
157
157
  export declare type CLITelemetryStore =
158
158
  TelemetryLogger<TelemetryUserProperties>;
159
159
 
160
+ /**
161
+ * A raw key-value store for CLI user configuration.
162
+ * Unlike the typed `getCliUserConfig`/`setCliUserConfig`, this operates on
163
+ * arbitrary keys without schema validation.
164
+ *
165
+ * @public
166
+ */
167
+ export declare interface ConfigStore {
168
+ /** Remove a key from the config file. */
169
+ delete: (key: string) => void;
170
+ /** Read a value by key. Returns `undefined` if the key does not exist. */
171
+ get: (key: string) => unknown;
172
+ /** Write a value by key, merging it into the existing config. */
173
+ set: (key: string, value: unknown) => void;
174
+ }
175
+
160
176
  export declare type ConsentInformation =
161
177
  | {
162
178
  reason: "fetchError" | "unauthenticated";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/_exports/types.ts"],"sourcesContent":["export {type CliConfig, type TypeGenConfig} from '../config/cli/types/cliConfig.js'\nexport {type UserViteConfig} from '../config/cli/types/userViteConfig.js'\nexport {type ApplicationType} from '../config/cli/workbenchApp.js'\nexport {type ProjectRootResult} from '../config/util/recursivelyResolveProjectRoot.js'\nexport {type SanityCommandInterface} from '../SanityCommand.js'\nexport {\n type CLITelemetryStore,\n type ConsentInformation,\n type TelemetryUserProperties,\n} from '../telemetry/types.js'\nexport {type Output, type RequireProps, type SanityOrgUser} from '../types.js'\nexport {type PackageJson, type ReadPackageJsonOptions} from '../util/readPackageJson.js'\nexport {type CoreAppManifest, type StudioManifest} from './schemas.js'\n"],"names":[],"mappings":"AAYA,WAAsE"}
1
+ {"version":3,"sources":["../../src/_exports/types.ts"],"sourcesContent":["export {\n type CliConfig,\n type ConfigStore,\n type TypeGenConfig,\n} from '../config/cli/types/cliConfig.js'\nexport {type UserViteConfig} from '../config/cli/types/userViteConfig.js'\nexport {type ApplicationType} from '../config/cli/workbenchApp.js'\nexport {type ProjectRootResult} from '../config/util/recursivelyResolveProjectRoot.js'\nexport {type SanityCommandInterface} from '../SanityCommand.js'\nexport {\n type CLITelemetryStore,\n type ConsentInformation,\n type TelemetryUserProperties,\n} from '../telemetry/types.js'\nexport {type Output, type RequireProps, type SanityOrgUser} from '../types.js'\nexport {type PackageJson, type ReadPackageJsonOptions} from '../util/readPackageJson.js'\nexport {type CoreAppManifest, type StudioManifest} from './schemas.js'\n"],"names":[],"mappings":"AAgBA,WAAsE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/config/cli/cliUserConfig.ts"],"sourcesContent":["import {mkdirSync} from 'node:fs'\nimport {dirname, join as joinPath} from 'node:path'\n\nimport {z} from 'zod/mini'\n\nimport {debug} from '../../_exports/debug.js'\nimport {getSanityConfigDir} from '../../util/getSanityConfigDir.js'\nimport {readJsonFileSync} from '../../util/readJsonFileSync.js'\nimport {writeJsonFileSync} from '../../util/writeJsonFileSync.js'\nimport {clearCliTokenCache, getCachedToken, setCachedToken} from './cliTokenCache.js'\n\n// Re-export so existing consumers don't break\nexport {clearCliTokenCache} from './cliTokenCache.js'\n\n// Only used for testing\nexport const _internals = {\n getCliUserConfig,\n}\n\n/**\n * Get the CLI authentication token from the environment or the config file\n *\n * @returns A promise that resolves to a CLI token, or undefined if no token is found\n * @internal\n */\nexport async function getCliToken(): Promise<string | undefined> {\n const cached = getCachedToken()\n if (cached !== undefined) {\n return cached\n }\n\n const token = process.env.SANITY_AUTH_TOKEN\n if (token) {\n const trimmed = token.trim()\n setCachedToken(trimmed)\n return trimmed\n }\n\n const configToken = _internals.getCliUserConfig('authToken')\n setCachedToken(configToken)\n return configToken\n}\nconst cliUserConfigSchema = {\n authToken: z.optional(z.string()),\n}\n\n/**\n * Set the config value for the given property.\n * Validates that the passed value adheres to the defined CLI config schema.\n *\n * @param prop - The property to set the value for\n * @param value - The value to set\n * @internal\n */\nexport function setCliUserConfig(prop: 'authToken', value: string | undefined): void {\n const config = readConfig()\n const result = cliUserConfigSchema[prop].safeParse(value)\n if (!result.success) {\n const message = result.error.issues\n .map(({message, path}) => `[${path.join('.')}] ${message}`)\n .join('\\n')\n\n throw new Error(`Invalid value for config property \"${prop}\": ${message}`)\n }\n\n const configPath = getCliUserConfigPath()\n mkdirSync(dirname(configPath), {recursive: true})\n\n // When value is undefined, explicitly delete the key rather than relying\n // on JSON.stringify silently dropping undefined values.\n if (value === undefined) {\n const {[prop]: _, ...rest} = config\n writeJsonFileSync(configPath, rest, {pretty: true})\n } else {\n writeJsonFileSync(configPath, {...config, [prop]: value}, {pretty: true})\n }\n\n // Invalidate the in-process token cache so subsequent getCliToken() calls\n // pick up the new value from disk.\n clearCliTokenCache()\n}\n\n/**\n * Get the config value for the given property\n *\n * @param prop - The property to get the value for\n * @returns The value of the given property\n */\nexport function getCliUserConfig(prop: 'authToken'): string | undefined {\n const config = readConfig()\n const result = cliUserConfigSchema[prop].safeParse(config[prop])\n if (!result.success) {\n debug('Ignoring invalid stored value for \"%s\", returning undefined', prop)\n return undefined\n }\n\n return result.data\n}\n\n/**\n * A raw key-value store for CLI user configuration.\n * Unlike the typed `getCliUserConfig`/`setCliUserConfig`, this operates on\n * arbitrary keys without schema validation.\n *\n * @public\n */\nexport interface ConfigStore {\n /** Remove a key from the config file. */\n delete: (key: string) => void\n /** Read a value by key. Returns `undefined` if the key does not exist. */\n get: (key: string) => unknown\n /** Write a value by key, merging it into the existing config. */\n set: (key: string, value: unknown) => void\n}\n\n/**\n * Get a key-value store backed by the CLI user configuration file\n * (`~/.config/sanity/config.json`).\n *\n * Each call to `get`, `set`, or `delete` performs a full synchronous\n * read-modify-write cycle. This is intentional: sync I/O prevents\n * intra-process race conditions that occurred with the previous async\n * (configstore-backed) implementation.\n *\n * Note: there is no file-level locking, so concurrent writes from\n * separate CLI processes could still conflict. In practice this is\n * unlikely since CLI config writes are rare and user-initiated.\n *\n * @returns A {@link ConfigStore} for the CLI config file\n * @public\n */\nexport function getUserConfig(): ConfigStore {\n return {\n get(key: string): unknown {\n const config = readConfig()\n return config[key]\n },\n\n set(key: string, value: unknown): void {\n const config = readConfig()\n const configPath = getCliUserConfigPath()\n mkdirSync(dirname(configPath), {recursive: true})\n writeJsonFileSync(configPath, {...config, [key]: value}, {pretty: true})\n if (key === 'authToken') clearCliTokenCache()\n },\n\n // No mkdirSync needed: if readConfig() succeeded the directory already exists.\n delete(key: string): void {\n const config = readConfig()\n if (!(key in config)) return\n const {[key]: _, ...rest} = config\n writeJsonFileSync(getCliUserConfigPath(), rest, {pretty: true})\n if (key === 'authToken') clearCliTokenCache()\n },\n }\n}\n\n/**\n * Read the whole configuration from file system. If the file does not exist,\n * is corrupt, or otherwise unreadable, an empty object is returned. This is\n * intentional: the config only holds recoverable data (auth tokens, telemetry\n * consent) so silently resetting is preferable to blocking the user.\n *\n * @returns The whole CLI configuration.\n * @internal\n */\nfunction readConfig(): Record<string, unknown> {\n try {\n const config = readJsonFileSync(getCliUserConfigPath())\n if (!config || typeof config !== 'object' || Array.isArray(config)) {\n throw new Error('Invalid config file - expected an object')\n }\n return config\n } catch (err: unknown) {\n debug('Failed to read CLI config file: %s', err instanceof Error ? err.message : `${err}`)\n return {}\n }\n}\n\n/**\n * Get the file system location for the CLI user configuration file.\n * Takes into account the active environment (staging vs production).\n * The file is located in the user's home directory under the `.config` directory.\n *\n * @returns The path to the CLI configuration file.\n * @internal\n */\nfunction getCliUserConfigPath() {\n return process.env.SANITY_CLI_CONFIG_PATH || joinPath(getSanityConfigDir(), 'config.json')\n}\n"],"names":["mkdirSync","dirname","join","joinPath","z","debug","getSanityConfigDir","readJsonFileSync","writeJsonFileSync","clearCliTokenCache","getCachedToken","setCachedToken","_internals","getCliUserConfig","getCliToken","cached","undefined","token","process","env","SANITY_AUTH_TOKEN","trimmed","trim","configToken","cliUserConfigSchema","authToken","optional","string","setCliUserConfig","prop","value","config","readConfig","result","safeParse","success","message","error","issues","map","path","Error","configPath","getCliUserConfigPath","recursive","_","rest","pretty","data","getUserConfig","get","key","set","delete","Array","isArray","err","SANITY_CLI_CONFIG_PATH"],"mappings":"AAAA,SAAQA,SAAS,QAAO,UAAS;AACjC,SAAQC,OAAO,EAAEC,QAAQC,QAAQ,QAAO,YAAW;AAEnD,SAAQC,CAAC,QAAO,WAAU;AAE1B,SAAQC,KAAK,QAAO,0BAAyB;AAC7C,SAAQC,kBAAkB,QAAO,mCAAkC;AACnE,SAAQC,gBAAgB,QAAO,iCAAgC;AAC/D,SAAQC,iBAAiB,QAAO,kCAAiC;AACjE,SAAQC,kBAAkB,EAAEC,cAAc,EAAEC,cAAc,QAAO,qBAAoB;AAErF,8CAA8C;AAC9C,SAAQF,kBAAkB,QAAO,qBAAoB;AAErD,wBAAwB;AACxB,OAAO,MAAMG,aAAa;IACxBC;AACF,EAAC;AAED;;;;;CAKC,GACD,OAAO,eAAeC;IACpB,MAAMC,SAASL;IACf,IAAIK,WAAWC,WAAW;QACxB,OAAOD;IACT;IAE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sC,sBAAsB,IAAItD,SAASG,sBAAsB;AAC9E"}
1
+ {"version":3,"sources":["../../../src/config/cli/cliUserConfig.ts"],"sourcesContent":["import {mkdirSync} from 'node:fs'\nimport {dirname, join as joinPath} from 'node:path'\n\nimport {z} from 'zod/mini'\n\nimport {debug} from '../../_exports/debug.js'\nimport {getSanityConfigDir} from '../../util/getSanityConfigDir.js'\nimport {readJsonFileSync} from '../../util/readJsonFileSync.js'\nimport {writeJsonFileSync} from '../../util/writeJsonFileSync.js'\nimport {clearCliTokenCache, getCachedToken, setCachedToken} from './cliTokenCache.js'\nimport {type ConfigStore} from './types/cliConfig.js'\n\n// Re-export so existing consumers don't break\nexport {clearCliTokenCache} from './cliTokenCache.js'\n\n// Only used for testing\nexport const _internals = {\n getCliUserConfig,\n}\n\n/**\n * Get the CLI authentication token from the environment or the config file\n *\n * @returns A promise that resolves to a CLI token, or undefined if no token is found\n * @internal\n */\nexport async function getCliToken(): Promise<string | undefined> {\n const cached = getCachedToken()\n if (cached !== undefined) {\n return cached\n }\n\n const token = process.env.SANITY_AUTH_TOKEN\n if (token) {\n const trimmed = token.trim()\n setCachedToken(trimmed)\n return trimmed\n }\n\n const configToken = _internals.getCliUserConfig('authToken')\n setCachedToken(configToken)\n return configToken\n}\nconst cliUserConfigSchema = {\n authToken: z.optional(z.string()),\n}\n\n/**\n * Set the config value for the given property.\n * Validates that the passed value adheres to the defined CLI config schema.\n *\n * @param prop - The property to set the value for\n * @param value - The value to set\n * @internal\n */\nexport function setCliUserConfig(prop: 'authToken', value: string | undefined): void {\n const config = readConfig()\n const result = cliUserConfigSchema[prop].safeParse(value)\n if (!result.success) {\n const message = result.error.issues\n .map(({message, path}) => `[${path.join('.')}] ${message}`)\n .join('\\n')\n\n throw new Error(`Invalid value for config property \"${prop}\": ${message}`)\n }\n\n const configPath = getCliUserConfigPath()\n mkdirSync(dirname(configPath), {recursive: true})\n\n // When value is undefined, explicitly delete the key rather than relying\n // on JSON.stringify silently dropping undefined values.\n if (value === undefined) {\n const {[prop]: _, ...rest} = config\n writeJsonFileSync(configPath, rest, {pretty: true})\n } else {\n writeJsonFileSync(configPath, {...config, [prop]: value}, {pretty: true})\n }\n\n // Invalidate the in-process token cache so subsequent getCliToken() calls\n // pick up the new value from disk.\n clearCliTokenCache()\n}\n\n/**\n * Get the config value for the given property\n *\n * @param prop - The property to get the value for\n * @returns The value of the given property\n */\nexport function getCliUserConfig(prop: 'authToken'): string | undefined {\n const config = readConfig()\n const result = cliUserConfigSchema[prop].safeParse(config[prop])\n if (!result.success) {\n debug('Ignoring invalid stored value for \"%s\", returning undefined', prop)\n return undefined\n }\n\n return result.data\n}\n\n/**\n * Get a key-value store backed by the CLI user configuration file\n * (`~/.config/sanity/config.json`).\n *\n * Each call to `get`, `set`, or `delete` performs a full synchronous\n * read-modify-write cycle. This is intentional: sync I/O prevents\n * intra-process race conditions that occurred with the previous async\n * (configstore-backed) implementation.\n *\n * Note: there is no file-level locking, so concurrent writes from\n * separate CLI processes could still conflict. In practice this is\n * unlikely since CLI config writes are rare and user-initiated.\n *\n * @returns A {@link ConfigStore} for the CLI config file\n * @public\n */\nexport function getUserConfig(): ConfigStore {\n return {\n get(key: string): unknown {\n const config = readConfig()\n return config[key]\n },\n\n set(key: string, value: unknown): void {\n const config = readConfig()\n const configPath = getCliUserConfigPath()\n mkdirSync(dirname(configPath), {recursive: true})\n writeJsonFileSync(configPath, {...config, [key]: value}, {pretty: true})\n if (key === 'authToken') clearCliTokenCache()\n },\n\n // No mkdirSync needed: if readConfig() succeeded the directory already exists.\n delete(key: string): void {\n const config = readConfig()\n if (!(key in config)) return\n const {[key]: _, ...rest} = config\n writeJsonFileSync(getCliUserConfigPath(), rest, {pretty: true})\n if (key === 'authToken') clearCliTokenCache()\n },\n }\n}\n\n/**\n * Read the whole configuration from file system. If the file does not exist,\n * is corrupt, or otherwise unreadable, an empty object is returned. This is\n * intentional: the config only holds recoverable data (auth tokens, telemetry\n * consent) so silently resetting is preferable to blocking the user.\n *\n * @returns The whole CLI configuration.\n * @internal\n */\nfunction readConfig(): Record<string, unknown> {\n try {\n const config = readJsonFileSync(getCliUserConfigPath())\n if (!config || typeof config !== 'object' || Array.isArray(config)) {\n throw new Error('Invalid config file - expected an object')\n }\n return config\n } catch (err: unknown) {\n debug('Failed to read CLI config file: %s', err instanceof Error ? err.message : `${err}`)\n return {}\n }\n}\n\n/**\n * Get the file system location for the CLI user configuration file.\n * Takes into account the active environment (staging vs production).\n * The file is located in the user's home directory under the `.config` directory.\n *\n * @returns The path to the CLI configuration file.\n * @internal\n */\nfunction getCliUserConfigPath() {\n return process.env.SANITY_CLI_CONFIG_PATH || joinPath(getSanityConfigDir(), 'config.json')\n}\n"],"names":["mkdirSync","dirname","join","joinPath","z","debug","getSanityConfigDir","readJsonFileSync","writeJsonFileSync","clearCliTokenCache","getCachedToken","setCachedToken","_internals","getCliUserConfig","getCliToken","cached","undefined","token","process","env","SANITY_AUTH_TOKEN","trimmed","trim","configToken","cliUserConfigSchema","authToken","optional","string","setCliUserConfig","prop","value","config","readConfig","result","safeParse","success","message","error","issues","map","path","Error","configPath","getCliUserConfigPath","recursive","_","rest","pretty","data","getUserConfig","get","key","set","delete","Array","isArray","err","SANITY_CLI_CONFIG_PATH"],"mappings":"AAAA,SAAQA,SAAS,QAAO,UAAS;AACjC,SAAQC,OAAO,EAAEC,QAAQC,QAAQ,QAAO,YAAW;AAEnD,SAAQC,CAAC,QAAO,WAAU;AAE1B,SAAQC,KAAK,QAAO,0BAAyB;AAC7C,SAAQC,kBAAkB,QAAO,mCAAkC;AACnE,SAAQC,gBAAgB,QAAO,iCAAgC;AAC/D,SAAQC,iBAAiB,QAAO,kCAAiC;AACjE,SAAQC,kBAAkB,EAAEC,cAAc,EAAEC,cAAc,QAAO,qBAAoB;AAGrF,8CAA8C;AAC9C,SAAQF,kBAAkB,QAAO,qBAAoB;AAErD,wBAAwB;AACxB,OAAO,MAAMG,aAAa;IACxBC;AACF,EAAC;AAED;;;;;CAKC,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,OAAO,CAAC;IACV;AACF;AAEA;;;;;;;CAOC,GACD,SAASb;IACP,OAAOzB,QAAQC,GAAG,CAACsC,sBAAsB,IAAItD,SAASG,sBAAsB;AAC9E"}
@@ -1,4 +1,8 @@
1
1
  /**
2
+ * A raw key-value store for CLI user configuration.
3
+ * Unlike the typed `getCliUserConfig`/`setCliUserConfig`, this operates on
4
+ * arbitrary keys without schema validation.
5
+ *
2
6
  * @public
3
7
  */ export { };
4
8
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/config/cli/types/cliConfig.ts"],"sourcesContent":["import {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\n\nimport {type UserViteConfig} from './userViteConfig'\n\nexport interface TypeGenConfig {\n formatGeneratedCode: boolean\n generates: string\n overloadClientMethods: boolean\n path: string | string[]\n schema: string\n}\n\n/**\n * @public\n */\nexport interface CliConfig {\n /** The project ID and dataset the Sanity CLI should use to run its commands */\n api?: {\n dataset?: string\n projectId?: string\n }\n\n /** Configuration for custom Sanity apps built with the App SDK */\n app?: {\n /** The entrypoint for your custom app. By default, `src/App.tsx` */\n entry?: string\n /** Dock group the app renders in. Defaults to `dock.applications`. */\n group?: 'dock.applications' | 'dock.system' | 'dock.user'\n /**\n * Path to an icon file relative to project root.\n * The file must be an SVG.\n */\n icon?: string\n /** @deprecated Use deployment.appId */\n id?: string\n /** The ID for the Sanity organization that manages this application */\n organizationId?: string\n /** Sort position within the dock group, ascending. Defaults to `100`. */\n priority?: number\n /** The title of the custom app, as it is seen in Dashboard UI */\n title?: string\n }\n\n /** @deprecated Use deployment.autoUpdates */\n autoUpdates?: boolean\n\n /** Options for custom app and Studio deployments */\n deployment?: {\n /**\n * The ID for your custom app or Studio. Generated when deploying your app or Studio for the first time.\n * Get your app ID by either:\n * 1. Checking the output of `sanity deploy`, or\n * 2. Checking your project’s Studio tab at https://sanity.io/manage\n *\n * @remarks This is required for all custom app deployments, and for Studios opting in to fine grained version control.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity#k0896ed4574b7}\n */\n appId?: string\n /**\n * Enable automatic updates for your Studio or custom app’s Sanity dependencies.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity}\n */\n autoUpdates?: boolean\n }\n\n /** Define the GraphQL APIs that the CLI can deploy and interact with */\n graphql?: Array<{\n filterSuffix?: string\n generation?: 'gen1' | 'gen2' | 'gen3'\n id?: string\n nonNullDocumentFields?: boolean\n playground?: boolean\n source?: string\n tag?: string\n workspace?: string\n }>\n\n /** Configuration for the Media Library */\n mediaLibrary?: {\n /** The path to the Media Library aspects directory. When using the CLI to manage aspects, this is the directory they will be read from and written to. */\n aspectsPath?: string\n }\n\n /** Contains the property `basePath` which lets you change the top-level slug for the Studio. You typically need to set this if you embed the Studio in another application where it is one of many routes. Defaults to an empty string. */\n project?: {\n basePath?: string\n }\n\n /** Configuration options for React Compiler */\n reactCompiler?: ReactCompilerConfig\n\n /** Wraps the Studio in \\<React.StrictMode\\> root to aid in flagging potential problems related to concurrent features (startTransition, useTransition, useDeferredValue, Suspense). Can also be enabled by setting SANITY_STUDIO_REACT_STRICT_MODE=\"true\"|\"false\". It only applies to sanity dev in development mode and is ignored in sanity build and in production. Defaults to true. */\n reactStrictMode?: boolean\n\n /**\n * Configuration for schema extraction (`sanity schema extract`)\n */\n schemaExtraction?: {\n /**\n * Enable schema extraction as part of sanity dev and sanity build\n */\n enabled?: boolean\n\n /**\n * When true, schema fields marked as required will be non-optional in the output.\n * Defaults to `false`\n */\n enforceRequiredFields?: boolean\n\n /**\n * Output path for the extracted schema file.\n * Defaults to `schema.json` in the working directory.\n */\n path?: string\n\n /**\n * Additional glob patterns to watch for schema changes in watch mode.\n * These extend the default patterns:\n * - `sanity.config.{js,jsx,ts,tsx,mjs}`\n * - `schema*\\/**\\/*.{js,jsx,ts,tsx,mjs}`\n */\n watchPatterns?: string[]\n\n /**\n * The name of the workspace to generate a schema for. Required if your Sanity project has more than one\n * workspace.\n */\n workspace?: string\n }\n\n /** Defines the hostname and port that the development server should run on. hostname defaults to localhost, and port to 3333. */\n server?: {\n hostname?: string\n port?: number\n }\n\n /** @deprecated Use deployment.appId */\n studioHost?: string\n\n /**\n * Configuration for Sanity typegen\n */\n typegen?: Partial<TypeGenConfig> & {\n /**\n * Enable typegen as part of sanity dev and sanity build.\n * When enabled, types are generated on startup and when files change.\n * Defaults to `false`\n */\n enabled?: boolean\n }\n\n /**\n * Enable Vite's experimental bundled dev mode for `sanity dev`. This serves bundled\n * files during development, which can speed up startup and reloads for large projects.\n * Defaults to `false`.\n *\n * Unstable: may change or be removed without notice while the underlying Vite\n * feature (`experimental.bundledDev`) is experimental.\n * {@link https://vite.dev/guide/rolldown#full-bundle-mode}\n */\n unstable_bundledDev?: boolean\n\n /** Exposes the default Vite configuration for custom apps and the Studio so it can be changed and extended. */\n vite?: UserViteConfig\n}\n"],"names":[],"mappings":"AAYA;;CAEC,GACD,WAqJC"}
1
+ {"version":3,"sources":["../../../../src/config/cli/types/cliConfig.ts"],"sourcesContent":["import {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\n\nimport {type UserViteConfig} from './userViteConfig'\n\nexport interface TypeGenConfig {\n formatGeneratedCode: boolean\n generates: string\n overloadClientMethods: boolean\n path: string | string[]\n schema: string\n}\n\n/**\n * @public\n */\nexport interface CliConfig {\n /** The project ID and dataset the Sanity CLI should use to run its commands */\n api?: {\n dataset?: string\n projectId?: string\n }\n\n /** Configuration for custom Sanity apps built with the App SDK */\n app?: {\n /** The entrypoint for your custom app. By default, `src/App.tsx` */\n entry?: string\n /** Dock group the app renders in. Defaults to `dock.applications`. */\n group?: 'dock.applications' | 'dock.system' | 'dock.user'\n /**\n * Path to an icon file relative to project root.\n * The file must be an SVG.\n */\n icon?: string\n /** @deprecated Use deployment.appId */\n id?: string\n /** The ID for the Sanity organization that manages this application */\n organizationId?: string\n /** Sort position within the dock group, ascending. Defaults to `100`. */\n priority?: number\n /** The title of the custom app, as it is seen in Dashboard UI */\n title?: string\n }\n\n /** @deprecated Use deployment.autoUpdates */\n autoUpdates?: boolean\n\n /** Options for custom app and Studio deployments */\n deployment?: {\n /**\n * The ID for your custom app or Studio. Generated when deploying your app or Studio for the first time.\n * Get your app ID by either:\n * 1. Checking the output of `sanity deploy`, or\n * 2. Checking your project’s Studio tab at https://sanity.io/manage\n *\n * @remarks This is required for all custom app deployments, and for Studios opting in to fine grained version control.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity#k0896ed4574b7}\n */\n appId?: string\n /**\n * Enable automatic updates for your Studio or custom app’s Sanity dependencies.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity}\n */\n autoUpdates?: boolean\n }\n\n /** Define the GraphQL APIs that the CLI can deploy and interact with */\n graphql?: Array<{\n filterSuffix?: string\n generation?: 'gen1' | 'gen2' | 'gen3'\n id?: string\n nonNullDocumentFields?: boolean\n playground?: boolean\n source?: string\n tag?: string\n workspace?: string\n }>\n\n /** Configuration for the Media Library */\n mediaLibrary?: {\n /** The path to the Media Library aspects directory. When using the CLI to manage aspects, this is the directory they will be read from and written to. */\n aspectsPath?: string\n }\n\n /** Contains the property `basePath` which lets you change the top-level slug for the Studio. You typically need to set this if you embed the Studio in another application where it is one of many routes. Defaults to an empty string. */\n project?: {\n basePath?: string\n }\n\n /** Configuration options for React Compiler */\n reactCompiler?: ReactCompilerConfig\n\n /** Wraps the Studio in \\<React.StrictMode\\> root to aid in flagging potential problems related to concurrent features (startTransition, useTransition, useDeferredValue, Suspense). Can also be enabled by setting SANITY_STUDIO_REACT_STRICT_MODE=\"true\"|\"false\". It only applies to sanity dev in development mode and is ignored in sanity build and in production. Defaults to true. */\n reactStrictMode?: boolean\n\n /**\n * Configuration for schema extraction (`sanity schema extract`)\n */\n schemaExtraction?: {\n /**\n * Enable schema extraction as part of sanity dev and sanity build\n */\n enabled?: boolean\n\n /**\n * When true, schema fields marked as required will be non-optional in the output.\n * Defaults to `false`\n */\n enforceRequiredFields?: boolean\n\n /**\n * Output path for the extracted schema file.\n * Defaults to `schema.json` in the working directory.\n */\n path?: string\n\n /**\n * Additional glob patterns to watch for schema changes in watch mode.\n * These extend the default patterns:\n * - `sanity.config.{js,jsx,ts,tsx,mjs}`\n * - `schema*\\/**\\/*.{js,jsx,ts,tsx,mjs}`\n */\n watchPatterns?: string[]\n\n /**\n * The name of the workspace to generate a schema for. Required if your Sanity project has more than one\n * workspace.\n */\n workspace?: string\n }\n\n /** Defines the hostname and port that the development server should run on. hostname defaults to localhost, and port to 3333. */\n server?: {\n hostname?: string\n port?: number\n }\n\n /** @deprecated Use deployment.appId */\n studioHost?: string\n\n /**\n * Configuration for Sanity typegen\n */\n typegen?: Partial<TypeGenConfig> & {\n /**\n * Enable typegen as part of sanity dev and sanity build.\n * When enabled, types are generated on startup and when files change.\n * Defaults to `false`\n */\n enabled?: boolean\n }\n\n /**\n * Enable Vite's experimental bundled dev mode for `sanity dev`. This serves bundled\n * files during development, which can speed up startup and reloads for large projects.\n * Defaults to `false`.\n *\n * Unstable: may change or be removed without notice while the underlying Vite\n * feature (`experimental.bundledDev`) is experimental.\n * {@link https://vite.dev/guide/rolldown#full-bundle-mode}\n */\n unstable_bundledDev?: boolean\n\n /** Exposes the default Vite configuration for custom apps and the Studio so it can be changed and extended. */\n vite?: UserViteConfig\n}\n\n/**\n * A raw key-value store for CLI user configuration.\n * Unlike the typed `getCliUserConfig`/`setCliUserConfig`, this operates on\n * arbitrary keys without schema validation.\n *\n * @public\n */\nexport interface ConfigStore {\n /** Remove a key from the config file. */\n delete: (key: string) => void\n /** Read a value by key. Returns `undefined` if the key does not exist. */\n get: (key: string) => unknown\n /** Write a value by key, merging it into the existing config. */\n set: (key: string, value: unknown) => void\n}\n"],"names":[],"mappings":"AAsKA;;;;;;CAMC,GACD,WAOC"}
@@ -0,0 +1,28 @@
1
+ import { isHttpError } from '@sanity/client';
2
+ /**
3
+ * Coerce an unknown thrown value into an Error instance.
4
+ *
5
+ * @param value - The thrown value
6
+ * @returns An Error instance (the original if already an Error, otherwise a new one)
7
+ * @internal
8
+ */ export function toError(value) {
9
+ return value instanceof Error ? value : new Error(String(value));
10
+ }
11
+ /**
12
+ * Get the error message from an error object
13
+ *
14
+ * @param err - The error object
15
+ * @returns The error message
16
+ * @internal
17
+ */ export function getErrorMessage(err) {
18
+ if (isHttpError(err)) {
19
+ const body = err.response.body;
20
+ if (typeof body === 'object' && body !== null && 'message' in body && typeof body.message === 'string') {
21
+ return body.message;
22
+ }
23
+ return err.message || 'HTTP error';
24
+ }
25
+ return err instanceof Error ? err.message : 'Unknown error';
26
+ }
27
+
28
+ //# sourceMappingURL=getErrorMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors/getErrorMessage.ts"],"sourcesContent":["import {isHttpError} from '@sanity/client'\n\n/**\n * Coerce an unknown thrown value into an Error instance.\n *\n * @param value - The thrown value\n * @returns An Error instance (the original if already an Error, otherwise a new one)\n * @internal\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Get the error message from an error object\n *\n * @param err - The error object\n * @returns The error message\n * @internal\n */\nexport function getErrorMessage(err: unknown): string {\n if (isHttpError(err)) {\n const body = err.response.body\n if (\n typeof body === 'object' &&\n body !== null &&\n 'message' in body &&\n typeof body.message === 'string'\n ) {\n return body.message\n }\n return err.message || 'HTTP error'\n }\n return err instanceof Error ? err.message : 'Unknown error'\n}\n"],"names":["isHttpError","toError","value","Error","String","getErrorMessage","err","body","response","message"],"mappings":"AAAA,SAAQA,WAAW,QAAO,iBAAgB;AAE1C;;;;;;CAMC,GACD,OAAO,SAASC,QAAQC,KAAc;IACpC,OAAOA,iBAAiBC,QAAQD,QAAQ,IAAIC,MAAMC,OAAOF;AAC3D;AAEA;;;;;;CAMC,GACD,OAAO,SAASG,gBAAgBC,GAAY;IAC1C,IAAIN,YAAYM,MAAM;QACpB,MAAMC,OAAOD,IAAIE,QAAQ,CAACD,IAAI;QAC9B,IACE,OAAOA,SAAS,YAChBA,SAAS,QACT,aAAaA,QACb,OAAOA,KAAKE,OAAO,KAAK,UACxB;YACA,OAAOF,KAAKE,OAAO;QACrB;QACA,OAAOH,IAAIG,OAAO,IAAI;IACxB;IACA,OAAOH,eAAeH,QAAQG,IAAIG,OAAO,GAAG;AAC9C"}
@@ -1,6 +1,7 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { up as packageUp } from 'empathic/package';
1
3
  import { getIt } from 'get-it';
2
4
  import { debug, headers, httpErrors, promise } from 'get-it/middleware';
3
- import { readPackageUpSync } from 'read-package-up';
4
5
  let cachedPkg;
5
6
  /**
6
7
  * Creates a `get-it` requester with a standard set of middleware.
@@ -67,15 +68,16 @@ let cachedPkg;
67
68
  * @internal
68
69
  */ function getPackageInfo() {
69
70
  if (cachedPkg) return cachedPkg;
70
- const result = readPackageUpSync({
71
+ const pkgPath = packageUp({
71
72
  cwd: import.meta.dirname
72
73
  });
73
- if (!result) {
74
+ if (!pkgPath) {
74
75
  throw new Error('Unable to resolve @sanity/cli-core package root');
75
76
  }
77
+ const packageJson = JSON.parse(readFileSync(pkgPath, 'utf8'));
76
78
  cachedPkg = {
77
- name: result.packageJson.name ?? '@sanity/cli-core',
78
- version: result.packageJson.version ?? '0.0.0'
79
+ name: packageJson.name ?? '@sanity/cli-core',
80
+ version: packageJson.version ?? '0.0.0'
79
81
  };
80
82
  return cachedPkg;
81
83
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/request/createRequester.ts"],"sourcesContent":["import {getIt, type Requester} from 'get-it'\nimport {debug, headers, httpErrors, promise} from 'get-it/middleware'\nimport {readPackageUpSync} from 'read-package-up'\n\nlet cachedPkg: {name: string; version: string} | undefined\n\n/**\n * Options for configuring individual middleware in {@link createRequester}.\n *\n * Each key corresponds to a middleware. Omitting a key uses the default,\n * `false` disables it, and an object merges with the defaults.\n *\n * @public\n */\nexport type MiddlewareOptions = {\n debug?: false | {namespace?: string; verbose?: boolean}\n headers?: false | Record<string, string>\n httpErrors?: false\n promise?: false | {onlyBody?: boolean}\n}\n\n/**\n * Creates a `get-it` requester with a standard set of middleware.\n *\n * Default middleware (in order):\n * 1. `httpErrors()` — throw on HTTP error status codes\n * 2. `headers({'User-Agent': '@sanity/cli-core@<version>'})` — identify CLI requests\n * 3. `debug({verbose: true, namespace: 'sanity:cli'})` — debug logging\n * 4. `promise({onlyBody: true})` — return body directly (must be last)\n *\n * @param options - Optional configuration to disable or customize middleware\n * @returns A configured `get-it` requester\n * @public\n */\nexport function createRequester(options?: {middleware?: MiddlewareOptions}): Requester {\n const opts = options?.middleware\n\n const middleware = []\n\n // 1. httpErrors\n if (opts?.httpErrors !== false) {\n middleware.push(httpErrors())\n }\n\n // 2. headers\n if (opts?.headers !== false) {\n const customHeaders = typeof opts?.headers === 'object' ? opts.headers : {}\n const allHeaders = customHeaders['User-Agent']\n ? {...customHeaders}\n : {\n get ['User-Agent']() {\n const pkg = getPackageInfo()\n return `${pkg.name}@${pkg.version}`\n },\n ...customHeaders,\n }\n middleware.push(headers(allHeaders))\n }\n\n // 3. debug\n if (opts?.debug !== false) {\n const debugDefaults = {namespace: 'sanity:cli', verbose: true}\n const customDebug = typeof opts?.debug === 'object' ? opts.debug : {}\n middleware.push(debug({...debugDefaults, ...customDebug}))\n }\n\n // 4. promise (must be last)\n if (opts?.promise !== false) {\n const promiseDefaults = {onlyBody: true}\n const customPromise = typeof opts?.promise === 'object' ? opts.promise : {}\n middleware.push(promise({...promiseDefaults, ...customPromise}))\n }\n\n return getIt(middleware)\n}\n\n/**\n * Reads the nearest `package.json` to determine the name and version of the `@sanity/cli-core` package.\n *\n * @returns The name and version of the package\n * @internal\n */\nfunction getPackageInfo(): {name: string; version: string} {\n if (cachedPkg) return cachedPkg\n\n const result = readPackageUpSync({cwd: import.meta.dirname})\n if (!result) {\n throw new Error('Unable to resolve @sanity/cli-core package root')\n }\n\n cachedPkg = {\n name: result.packageJson.name ?? '@sanity/cli-core',\n version: result.packageJson.version ?? '0.0.0',\n }\n return cachedPkg\n}\n"],"names":["getIt","debug","headers","httpErrors","promise","readPackageUpSync","cachedPkg","createRequester","options","opts","middleware","push","customHeaders","allHeaders","pkg","getPackageInfo","name","version","debugDefaults","namespace","verbose","customDebug","promiseDefaults","onlyBody","customPromise","result","cwd","dirname","Error","packageJson"],"mappings":"AAAA,SAAQA,KAAK,QAAuB,SAAQ;AAC5C,SAAQC,KAAK,EAAEC,OAAO,EAAEC,UAAU,EAAEC,OAAO,QAAO,oBAAmB;AACrE,SAAQC,iBAAiB,QAAO,kBAAiB;AAEjD,IAAIC;AAiBJ;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,gBAAgBC,OAA0C;IACxE,MAAMC,OAAOD,SAASE;IAEtB,MAAMA,aAAa,EAAE;IAErB,gBAAgB;IAChB,IAAID,MAAMN,eAAe,OAAO;QAC9BO,WAAWC,IAAI,CAACR;IAClB;IAEA,aAAa;IACb,IAAIM,MAAMP,YAAY,OAAO;QAC3B,MAAMU,gBAAgB,OAAOH,MAAMP,YAAY,WAAWO,KAAKP,OAAO,GAAG,CAAC;QAC1E,MAAMW,aAAaD,aAAa,CAAC,aAAa,GAC1C;YAAC,GAAGA,aAAa;QAAA,IACjB;YACE,IAAI,CAAC,aAAa,IAAG;gBACnB,MAAME,MAAMC;gBACZ,OAAO,GAAGD,IAAIE,IAAI,CAAC,CAAC,EAAEF,IAAIG,OAAO,EAAE;YACrC;YACA,GAAGL,aAAa;QAClB;QACJF,WAAWC,IAAI,CAACT,QAAQW;IAC1B;IAEA,WAAW;IACX,IAAIJ,MAAMR,UAAU,OAAO;QACzB,MAAMiB,gBAAgB;YAACC,WAAW;YAAcC,SAAS;QAAI;QAC7D,MAAMC,cAAc,OAAOZ,MAAMR,UAAU,WAAWQ,KAAKR,KAAK,GAAG,CAAC;QACpES,WAAWC,IAAI,CAACV,MAAM;YAAC,GAAGiB,aAAa;YAAE,GAAGG,WAAW;QAAA;IACzD;IAEA,4BAA4B;IAC5B,IAAIZ,MAAML,YAAY,OAAO;QAC3B,MAAMkB,kBAAkB;YAACC,UAAU;QAAI;QACvC,MAAMC,gBAAgB,OAAOf,MAAML,YAAY,WAAWK,KAAKL,OAAO,GAAG,CAAC;QAC1EM,WAAWC,IAAI,CAACP,QAAQ;YAAC,GAAGkB,eAAe;YAAE,GAAGE,aAAa;QAAA;IAC/D;IAEA,OAAOxB,MAAMU;AACf;AAEA;;;;;CAKC,GACD,SAASK;IACP,IAAIT,WAAW,OAAOA;IAEtB,MAAMmB,SAASpB,kBAAkB;QAACqB,KAAK,YAAYC,OAAO;IAAA;IAC1D,IAAI,CAACF,QAAQ;QACX,MAAM,IAAIG,MAAM;IAClB;IAEAtB,YAAY;QACVU,MAAMS,OAAOI,WAAW,CAACb,IAAI,IAAI;QACjCC,SAASQ,OAAOI,WAAW,CAACZ,OAAO,IAAI;IACzC;IACA,OAAOX;AACT"}
1
+ {"version":3,"sources":["../../src/request/createRequester.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\n\nimport {up as packageUp} from 'empathic/package'\nimport {getIt, type Requester} from 'get-it'\nimport {debug, headers, httpErrors, promise} from 'get-it/middleware'\n\nlet cachedPkg: {name: string; version: string} | undefined\n\n/**\n * Options for configuring individual middleware in {@link createRequester}.\n *\n * Each key corresponds to a middleware. Omitting a key uses the default,\n * `false` disables it, and an object merges with the defaults.\n *\n * @public\n */\nexport type MiddlewareOptions = {\n debug?: false | {namespace?: string; verbose?: boolean}\n headers?: false | Record<string, string>\n httpErrors?: false\n promise?: false | {onlyBody?: boolean}\n}\n\n/**\n * Creates a `get-it` requester with a standard set of middleware.\n *\n * Default middleware (in order):\n * 1. `httpErrors()` — throw on HTTP error status codes\n * 2. `headers({'User-Agent': '@sanity/cli-core@<version>'})` — identify CLI requests\n * 3. `debug({verbose: true, namespace: 'sanity:cli'})` — debug logging\n * 4. `promise({onlyBody: true})` — return body directly (must be last)\n *\n * @param options - Optional configuration to disable or customize middleware\n * @returns A configured `get-it` requester\n * @public\n */\nexport function createRequester(options?: {middleware?: MiddlewareOptions}): Requester {\n const opts = options?.middleware\n\n const middleware = []\n\n // 1. httpErrors\n if (opts?.httpErrors !== false) {\n middleware.push(httpErrors())\n }\n\n // 2. headers\n if (opts?.headers !== false) {\n const customHeaders = typeof opts?.headers === 'object' ? opts.headers : {}\n const allHeaders = customHeaders['User-Agent']\n ? {...customHeaders}\n : {\n get ['User-Agent']() {\n const pkg = getPackageInfo()\n return `${pkg.name}@${pkg.version}`\n },\n ...customHeaders,\n }\n middleware.push(headers(allHeaders))\n }\n\n // 3. debug\n if (opts?.debug !== false) {\n const debugDefaults = {namespace: 'sanity:cli', verbose: true}\n const customDebug = typeof opts?.debug === 'object' ? opts.debug : {}\n middleware.push(debug({...debugDefaults, ...customDebug}))\n }\n\n // 4. promise (must be last)\n if (opts?.promise !== false) {\n const promiseDefaults = {onlyBody: true}\n const customPromise = typeof opts?.promise === 'object' ? opts.promise : {}\n middleware.push(promise({...promiseDefaults, ...customPromise}))\n }\n\n return getIt(middleware)\n}\n\n/**\n * Reads the nearest `package.json` to determine the name and version of the `@sanity/cli-core` package.\n *\n * @returns The name and version of the package\n * @internal\n */\nfunction getPackageInfo(): {name: string; version: string} {\n if (cachedPkg) return cachedPkg\n\n const pkgPath = packageUp({cwd: import.meta.dirname})\n if (!pkgPath) {\n throw new Error('Unable to resolve @sanity/cli-core package root')\n }\n\n const packageJson = JSON.parse(readFileSync(pkgPath, 'utf8'))\n cachedPkg = {\n name: packageJson.name ?? '@sanity/cli-core',\n version: packageJson.version ?? '0.0.0',\n }\n return cachedPkg\n}\n"],"names":["readFileSync","up","packageUp","getIt","debug","headers","httpErrors","promise","cachedPkg","createRequester","options","opts","middleware","push","customHeaders","allHeaders","pkg","getPackageInfo","name","version","debugDefaults","namespace","verbose","customDebug","promiseDefaults","onlyBody","customPromise","pkgPath","cwd","dirname","Error","packageJson","JSON","parse"],"mappings":"AAAA,SAAQA,YAAY,QAAO,UAAS;AAEpC,SAAQC,MAAMC,SAAS,QAAO,m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OAAOvB,MAAMS;AACf;AAEA;;;;;CAKC,GACD,SAASK;IACP,IAAIT,WAAW,OAAOA;IAEtB,MAAMmB,UAAUzB,UAAU;QAAC0B,KAAK,YAAYC,OAAO;IAAA;IACnD,IAAI,CAACF,SAAS;QACZ,MAAM,IAAIG,MAAM;IAClB;IAEA,MAAMC,cAAcC,KAAKC,KAAK,CAACjC,aAAa2B,SAAS;IACrDnB,YAAY;QACVU,MAAMa,YAAYb,IAAI,IAAI;QAC1BC,SAASY,YAAYZ,OAAO,IAAI;IAClC;IACA,OAAOX;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli-core",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Sanity CLI core package",
5
5
  "keywords": [
6
6
  "cli",
@@ -104,6 +104,7 @@
104
104
  "@sanity/client": "^7.23.0",
105
105
  "boxen": "^8.0.1",
106
106
  "debug": "^4.4.3",
107
+ "empathic": "^2.0.1",
107
108
  "get-it": "^8.8.0",
108
109
  "get-tsconfig": "^4.14.0",
109
110
  "import-meta-resolve": "^4.2.0",
@@ -112,7 +113,6 @@
112
113
  "json-lexer": "^1.2.0",
113
114
  "log-symbols": "^7.0.1",
114
115
  "ora": "^9.0.0",
115
- "read-package-up": "^12.0.0",
116
116
  "rxjs": "^7.8.2",
117
117
  "tsx": "^4.22.4",
118
118
  "vite": "^8.1.3",