@sanity/cli 8.28.2 → 8.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/actions/build/buildApp.js +1 -0
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStudio.js +1 -0
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/deploy/createUserApplication.js +4 -1
- package/dist/actions/deploy/createUserApplication.js.map +1 -1
- package/dist/actions/deploy/deployChecks.js +3 -2
- package/dist/actions/deploy/deployChecks.js.map +1 -1
- package/dist/actions/deploy/deployRunner.js +3 -2
- package/dist/actions/deploy/deployRunner.js.map +1 -1
- package/dist/actions/deploy/findUserApplication.js +4 -3
- package/dist/actions/deploy/findUserApplication.js.map +1 -1
- package/dist/actions/deploy/serviceUnavailable.js +49 -0
- package/dist/actions/deploy/serviceUnavailable.js.map +1 -0
- package/dist/actions/dev/servers/getDashboardAppUrl.js +2 -2
- package/dist/actions/dev/servers/getDashboardAppUrl.js.map +1 -1
- package/dist/actions/dev/servers/getDevServerConfig.js +1 -0
- package/dist/actions/dev/servers/getDevServerConfig.js.map +1 -1
- package/dist/actions/dev/servers/startAppDevServer.js +3 -2
- package/dist/actions/dev/servers/startAppDevServer.js.map +1 -1
- package/dist/actions/dev/servers/startStudioDevServer.js +4 -2
- package/dist/actions/dev/servers/startStudioDevServer.js.map +1 -1
- package/dist/actions/documents/validateDocuments.worker.js +34 -30
- package/dist/actions/documents/validateDocuments.worker.js.map +1 -1
- package/dist/actions/mcp/detectAvailableEditors.js +5 -13
- package/dist/actions/mcp/detectAvailableEditors.js.map +1 -1
- package/dist/actions/mcp/editorConfigs.js +43 -89
- package/dist/actions/mcp/editorConfigs.js.map +1 -1
- package/dist/actions/mcp/promptForMCPSetup.js +2 -5
- package/dist/actions/mcp/promptForMCPSetup.js.map +1 -1
- package/dist/actions/mcp/setupMCP.js +37 -50
- package/dist/actions/mcp/setupMCP.js.map +1 -1
- package/dist/actions/mcp/types.js.map +1 -1
- package/dist/actions/mcp/writeMCPConfig.js +3 -3
- package/dist/actions/mcp/writeMCPConfig.js.map +1 -1
- package/dist/commands/mcp/configure.js +2 -22
- package/dist/commands/mcp/configure.js.map +1 -1
- package/dist/commands/skills/install.js +1 -1
- package/dist/commands/skills/install.js.map +1 -1
- package/dist/exports/invokeSanityCli/index.d.ts +4 -2
- package/dist/exports/runtime.d.ts +2 -2
- package/dist/exports/runtime.js +1 -1
- package/dist/exports/runtime.js.map +1 -1
- package/dist/generated/apiRoutes.js +12 -0
- package/dist/generated/apiRoutes.js.map +1 -1
- package/dist/server/devServer.js +2 -1
- package/dist/server/devServer.js.map +1 -1
- package/dist/services/mcp.js +1 -73
- package/dist/services/mcp.js.map +1 -1
- package/oclif.manifest.json +606 -606
- package/package.json +27 -25
- package/dist/actions/mcp/validateEditorTokens.js +0 -56
- package/dist/actions/mcp/validateEditorTokens.js.map +0 -1
package/README.md
CHANGED
|
@@ -4505,15 +4505,15 @@ EXAMPLES
|
|
|
4505
4505
|
|
|
4506
4506
|
## `sanity mcp configure`
|
|
4507
4507
|
|
|
4508
|
-
Configure Sanity MCP server for AI editors (Antigravity, Claude Code, Cline,
|
|
4508
|
+
Configure Sanity MCP server for AI editors (Antigravity, Claude Code, Cline, Codex CLI, Cursor, Gemini CLI, GitHub Copilot CLI, MCPorter, OpenCode, VS Code, VS Code Insiders, Zed)
|
|
4509
4509
|
|
|
4510
4510
|
```
|
|
4511
4511
|
USAGE
|
|
4512
4512
|
$ sanity mcp configure
|
|
4513
4513
|
|
|
4514
4514
|
DESCRIPTION
|
|
4515
|
-
Configure Sanity MCP server for AI editors (Antigravity, Claude Code, Cline,
|
|
4516
|
-
|
|
4515
|
+
Configure Sanity MCP server for AI editors (Antigravity, Claude Code, Cline, Codex CLI, Cursor, Gemini CLI, GitHub
|
|
4516
|
+
Copilot CLI, MCPorter, OpenCode, VS Code, VS Code Insiders, Zed)
|
|
4517
4517
|
|
|
4518
4518
|
EXAMPLES
|
|
4519
4519
|
Configure Sanity MCP server for detected AI editors
|
|
@@ -5340,15 +5340,15 @@ EXAMPLES
|
|
|
5340
5340
|
|
|
5341
5341
|
## `sanity skills install`
|
|
5342
5342
|
|
|
5343
|
-
Install Sanity agent skills for detected AI editors (Antigravity, Claude Code, Cline,
|
|
5343
|
+
Install Sanity agent skills for detected AI editors (Antigravity, Claude Code, Cline, Codex CLI, Cursor, Gemini CLI, GitHub Copilot CLI, OpenCode, VS Code, VS Code Insiders)
|
|
5344
5344
|
|
|
5345
5345
|
```
|
|
5346
5346
|
USAGE
|
|
5347
5347
|
$ sanity skills install
|
|
5348
5348
|
|
|
5349
5349
|
DESCRIPTION
|
|
5350
|
-
Install Sanity agent skills for detected AI editors (Antigravity, Claude Code, Cline,
|
|
5351
|
-
|
|
5350
|
+
Install Sanity agent skills for detected AI editors (Antigravity, Claude Code, Cline, Codex CLI, Cursor, Gemini CLI,
|
|
5351
|
+
GitHub Copilot CLI, OpenCode, VS Code, VS Code Insiders)
|
|
5352
5352
|
|
|
5353
5353
|
EXAMPLES
|
|
5354
5354
|
Install Sanity agent skills for detected AI editors
|
|
@@ -46,6 +46,7 @@ import { preReleaseEventListenerFactory } from './eventListenerFactory.js';
|
|
|
46
46
|
appId
|
|
47
47
|
}),
|
|
48
48
|
determineBasePath: ()=>determineBasePath(cliConfig, 'app', output),
|
|
49
|
+
documentComponent: cliConfig.unstable_documentComponent,
|
|
49
50
|
entry: resolveAppEntry(app),
|
|
50
51
|
exposes,
|
|
51
52
|
isWorkbenchApp: isWorkbench,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/buildApp.ts"],"sourcesContent":["import {\n compareDependencyVersions,\n buildApp as internalBuildApp,\n} from '@sanity/cli-build/_internal/build'\nimport {\n buildAppId,\n resolveAppEntry,\n resolveWorkbenchApp,\n resolveWorkbenchConfig,\n} from '@sanity/workbench-cli/build'\n\nimport {getAppId} from '../../util/appId.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {preReleaseEventListenerFactory} from './eventListenerFactory.js'\nimport {type BuildOptions} from './types.js'\n\n/**\n * Build the Sanity app.\n *\n * @internal\n */\nexport async function buildApp(\n options: BuildOptions,\n): Promise<{mfManifest: Record<string, unknown> | undefined}> {\n const {cliConfig, flags, outDir, output, workDir} = options\n\n const app = cliConfig && 'app' in cliConfig ? cliConfig.app : undefined\n // `views`/`webWorkers` live on the branded `defineApplication` result, not the\n // legacy `app` config object — resolve the workbench capability to read them. A\n // config is not an app: it resolves separately and only expands its `fields`.\n const workbench = resolveWorkbenchApp(cliConfig)\n const workbenchConfig = resolveWorkbenchConfig(cliConfig)\n const exposes = workbench\n ? {views: workbench.views, webWorkers: workbench.webWorkers}\n : workbenchConfig\n ? {config: {appType: workbenchConfig.appType, fields: workbenchConfig.fields}}\n : undefined\n const isWorkbench = !!workbench || !!workbenchConfig\n\n const appId = getAppId(cliConfig)\n\n return internalBuildApp({\n appId,\n appTitle: app?.title,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n checkAppId: () => {\n // Warn if auto updates enabled but no appId configured.\n // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !options.calledFromDeploy) {\n warnAboutMissingAppId({appType: 'app', output})\n }\n },\n compareDependencyVersions: (packages) => compareDependencyVersions(packages, workDir, {appId}),\n determineBasePath: () => determineBasePath(cliConfig, 'app', output),\n entry: resolveAppEntry(app),\n exposes,\n isWorkbenchApp: isWorkbench,\n minify: flags.minify,\n outDir,\n output,\n reactCompiler: cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n schemaExtraction: cliConfig?.schemaExtraction,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: flags.yes,\n vite: cliConfig.vite,\n // Shared with deploy: it passes the resolved application id (minted by the\n // API on a first deploy) to inline; a plain build has none, so it hashes the shape.\n workbenchAppId: workbench\n ? (options.applicationId ?? (await buildAppId(workbench)))\n : undefined,\n workDir,\n\n eventListener: preReleaseEventListenerFactory(output),\n })\n}\n"],"names":["compareDependencyVersions","buildApp","internalBuildApp","buildAppId","resolveAppEntry","resolveWorkbenchApp","resolveWorkbenchConfig","getAppId","warnAboutMissingAppId","determineBasePath","preReleaseEventListenerFactory","options","cliConfig","flags","outDir","output","workDir","app","undefined","workbench","workbenchConfig","exposes","views","webWorkers","config","appType","fields","isWorkbench","appId","appTitle","title","autoUpdatesEnabled","checkAppId","calledFromDeploy","packages","entry","isWorkbenchApp","minify","reactCompiler","schemaExtraction","sourceMap","Boolean","stats","unattendedMode","yes","vite","workbenchAppId","applicationId","eventListener"],"mappings":"AAAA,SACEA,yBAAyB,EACzBC,YAAYC,gBAAgB,QACvB,oCAAmC;AAC1C,SACEC,UAAU,EACVC,eAAe,EACfC,mBAAmB,EACnBC,sBAAsB,QACjB,8BAA6B;AAEpC,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SAAQC,8BAA8B,QAAO,4BAA2B;AAGxE;;;;CAIC,GACD,OAAO,eAAeT,SACpBU,OAAqB;IAErB,MAAM,EAACC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGL;IAEpD,MAAMM,MAAML,aAAa,SAASA,YAAYA,UAAUK,GAAG,GAAGC;IAC9D,+EAA+E;IAC/E,gFAAgF;IAChF,8EAA8E;IAC9E,MAAMC,YAAYd,oBAAoBO;IACtC,MAAMQ,kBAAkBd,uBAAuBM;IAC/C,MAAMS,UAAUF,YACZ;QAACG,OAAOH,UAAUG,KAAK;QAAEC,YAAYJ,UAAUI,UAAU;IAAA,IACzDH,kBACE;QAACI,QAAQ;YAACC,SAASL,gBAAgBK,OAAO;YAAEC,QAAQN,gBAAgBM,MAAM;QAAA;IAAC,IAC3ER;IACN,MAAMS,cAAc,CAAC,CAACR,aAAa,CAAC,CAACC;IAErC,MAAMQ,QAAQrB,SAASK;IAEvB,OAAOV,iBAAiB;QACtB0B;QACAC,UAAUZ,KAAKa;QACfC,oBAAoBpB,QAAQoB,kBAAkB;QAC9CC,YAAY;YACV,wDAAwD;YACxD,kEAAkE;YAClE,yDAAyD;YACzD,IAAI,CAACJ,SAAS,CAACjB,QAAQsB,gBAAgB,EAAE;gBACvCzB,sBAAsB;oBAACiB,SAAS;oBAAOV;gBAAM;YAC/C;QACF;QACAf,2BAA2B,CAACkC,WAAalC,0BAA0BkC,UAAUlB,SAAS;gBAACY;YAAK;QAC5FnB,mBAAmB,IAAMA,kBAAkBG,WAAW,OAAOG;QAC7DoB,
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/buildApp.ts"],"sourcesContent":["import {\n compareDependencyVersions,\n buildApp as internalBuildApp,\n} from '@sanity/cli-build/_internal/build'\nimport {\n buildAppId,\n resolveAppEntry,\n resolveWorkbenchApp,\n resolveWorkbenchConfig,\n} from '@sanity/workbench-cli/build'\n\nimport {getAppId} from '../../util/appId.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {preReleaseEventListenerFactory} from './eventListenerFactory.js'\nimport {type BuildOptions} from './types.js'\n\n/**\n * Build the Sanity app.\n *\n * @internal\n */\nexport async function buildApp(\n options: BuildOptions,\n): Promise<{mfManifest: Record<string, unknown> | undefined}> {\n const {cliConfig, flags, outDir, output, workDir} = options\n\n const app = cliConfig && 'app' in cliConfig ? cliConfig.app : undefined\n // `views`/`webWorkers` live on the branded `defineApplication` result, not the\n // legacy `app` config object — resolve the workbench capability to read them. A\n // config is not an app: it resolves separately and only expands its `fields`.\n const workbench = resolveWorkbenchApp(cliConfig)\n const workbenchConfig = resolveWorkbenchConfig(cliConfig)\n const exposes = workbench\n ? {views: workbench.views, webWorkers: workbench.webWorkers}\n : workbenchConfig\n ? {config: {appType: workbenchConfig.appType, fields: workbenchConfig.fields}}\n : undefined\n const isWorkbench = !!workbench || !!workbenchConfig\n\n const appId = getAppId(cliConfig)\n\n return internalBuildApp({\n appId,\n appTitle: app?.title,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n checkAppId: () => {\n // Warn if auto updates enabled but no appId configured.\n // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !options.calledFromDeploy) {\n warnAboutMissingAppId({appType: 'app', output})\n }\n },\n compareDependencyVersions: (packages) => compareDependencyVersions(packages, workDir, {appId}),\n determineBasePath: () => determineBasePath(cliConfig, 'app', output),\n documentComponent: cliConfig.unstable_documentComponent,\n entry: resolveAppEntry(app),\n exposes,\n isWorkbenchApp: isWorkbench,\n minify: flags.minify,\n outDir,\n output,\n reactCompiler: cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n schemaExtraction: cliConfig?.schemaExtraction,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: flags.yes,\n vite: cliConfig.vite,\n // Shared with deploy: it passes the resolved application id (minted by the\n // API on a first deploy) to inline; a plain build has none, so it hashes the shape.\n workbenchAppId: workbench\n ? (options.applicationId ?? (await buildAppId(workbench)))\n : undefined,\n workDir,\n\n eventListener: preReleaseEventListenerFactory(output),\n })\n}\n"],"names":["compareDependencyVersions","buildApp","internalBuildApp","buildAppId","resolveAppEntry","resolveWorkbenchApp","resolveWorkbenchConfig","getAppId","warnAboutMissingAppId","determineBasePath","preReleaseEventListenerFactory","options","cliConfig","flags","outDir","output","workDir","app","undefined","workbench","workbenchConfig","exposes","views","webWorkers","config","appType","fields","isWorkbench","appId","appTitle","title","autoUpdatesEnabled","checkAppId","calledFromDeploy","packages","documentComponent","unstable_documentComponent","entry","isWorkbenchApp","minify","reactCompiler","schemaExtraction","sourceMap","Boolean","stats","unattendedMode","yes","vite","workbenchAppId","applicationId","eventListener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AAW,OAAOG;QAC7DoB,mBAAmBvB,UAAUwB,0BAA0B;QACvDC,OAAOjC,gBAAgBa;QACvBI;QACAiB,gBAAgBX;QAChBY,QAAQ1B,MAAM0B,MAAM;QACpBzB;QACAC;QACAyB,eAAe5B,aAAa,mBAAmBA,YAAYA,UAAU4B,aAAa,GAAGtB;QACrFuB,kBAAkB7B,WAAW6B;QAC7BC,WAAWC,QAAQ9B,KAAK,CAAC,cAAc;QACvC+B,OAAO/B,MAAM+B,KAAK;QAClBC,gBAAgBhC,MAAMiC,GAAG;QACzBC,MAAMnC,UAAUmC,IAAI;QACpB,2EAA2E;QAC3E,oFAAoF;QACpFC,gBAAgB7B,YACXR,QAAQsC,aAAa,IAAK,MAAM9C,WAAWgB,aAC5CD;QACJF;QAEAkC,eAAexC,+BAA+BK;IAChD;AACF"}
|
|
@@ -45,6 +45,7 @@ import { checkDependenciesEventListenerFactory, preReleaseEventListenerFactory }
|
|
|
45
45
|
appId
|
|
46
46
|
}),
|
|
47
47
|
determineBasePath: ()=>determineBasePath(cliConfig, 'studio', output),
|
|
48
|
+
documentComponent: cliConfig.unstable_documentComponent,
|
|
48
49
|
exposes,
|
|
49
50
|
isApp: determineIsApp(cliConfig),
|
|
50
51
|
isWorkbenchApp: !!workbench,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/buildStudio.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {\n compareDependencyVersions,\n buildStudio as internalBuildStudio,\n} from '@sanity/cli-build/_internal/build'\nimport {exitCodes} from '@sanity/cli-core'\nimport {confirm, logSymbols, select, spinner} from '@sanity/cli-core/ux'\nimport {buildAppId, resolveWorkbenchApp} from '@sanity/workbench-cli/build'\n\nimport {getAppId} from '../../util/appId.js'\nimport {determineIsApp} from '../../util/determineIsApp.js'\nimport {getPackageManagerChoice} from '../../util/packageManager/packageManagerChoice.js'\nimport {upgradePackages} from '../../util/packageManager/upgradePackages.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {\n checkDependenciesEventListenerFactory,\n preReleaseEventListenerFactory,\n} from './eventListenerFactory.js'\nimport {type BuildOptions} from './types.js'\n\n/**\n * Build the Sanity Studio.\n *\n * @internal\n */\nexport async function buildStudio(\n options: BuildOptions,\n): Promise<{mfManifest: Record<string, unknown> | undefined}> {\n const {calledFromDeploy, cliConfig, flags, outDir, output, workDir} = options\n\n // `views`/`webWorkers` live on the branded `defineApplication` result — resolve\n // the workbench capability so it's gated on the brand, like the app build.\n const workbench = resolveWorkbenchApp(cliConfig)\n const exposes = workbench ? {views: workbench.views, webWorkers: workbench.webWorkers} : undefined\n\n const appId = getAppId(cliConfig)\n\n let cleanOutputDirSpinner: ReturnType<typeof spinner> | undefined\n let buildSpinner: ReturnType<typeof spinner> | undefined\n\n return internalBuildStudio({\n appId,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n checkAppId: () => {\n // Warn if auto updates enabled but no appId configured.\n // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !calledFromDeploy) {\n warnAboutMissingAppId({appType: 'studio', output, projectId: cliConfig?.api?.projectId})\n }\n },\n compareDependencyVersions: (packages) => compareDependencyVersions(packages, workDir, {appId}),\n determineBasePath: () => determineBasePath(cliConfig, 'studio', output),\n exposes,\n isApp: determineIsApp(cliConfig),\n isWorkbenchApp: !!workbench,\n minify: Boolean(flags.minify),\n outDir,\n output,\n reactCompiler: cliConfig.reactCompiler,\n schemaExtraction: cliConfig.schemaExtraction,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: Boolean(flags.yes),\n vite: cliConfig.vite,\n // Shared with deploy: it passes the resolved application id (minted by the\n // API on a first deploy) to inline; a plain build has none, so it hashes the shape.\n workbenchAppId: workbench\n ? (options.applicationId ?? (await buildAppId(workbench)))\n : undefined,\n workDir,\n\n eventListener: {\n ...preReleaseEventListenerFactory(output),\n\n ...checkDependenciesEventListenerFactory(output),\n\n onBuildEnd({message}) {\n if (buildSpinner) {\n buildSpinner.text = message\n buildSpinner.succeed()\n }\n },\n onBuildFail({message}) {\n if (buildSpinner) {\n buildSpinner.fail()\n }\n\n output.error(message, {exit: exitCodes.RUNTIME_ERROR})\n },\n onBuildStart({message}) {\n if (!buildSpinner) {\n buildSpinner = spinner(message).start()\n }\n },\n onCleanOutputDirEnd({message}) {\n if (cleanOutputDirSpinner) {\n cleanOutputDirSpinner.text = message\n cleanOutputDirSpinner.succeed()\n }\n },\n onCleanOutputDirStart({message}) {\n if (!cleanOutputDirSpinner) {\n cleanOutputDirSpinner = spinner(message).start()\n }\n },\n async onInteractiveNonDefaultOutputDir({message}: {message: string}) {\n const shouldClean = await confirm({\n default: true,\n message,\n })\n return {shouldClean}\n },\n async onVersionMismatchInInteractiveAutoUpdate({mismatched, versionMismatchWarning}) {\n const choice = await select({\n choices: [\n {\n name: `Upgrade local versions (recommended). You will need to run the build command again`,\n value: 'upgrade',\n },\n {\n name: `Upgrade and proceed with build`,\n value: 'upgrade-and-proceed',\n },\n {\n name: `Continue anyway`,\n value: 'continue',\n },\n {name: 'Cancel', value: 'cancel'},\n ],\n default: 'upgrade',\n message: styleText(\n 'yellow',\n `${logSymbols.warning} ${versionMismatchWarning}\\n\\nDo you want to upgrade local versions before deploying?`,\n ),\n })\n\n if (choice === 'cancel') {\n output.error('Declined to continue with build', {exit: exitCodes.RUNTIME_ERROR})\n return {stopBuild: true}\n }\n\n if (choice === 'upgrade' || choice === 'upgrade-and-proceed') {\n await upgradePackages(\n {\n packageManager: (await getPackageManagerChoice(workDir, {interactive: false})).chosen,\n packages: mismatched.map((res) => [res.pkg, res.remote]),\n },\n {output, workDir},\n )\n\n return {stopBuild: choice === 'upgrade'}\n }\n\n return {stopBuild: false}\n },\n onVersionMismatchInNonInteractiveAutoUpdate({versionMismatchWarning}) {\n output.warn(versionMismatchWarning)\n },\n },\n })\n}\n"],"names":["styleText","compareDependencyVersions","buildStudio","internalBuildStudio","exitCodes","confirm","logSymbols","select","spinner","buildAppId","resolveWorkbenchApp","getAppId","determineIsApp","getPackageManagerChoice","upgradePackages","warnAboutMissingAppId","determineBasePath","checkDependenciesEventListenerFactory","preReleaseEventListenerFactory","options","calledFromDeploy","cliConfig","flags","outDir","output","workDir","workbench","exposes","views","webWorkers","undefined","appId","cleanOutputDirSpinner","buildSpinner","autoUpdatesEnabled","checkAppId","appType","projectId","api","packages","isApp","isWorkbenchApp","minify","Boolean","reactCompiler","schemaExtraction","sourceMap","stats","unattendedMode","yes","vite","workbenchAppId","applicationId","eventListener","onBuildEnd","message","text","succeed","onBuildFail","fail","error","exit","RUNTIME_ERROR","onBuildStart","start","onCleanOutputDirEnd","onCleanOutputDirStart","onInteractiveNonDefaultOutputDir","shouldClean","default","onVersionMismatchInInteractiveAutoUpdate","mismatched","versionMismatchWarning","choice","choices","name","value","warning","stopBuild","packageManager","interactive","chosen","map","res","pkg","remote","onVersionMismatchInNonInteractiveAutoUpdate","warn"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SACEC,yBAAyB,EACzBC,eAAeC,mBAAmB,QAC7B,oCAAmC;AAC1C,SAAQC,SAAS,QAAO,mBAAkB;AAC1C,SAAQC,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,QAAO,sBAAqB;AACxE,SAAQC,UAAU,EAAEC,mBAAmB,QAAO,8BAA6B;AAE3E,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,cAAc,QAAO,+BAA8B;AAC3D,SAAQC,uBAAuB,QAAO,oDAAmD;AACzF,SAAQC,eAAe,QAAO,+CAA8C;AAC5E,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SACEC,qCAAqC,EACrCC,8BAA8B,QACzB,4BAA2B;AAGlC;;;;CAIC,GACD,OAAO,eAAehB,YACpBiB,OAAqB;IAErB,MAAM,EAACC,gB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Aa;oBAAA;oBAC9E,OAAO;wBAACgB,WAAW;oBAAI;gBACzB;gBAEA,IAAIL,WAAW,aAAaA,WAAW,uBAAuB;oBAC5D,MAAM3D,gBACJ;wBACEiE,gBAAgB,AAAC,CAAA,MAAMlE,wBAAwBY,SAAS;4BAACuD,aAAa;wBAAK,EAAC,EAAGC,MAAM;wBACrF1C,UAAUgC,WAAWW,GAAG,CAAC,CAACC,MAAQ;gCAACA,IAAIC,GAAG;gCAAED,IAAIE,MAAM;6BAAC;oBACzD,GACA;wBAAC7D;wBAAQC;oBAAO;oBAGlB,OAAO;wBAACqD,WAAWL,WAAW;oBAAS;gBACzC;gBAEA,OAAO;oBAACK,WAAW;gBAAK;YAC1B;YACAQ,6CAA4C,EAACd,sBAAsB,EAAC;gBAClEhD,OAAO+D,IAAI,CAACf;YACd;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/buildStudio.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {\n compareDependencyVersions,\n buildStudio as internalBuildStudio,\n} from '@sanity/cli-build/_internal/build'\nimport {exitCodes} from '@sanity/cli-core'\nimport {confirm, logSymbols, select, spinner} from '@sanity/cli-core/ux'\nimport {buildAppId, resolveWorkbenchApp} from '@sanity/workbench-cli/build'\n\nimport {getAppId} from '../../util/appId.js'\nimport {determineIsApp} from '../../util/determineIsApp.js'\nimport {getPackageManagerChoice} from '../../util/packageManager/packageManagerChoice.js'\nimport {upgradePackages} from '../../util/packageManager/upgradePackages.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {\n checkDependenciesEventListenerFactory,\n preReleaseEventListenerFactory,\n} from './eventListenerFactory.js'\nimport {type BuildOptions} from './types.js'\n\n/**\n * Build the Sanity Studio.\n *\n * @internal\n */\nexport async function buildStudio(\n options: BuildOptions,\n): Promise<{mfManifest: Record<string, unknown> | undefined}> {\n const {calledFromDeploy, cliConfig, flags, outDir, output, workDir} = options\n\n // `views`/`webWorkers` live on the branded `defineApplication` result — resolve\n // the workbench capability so it's gated on the brand, like the app build.\n const workbench = resolveWorkbenchApp(cliConfig)\n const exposes = workbench ? {views: workbench.views, webWorkers: workbench.webWorkers} : undefined\n\n const appId = getAppId(cliConfig)\n\n let cleanOutputDirSpinner: ReturnType<typeof spinner> | undefined\n let buildSpinner: ReturnType<typeof spinner> | undefined\n\n return internalBuildStudio({\n appId,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n checkAppId: () => {\n // Warn if auto updates enabled but no appId configured.\n // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !calledFromDeploy) {\n warnAboutMissingAppId({appType: 'studio', output, projectId: cliConfig?.api?.projectId})\n }\n },\n compareDependencyVersions: (packages) => compareDependencyVersions(packages, workDir, {appId}),\n determineBasePath: () => determineBasePath(cliConfig, 'studio', output),\n documentComponent: cliConfig.unstable_documentComponent,\n exposes,\n isApp: determineIsApp(cliConfig),\n isWorkbenchApp: !!workbench,\n minify: Boolean(flags.minify),\n outDir,\n output,\n reactCompiler: cliConfig.reactCompiler,\n schemaExtraction: cliConfig.schemaExtraction,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: Boolean(flags.yes),\n vite: cliConfig.vite,\n // Shared with deploy: it passes the resolved application id (minted by the\n // API on a first deploy) to inline; a plain build has none, so it hashes the shape.\n workbenchAppId: workbench\n ? (options.applicationId ?? (await buildAppId(workbench)))\n : undefined,\n workDir,\n\n eventListener: {\n ...preReleaseEventListenerFactory(output),\n\n ...checkDependenciesEventListenerFactory(output),\n\n onBuildEnd({message}) {\n if (buildSpinner) {\n buildSpinner.text = message\n buildSpinner.succeed()\n }\n },\n onBuildFail({message}) {\n if (buildSpinner) {\n buildSpinner.fail()\n }\n\n output.error(message, {exit: exitCodes.RUNTIME_ERROR})\n },\n onBuildStart({message}) {\n if (!buildSpinner) {\n buildSpinner = spinner(message).start()\n }\n },\n onCleanOutputDirEnd({message}) {\n if (cleanOutputDirSpinner) {\n cleanOutputDirSpinner.text = message\n cleanOutputDirSpinner.succeed()\n }\n },\n onCleanOutputDirStart({message}) {\n if (!cleanOutputDirSpinner) {\n cleanOutputDirSpinner = spinner(message).start()\n }\n },\n async onInteractiveNonDefaultOutputDir({message}: {message: string}) {\n const shouldClean = await confirm({\n default: true,\n message,\n })\n return {shouldClean}\n },\n async onVersionMismatchInInteractiveAutoUpdate({mismatched, versionMismatchWarning}) {\n const choice = await select({\n choices: [\n {\n name: `Upgrade local versions (recommended). You will need to run the build command again`,\n value: 'upgrade',\n },\n {\n name: `Upgrade and proceed with build`,\n value: 'upgrade-and-proceed',\n },\n {\n name: `Continue anyway`,\n value: 'continue',\n },\n {name: 'Cancel', value: 'cancel'},\n ],\n default: 'upgrade',\n message: styleText(\n 'yellow',\n `${logSymbols.warning} ${versionMismatchWarning}\\n\\nDo you want to upgrade local versions before deploying?`,\n ),\n })\n\n if (choice === 'cancel') {\n output.error('Declined to continue with build', {exit: exitCodes.RUNTIME_ERROR})\n return {stopBuild: true}\n }\n\n if (choice === 'upgrade' || choice === 'upgrade-and-proceed') {\n await upgradePackages(\n {\n packageManager: (await getPackageManagerChoice(workDir, {interactive: false})).chosen,\n packages: mismatched.map((res) => [res.pkg, res.remote]),\n },\n {output, workDir},\n )\n\n return {stopBuild: choice === 'upgrade'}\n }\n\n return {stopBuild: false}\n },\n onVersionMismatchInNonInteractiveAutoUpdate({versionMismatchWarning}) {\n output.warn(versionMismatchWarning)\n },\n },\n })\n}\n"],"names":["styleText","compareDependencyVersions","buildStudio","internalBuildStudio","exitCodes","confirm","logSymbols","select","spinner","buildAppId","resolveWorkbenchApp","getAppId","determineIsApp","getPackageManagerChoice","upgradePackages","warnAboutMissingAppId","determineBasePath","checkDependenciesEventListenerFactory","preReleaseEventListenerFactory","options","calledFromDeploy","cliConfig","flags","outDir","output","workDir","workbench","exposes","views","webWorkers","undefined","appId","cleanOutputDirSpinner","buildSpinner","autoUpdatesEnabled","checkAppId","appType","projectId","api","packages","documentComponent","unstable_documentComponent","isApp","isWorkbenchApp","minify","Boolean","reactCompiler","schemaExtraction","sourceMap","stats","unattendedMode","yes","vite","workbenchAppId","applicationId","eventListener","onBuildEnd","message","text","succeed","onBuildFail","fail","error","exit","RUNTIME_ERROR","onBuildStart","start","onCleanOutputDirEnd","onCleanOutputDirStart","onInteractiveNonDefaultOutputDir","shouldClean","default","onVersionMismatchInInteractiveAutoUpdate","mismatched","versionMismatchWarning","choice","choices","name","value","warning","stopBuild","packageManager","interactive","chosen","map","res","pkg","remote","onVersionMismatchInNonInteractiveAutoUpdate","warn"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SACEC,yBAAyB,EACzBC,eAAeC,mBAAmB,QAC7B,oCAAmC;AAC1C,SAAQC,SAAS,QAAO,mBAAkB;AAC1C,SAAQC,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,QAAO,sBAAqB;AACxE,SAAQC,UAAU,EAAEC,mBAAmB,QAAO,8BAA6B;AAE3E,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,cAAc,QAAO,+BAA8B;AAC3D,SAAQC,uBAAuB,QAAO,oDAAmD;AACzF,SAAQC,eAAe,QAAO,+CAA8C;AAC5E,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SACEC,qCAAqC,EACrCC,8BAA8B,QACzB,4BAA2B;AAGlC;;;;CAIC,GACD,OAAO,eAAehB,YACpBiB,OAAqB;IAErB,MAAM,EAACC,gBAAgB,EAAEC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGN;IAEtE,gFAAgF;IAChF,2EAA2E;IAC3E,MAAMO,YAAYhB,oBAAoBW;IACtC,MAAMM,UAAUD,YAAY;QAACE,OAAOF,UAAUE,KAAK;QAAEC,YAAYH,UAAUG,UAAU;IA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K,EAAC,EAAGC,MAAM;wBACrF5C,UAAUkC,WAAWW,GAAG,CAAC,CAACC,MAAQ;gCAACA,IAAIC,GAAG;gCAAED,IAAIE,MAAM;6BAAC;oBACzD,GACA;wBAAC/D;wBAAQC;oBAAO;oBAGlB,OAAO;wBAACuD,WAAWL,WAAW;oBAAS;gBACzC;gBAEA,OAAO;oBAACK,WAAW;gBAAK;YAC1B;YACAQ,6CAA4C,EAACd,sBAAsB,EAAC;gBAClElD,OAAOiE,IAAI,CAACf;YACd;QACF;IACF;AACF"}
|
|
@@ -5,6 +5,7 @@ import { input, spinner } from '@sanity/cli-core/ux';
|
|
|
5
5
|
import { createUserApplication as createUserApplicationRequest } from '../../services/userApplications.js';
|
|
6
6
|
import { NO_ORGANIZATION_ID } from '../../util/errorMessages.js';
|
|
7
7
|
import { deployDebug } from './deployDebug.js';
|
|
8
|
+
import { describeServiceUnavailable } from './serviceUnavailable.js';
|
|
8
9
|
import { normalizeUrl, validateUrl } from './urlUtils.js';
|
|
9
10
|
const LETTERS = 'abcdefghijklmnopqrstuvwxyz';
|
|
10
11
|
const ALPHANUMERIC = `${LETTERS}0123456789`;
|
|
@@ -73,7 +74,9 @@ export async function createStudioUserApplication(options) {
|
|
|
73
74
|
}
|
|
74
75
|
deployDebug('Error creating user application', e);
|
|
75
76
|
// otherwise, it's a fatal error
|
|
76
|
-
|
|
77
|
+
const failure = isExternal ? 'Error registering external studio' : 'Error creating studio hostname';
|
|
78
|
+
const unavailable = describeServiceUnavailable(e);
|
|
79
|
+
throw new CLIError(unavailable ? `${failure}: ${unavailable}` : failure, {
|
|
77
80
|
exit: exitCodes.RUNTIME_ERROR
|
|
78
81
|
});
|
|
79
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/createUserApplication.ts"],"sourcesContent":["import {randomInt} from 'node:crypto'\n\nimport {CLIError} from '@oclif/core/errors'\nimport {type AppVisibility, exitCodes} from '@sanity/cli-core'\nimport {input, spinner} from '@sanity/cli-core/ux'\n\nimport {\n createUserApplication as createUserApplicationRequest,\n type UserApplication,\n type UserApplicationResolved,\n} from '../../services/userApplications.js'\nimport {NO_ORGANIZATION_ID} from '../../util/errorMessages.js'\nimport {deployDebug} from './deployDebug.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\nconst LETTERS = 'abcdefghijklmnopqrstuvwxyz'\nconst ALPHANUMERIC = `${LETTERS}0123456789`\n\nconst randomString = (alphabet: string, length: number) =>\n Array.from({length}, () => alphabet[randomInt(alphabet.length)]).join('')\n\n// appHosts have some restrictions (no uppercase, must start with a letter)\nexport function generateAppSlug() {\n return randomString(LETTERS, 1) + randomString(ALPHANUMERIC, 11)\n}\n\n// TODO: replace with `Promise.withResolvers()` once it lands in node 22\nfunction promiseWithResolvers<T>() {\n let resolve!: (t: T) => void\n let reject!: (err: unknown) => void\n const promise = new Promise<T>((res, rej) => {\n resolve = res\n reject = rej\n })\n return {promise, reject, resolve}\n}\n\ninterface CreateStudioUserApplicationOptions {\n projectId: string\n\n title?: string\n urlType?: 'external' | 'internal'\n}\n\nexport async function createStudioUserApplication(options: CreateStudioUserApplicationOptions) {\n const {projectId, title, urlType = 'internal'} = options\n const {promise, resolve} = promiseWithResolvers<UserApplication>()\n\n const isExternal = urlType === 'external'\n\n await input({\n message: isExternal ? 'Studio URL (https://...):' : 'Studio hostname (<value>.sanity.studio):',\n // if a string is returned here, it is relayed to the user and prompt allows\n // the user to try again until this function returns true\n validate: async (inp: string) => {\n let appHost: string\n\n if (isExternal) {\n const normalized = normalizeUrl(inp)\n const validation = validateUrl(normalized)\n if (validation !== true) {\n return validation\n }\n appHost = normalized\n } else {\n appHost = inp.replace(/\\.sanity\\.studio$/i, '')\n }\n\n try {\n const response = await createUserApplicationRequest({\n appType: 'studio',\n body: {appHost, title, type: 'studio', urlType},\n projectId,\n })\n resolve(response)\n return true\n } catch (e) {\n // if the name is taken, it should return a 409 so we relay to the user\n if ([402, 409].includes(e?.statusCode)) {\n return e?.response?.body?.message || 'Bad request' // just in case\n }\n\n deployDebug('Error creating user application', e)\n // otherwise, it's a fatal error\n throw new CLIError(
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/createUserApplication.ts"],"sourcesContent":["import {randomInt} from 'node:crypto'\n\nimport {CLIError} from '@oclif/core/errors'\nimport {type AppVisibility, exitCodes} from '@sanity/cli-core'\nimport {input, spinner} from '@sanity/cli-core/ux'\n\nimport {\n createUserApplication as createUserApplicationRequest,\n type UserApplication,\n type UserApplicationResolved,\n} from '../../services/userApplications.js'\nimport {NO_ORGANIZATION_ID} from '../../util/errorMessages.js'\nimport {deployDebug} from './deployDebug.js'\nimport {describeServiceUnavailable} from './serviceUnavailable.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\nconst LETTERS = 'abcdefghijklmnopqrstuvwxyz'\nconst ALPHANUMERIC = `${LETTERS}0123456789`\n\nconst randomString = (alphabet: string, length: number) =>\n Array.from({length}, () => alphabet[randomInt(alphabet.length)]).join('')\n\n// appHosts have some restrictions (no uppercase, must start with a letter)\nexport function generateAppSlug() {\n return randomString(LETTERS, 1) + randomString(ALPHANUMERIC, 11)\n}\n\n// TODO: replace with `Promise.withResolvers()` once it lands in node 22\nfunction promiseWithResolvers<T>() {\n let resolve!: (t: T) => void\n let reject!: (err: unknown) => void\n const promise = new Promise<T>((res, rej) => {\n resolve = res\n reject = rej\n })\n return {promise, reject, resolve}\n}\n\ninterface CreateStudioUserApplicationOptions {\n projectId: string\n\n title?: string\n urlType?: 'external' | 'internal'\n}\n\nexport async function createStudioUserApplication(options: CreateStudioUserApplicationOptions) {\n const {projectId, title, urlType = 'internal'} = options\n const {promise, resolve} = promiseWithResolvers<UserApplication>()\n\n const isExternal = urlType === 'external'\n\n await input({\n message: isExternal ? 'Studio URL (https://...):' : 'Studio hostname (<value>.sanity.studio):',\n // if a string is returned here, it is relayed to the user and prompt allows\n // the user to try again until this function returns true\n validate: async (inp: string) => {\n let appHost: string\n\n if (isExternal) {\n const normalized = normalizeUrl(inp)\n const validation = validateUrl(normalized)\n if (validation !== true) {\n return validation\n }\n appHost = normalized\n } else {\n appHost = inp.replace(/\\.sanity\\.studio$/i, '')\n }\n\n try {\n const response = await createUserApplicationRequest({\n appType: 'studio',\n body: {appHost, title, type: 'studio', urlType},\n projectId,\n })\n resolve(response)\n return true\n } catch (e) {\n // if the name is taken, it should return a 409 so we relay to the user\n if ([402, 409].includes(e?.statusCode)) {\n return e?.response?.body?.message || 'Bad request' // just in case\n }\n\n deployDebug('Error creating user application', e)\n // otherwise, it's a fatal error\n const failure = isExternal\n ? 'Error registering external studio'\n : 'Error creating studio hostname'\n const unavailable = describeServiceUnavailable(e)\n throw new CLIError(unavailable ? `${failure}: ${unavailable}` : failure, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n },\n })\n\n return await promise\n}\n\nexport async function createUserApplication(\n organizationId?: string,\n title?: string,\n visibility?: AppVisibility,\n): Promise<UserApplicationResolved> {\n if (!organizationId) {\n throw new Error(NO_ORGANIZATION_ID)\n }\n\n const resolvedTitle =\n title ??\n (await input({\n message: 'Enter a title for your application:',\n validate: (value: string) => value.length > 0 || 'Title is required',\n }))\n\n return tryCreateApp(resolvedTitle, organizationId, visibility)\n}\n\nconst tryCreateApp = async (title: string, organizationId: string, visibility?: AppVisibility) => {\n // we will likely prepend this with an org ID or other parameter in the future\n const appHost = generateAppSlug()\n\n const spin = spinner('Creating application').start()\n\n try {\n const response = await createUserApplicationRequest({\n appType: 'coreApp',\n body: {\n appHost,\n title,\n type: 'coreApp',\n urlType: 'internal',\n ...(visibility ? {dashboardStatus: visibility} : {}),\n },\n organizationId,\n })\n\n spin.succeed()\n return response\n } catch (e) {\n // if the name is taken, generate a new one and try again\n if ([402, 409].includes(e?.statusCode)) {\n deployDebug('App host taken, retrying with new host')\n return tryCreateApp(title, organizationId, visibility)\n }\n\n spin.fail()\n\n deployDebug('Error creating core application', e)\n throw e\n }\n}\n"],"names":["randomInt","CLIError","exitCodes","input","spinner","createUserApplication","createUserApplicationRequest","NO_ORGANIZATION_ID","deployDebug","describeServiceUnavailable","normalizeUrl","validateUrl","LETTERS","ALPHANUMERIC","randomString","alphabet","length","Array","from","join","generateAppSlug","promiseWithResolvers","resolve","reject","promise","Promise","res","rej","createStudioUserApplication","options","projectId","title","urlType","isExternal","message","validate","inp","appHost","normalized","validation","replace","response","appType","body","type","e","includes","statusCode","failure","unavailable","exit","RUNTIME_ERROR","organizationId","visibility","Error","resolvedTitle","value","tryCreateApp","spin","start","dashboardStatus","succeed","fail"],"mappings":"AAAA,SAAQA,SAAS,QAAO,cAAa;AAErC,SAAQC,QAAQ,QAAO,qBAAoB;AAC3C,SAA4BC,SAAS,QAAO,mBAAkB;AAC9D,SAAQC,KAAK,EAAEC,OAAO,QAAO,sBAAqB;AAElD,SACEC,yBAAyBC,4BAA4B,QAGhD,qCAAoC;AAC3C,SAAQC,kBAAkB,QAAO,8BAA6B;AAC9D,SAAQC,WAAW,QAAO,mBAAkB;AAC5C,SAAQC,0BAA0B,QAAO,0BAAyB;AAClE,SAAQC,YAAY,EAAEC,WAAW,QAAO,gBAAe;AAEvD,MAAMC,UAAU;AAChB,MAAMC,eAAe,GAAGD,QAAQ,UAAU,CAAC;AAE3C,MAAME,eAAe,CAACC,UAAkBC,SACtCC,MAAMC,IAAI,CAAC;QAACF;IAAM,GAAG,IAAMD,QAAQ,CAACf,UAAUe,SAASC,MAAM,EAAE,EAAEG,IAAI,CAAC;AAExE,2EAA2E;AAC3E,OAAO,SAASC;IACd,OAAON,aAAaF,SAAS,KAAKE,aAAaD,cAAc;AAC/D;AAEA,wEAAwE;AACxE,SAASQ;IACP,IAAIC;IACJ,IAAIC;IACJ,MAAMC,UAAU,IAAIC,QAAW,CAACC,KAAKC;QACnCL,UAAUI;QACVH,SAASI;IACX;IACA,OAAO;QAACH;QAASD;QAAQD;IAAO;AAClC;AASA,OAAO,eAAeM,4BAA4BC,OAA2C;IAC3F,MAAM,EAACC,SA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AAS;QACTC,UAAU,CAACqB,QAAkBA,MAAMxC,MAAM,GAAG,KAAK;IACnD;IAEF,OAAOyC,aAAaF,eAAeH,gBAAgBC;AACrD;AAEA,MAAMI,eAAe,OAAO1B,OAAeqB,gBAAwBC;IACjE,8EAA8E;IAC9E,MAAMhB,UAAUjB;IAEhB,MAAMsC,OAAOtD,QAAQ,wBAAwBuD,KAAK;IAElD,IAAI;QACF,MAAMlB,WAAW,MAAMnC,6BAA6B;YAClDoC,SAAS;YACTC,MAAM;gBACJN;gBACAN;gBACAa,MAAM;gBACNZ,SAAS;gBACT,GAAIqB,aAAa;oBAACO,iBAAiBP;gBAAU,IAAI,CAAC,CAAC;YACrD;YACAD;QACF;QAEAM,KAAKG,OAAO;QACZ,OAAOpB;IACT,EAAE,OAAOI,GAAG;QACV,yDAAyD;QACzD,IAAI;YAAC;YAAK;SAAI,CAACC,QAAQ,CAACD,GAAGE,aAAa;YACtCvC,YAAY;YACZ,OAAOiD,aAAa1B,OAAOqB,gBAAgBC;QAC7C;QAEAK,KAAKI,IAAI;QAETtD,YAAY,mCAAmCqC;QAC/C,MAAMA;IACR;AACF"}
|
|
@@ -10,6 +10,7 @@ import { getAutoUpdateIssueMessage, getAutoUpdateMigrationHint, resolveAutoUpdat
|
|
|
10
10
|
import { checkDir } from './checkDir.js';
|
|
11
11
|
import { deployDebug } from './deployDebug.js';
|
|
12
12
|
import { resolveAppDeployTarget, resolveStudioDeployTarget, resolveWorkbenchApp, resolveWorkbenchStudio } from './resolveDeployTarget.js';
|
|
13
|
+
import { getDeployErrorMessage } from './serviceUnavailable.js';
|
|
13
14
|
import { normalizeUrl, validateUrl } from './urlUtils.js';
|
|
14
15
|
export async function checkPackageVersion(reporter, { moduleName, workDir }) {
|
|
15
16
|
const version = await getLocalPackageVersion(moduleName, workDir);
|
|
@@ -250,7 +251,7 @@ export async function checkBuild(reporter, { build, skipReason, successMessage }
|
|
|
250
251
|
};
|
|
251
252
|
}
|
|
252
253
|
export function describeAppTargetError(err, organizationId) {
|
|
253
|
-
return err?.statusCode === 403 ? `You don’t have permission to view applications for the configured organization ID ("${organizationId}"). Verify the organization ID, or ask your organization’s admin for access.` : `Failed to resolve deploy target: ${
|
|
254
|
+
return err?.statusCode === 403 ? `You don’t have permission to view applications for the configured organization ID ("${organizationId}"). Verify the organization ID, or ask your organization’s admin for access.` : `Failed to resolve deploy target: ${getDeployErrorMessage(err)}`;
|
|
254
255
|
}
|
|
255
256
|
/**
|
|
256
257
|
* Reports the app deploy target as a check and returns the resolved target;
|
|
@@ -395,7 +396,7 @@ export function describeAppTargetError(err, organizationId) {
|
|
|
395
396
|
const isExternal = options.isWorkbenchApp ? false : options.isExternal;
|
|
396
397
|
return runStep(reporter, {
|
|
397
398
|
debug: deployDebug,
|
|
398
|
-
formatError: (err)=>`Failed to resolve deploy target: ${
|
|
399
|
+
formatError: (err)=>`Failed to resolve deploy target: ${getDeployErrorMessage(err)}`,
|
|
399
400
|
name: 'target',
|
|
400
401
|
work: async ()=>{
|
|
401
402
|
const check = describeStudioTarget(await resolve, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/deployChecks.ts"],"sourcesContent":["import {type CliConfig, exitCodes, getLocalPackageVersion} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {getCoreAppUrl} from '@sanity/cli-core/util'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {readBuiltManifest} from '@sanity/workbench-cli/build'\n\nimport {resolveAppIdIssue} from '../../util/appId.js'\nimport {type Check, type CheckReporter, runStep} from '../../util/checks.js'\nimport {APP_ID_NOT_FOUND_IN_ORGANIZATION} from '../../util/errorMessages.js'\nimport {\n getAutoUpdateIssueMessage,\n getAutoUpdateMigrationHint,\n resolveAutoUpdates,\n} from '../build/shouldAutoUpdate.js'\nimport {checkDir} from './checkDir.js'\nimport {deployDebug} from './deployDebug.js'\nimport {\n type AppDeployTargetResolution,\n type DeployTargetApp,\n resolveAppDeployTarget,\n resolveStudioDeployTarget,\n resolveWorkbenchApp,\n resolveWorkbenchStudio,\n type StudioDeployTargetResolution,\n} from './resolveDeployTarget.js'\nimport {type DeployFlags} from './types.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\n/**\n * Where a deploy resolves to, computed once from the deploy-target verdict. The\n * dry-run report and its JSON both read this, so the human and machine outputs\n * can't drift.\n */\nexport interface DeployTarget {\n /** Whether the deploy creates a new application/studio or updates an existing one. */\n action: 'create' | 'update'\n /** `null` until the deploy creates the application. */\n id: string | null\n title: string | null\n type: 'coreApp' | 'studio'\n url: string | null\n\n /** Absent on a plain app, whose backend reports `appHost` instead. */\n slug?: string\n}\n\nexport interface DeployCheck extends Check {\n /** The backend's record, verbatim; `--json` reports it once the deploy succeeds. */\n application?: object\n /** Set on the deploy-target check with the resolved target both reporters read. */\n target?: DeployTarget\n}\n\nexport type DeployCheckReporter = CheckReporter<DeployCheck>\n\nexport async function checkPackageVersion(\n reporter: DeployCheckReporter,\n {moduleName, workDir}: {moduleName: string; workDir: string},\n): Promise<string | null> {\n const version = await getLocalPackageVersion(moduleName, workDir)\n reporter.report(\n version\n ? {message: `Using ${moduleName} ${version}`, status: 'pass'}\n : {\n message: `Failed to find installed ${moduleName} version`,\n solution: `Install ${moduleName} in this project`,\n status: 'fail',\n },\n )\n return version\n}\n\nexport function checkAutoUpdates(\n reporter: DeployCheckReporter,\n {cliConfig, flags}: {cliConfig: CliConfig; flags: DeployFlags},\n): boolean {\n const {enabled, issue} = resolveAutoUpdates({cliConfig, flags})\n\n if (issue) {\n reporter.report({\n message: getAutoUpdateIssueMessage(issue),\n // A config conflict makes a real deploy refuse to run; deprecations only warn\n status: issue.type === 'conflicting-config' ? 'fail' : 'warn',\n })\n\n // The deprecated top-level config also gets the styled migration edit, the\n // same second warning the build/dev path prints through shouldAutoUpdate.\n if (issue.type === 'deprecated-config') {\n reporter.report({\n message: getAutoUpdateMigrationHint(cliConfig.autoUpdates),\n status: 'warn',\n })\n }\n }\n\n return enabled\n}\n\n/**\n * The dry-run form of the `app.id` config check a real deploy runs in\n * `findUserApplication`: a conflict fails (both `app.id` and `deployment.appId`\n * set), the deprecated config alone warns.\n */\nexport function checkAppId(\n reporter: DeployCheckReporter,\n {cliConfig}: {cliConfig: CliConfig},\n): void {\n const issue = resolveAppIdIssue(cliConfig)\n if (issue === 'conflicting-config') {\n reporter.report({\n message: 'Both `app.id` (deprecated) and `deployment.appId` are set',\n solution: 'Remove `app.id` from sanity.cli.ts',\n status: 'fail',\n })\n } else if (issue === 'deprecated-config') {\n reporter.report({\n message: 'The `app.id` config is deprecated',\n solution: 'Move it to `deployment.appId` in sanity.cli.ts',\n status: 'warn',\n })\n }\n}\n\n/**\n * The origin a federated studio deployed with --external is registered\n * at. Only a first deploy registers one; a redeploy keeps the URL it has.\n */\nexport function checkExternalUrl(\n reporter: DeployCheckReporter,\n {appId, url}: {appId: string | undefined; url: string | undefined},\n): string | undefined {\n if (appId) return undefined\n\n if (!url) {\n reporter.report({\n exitCode: exitCodes.USAGE_ERROR,\n message: 'A first external deploy needs the URL your host serves the build from',\n solution: 'Pass it with --url, for example --url https://studio.example.com',\n status: 'fail',\n })\n return undefined\n }\n\n const normalized = normalizeUrl(url)\n const validation = validateUrl(normalized)\n if (validation !== true) {\n reporter.report({\n exitCode: exitCodes.USAGE_ERROR,\n message: validation,\n solution:\n 'Pass --url with an http or https URL, for example --url https://studio.example.com',\n status: 'fail',\n })\n return undefined\n }\n\n // The Dashboard loads the remote from the origin root, so a path would never be fetched.\n const {hash, origin, pathname, search} = new URL(normalized)\n if (pathname !== '/' || search || hash) {\n reporter.report({\n exitCode: exitCodes.USAGE_ERROR,\n message: '--url must be an origin with no path, query or hash',\n solution:\n 'Pass the origin your host serves the build from, for example --url https://studio.example.com',\n status: 'fail',\n })\n return undefined\n }\n\n reporter.report({message: `Registers at ${origin}`, status: 'pass'})\n return origin\n}\n\nexport async function checkBuild<T>(\n reporter: DeployCheckReporter,\n {\n build,\n skipReason,\n successMessage,\n }: {build: () => Promise<T>; skipReason: string | undefined; successMessage: string},\n): Promise<T | undefined> {\n if (skipReason) {\n reporter.report({message: skipReason, status: 'skip'})\n return undefined\n }\n\n const result = await runStep(reporter, {\n debug: deployDebug,\n formatError: (err) => `Build failed: ${getErrorMessage(err)}`,\n name: 'build',\n solution: 'Fix the build error above, then retry',\n work: async () => {\n const result = await build()\n reporter.report({message: successMessage, status: 'pass'})\n return result\n },\n })\n return result ?? undefined\n}\n\n/**\n * The deploy directory must exist and hold the right build output: a federation\n * remote for a workbench app, an `index.html` SPA otherwise.\n */\nexport async function verifyOutputDir({\n isWorkbenchApp,\n reporter,\n sourceDir,\n}: {\n isWorkbenchApp: boolean\n reporter: DeployCheckReporter\n sourceDir: string\n}): Promise<Record<string, unknown> | undefined> {\n const spin = spinner('Verifying local content...').start()\n let mfManifest: Record<string, unknown> | undefined\n try {\n if (isWorkbenchApp) mfManifest = await readBuiltManifest(sourceDir)\n else await checkDir(sourceDir)\n spin.succeed()\n } catch (err) {\n spin.fail()\n deployDebug('Error checking directory', err)\n reporter.report({\n message: getErrorMessage(err),\n solution: 'Run the build first, or check the output directory',\n status: 'fail',\n })\n }\n return mfManifest\n}\n\n/**\n * The single diagnosis for each app deploy-target verdict, shared by the\n * dry-run report and the real deploy's unattended error paths so message,\n * fix, and exit code can't drift between the two.\n */\nexport function describeAppTarget(\n resolution: AppDeployTargetResolution,\n {title}: {title?: string} = {},\n): DeployCheck {\n switch (resolution.type) {\n case 'blocked': {\n return {message: `Deploy target not resolved — ${resolution.message}`, status: 'skip'}\n }\n case 'found': {\n const {application} = resolution\n const title = application.title ?? application.appHost\n const url = application.url ?? getCoreAppUrl(application.organizationId, application.id)\n return {\n application,\n message: `Deploys to existing application \"${title}\" at ${url}`,\n status: 'pass',\n target: {\n action: 'update',\n id: application.id,\n title: application.title,\n type: 'coreApp',\n url,\n },\n }\n }\n case 'invalid': {\n return {\n message: APP_ID_NOT_FOUND_IN_ORGANIZATION,\n solution: 'Check `deployment.appId` matches an app in your organization',\n status: 'fail',\n }\n }\n case 'needs-input': {\n return {\n exitCode: exitCodes.USAGE_ERROR,\n message: `No \\`deployment.appId\\` configured (${resolution.existing.length} existing ${resolution.existing.length === 1 ? 'application' : 'applications'} to choose from)`,\n solution:\n 'Set `deployment.appId` in sanity.cli.ts to deploy to an existing app, or run `sanity deploy --create --title \"<name>\" --yes` to create a new one',\n status: 'fail',\n }\n }\n case 'slug-taken': {\n return describeSlugTaken(resolution)\n }\n // Without --title, creating an app needs a prompt no unattended run can answer\n case 'would-create': {\n const {appHost} = resolution\n if (title) {\n return {\n message: `Would create a new application \"${title}\"${appHost ? ` with slug \"${appHost}\"` : ''}`,\n status: 'pass',\n target: {\n action: 'create',\n id: null,\n ...(appHost ? {slug: appHost} : {}),\n title,\n type: 'coreApp',\n url: null,\n },\n }\n }\n return {\n exitCode: exitCodes.USAGE_ERROR,\n message: 'No application to deploy to — creating one needs a title',\n solution:\n 'Pass `--title \"<name>\"` or set `app.title` in sanity.cli.ts to create one, or set `deployment.appId` to deploy to an existing app',\n status: 'fail',\n }\n }\n }\n}\n\n/** One diagnosis for both the app and studio verdicts: they share a slug namespace. */\nfunction describeSlugTaken({\n appHost,\n existing,\n}: {\n appHost: string\n existing: DeployTargetApp\n}): DeployCheck {\n return {\n application: existing,\n exitCode: exitCodes.USAGE_ERROR,\n message: `An application already exists at slug \"${appHost}\" in this organization (app ID ${existing.id})`,\n solution: `Add \\`deployment: {appId: '${existing.id}'}\\` to sanity.cli.ts to redeploy it`,\n status: 'fail',\n target: {\n action: 'update',\n id: existing.id,\n title: existing.title,\n type: existing.type,\n url: existing.url ?? null,\n },\n }\n}\n\nexport function describeAppTargetError(err: unknown, organizationId: string | undefined): string {\n return (err as {statusCode?: number})?.statusCode === 403\n ? `You don’t have permission to view applications for the configured organization ID (\"${organizationId}\"). Verify the organization ID, or ask your organization’s admin for access.`\n : `Failed to resolve deploy target: ${getErrorMessage(err)}`\n}\n\n/**\n * Reports the app deploy target as a check and returns the resolved target;\n * `isWorkbenchApp` selects the backend. Both modes run it — a real deploy uses\n * it to reject a bad `appId` before building.\n */\nexport async function checkAppTarget(\n reporter: DeployCheckReporter,\n options:\n | {\n appId: string | undefined\n create?: boolean\n isWorkbenchApp?: false\n organizationId: string | undefined\n title?: string\n }\n | {\n appId: string | undefined\n hasAppView: boolean\n isWorkbenchApp: true\n organizationId?: string\n slug?: string\n title?: string\n },\n): Promise<DeployCheck | null> {\n const {title} = options\n if (options.isWorkbenchApp) {\n const {appId, hasAppView, organizationId, slug} = options\n return runStep(reporter, {\n debug: deployDebug,\n name: 'target',\n work: async () => {\n const resolution = await resolveWorkbenchApp({appId, hasAppView, organizationId, slug})\n const check = describeAppTarget(resolution, {title})\n reporter.report(check)\n return check\n },\n })\n }\n\n const {appId, create, organizationId} = options\n return runStep(reporter, {\n debug: deployDebug,\n formatError: (err) => describeAppTargetError(err, organizationId),\n name: 'target',\n work: async () => {\n const check = describeAppTarget(\n await resolveAppDeployTarget({appId, create, organizationId}),\n {\n title,\n },\n )\n reporter.report(check)\n return check\n },\n })\n}\n\n/** Same contract as {@link describeAppTarget}, for the studio verdicts. */\nexport function describeStudioTarget(\n resolution: StudioDeployTargetResolution,\n {isExternal, isWorkbench, title}: {isExternal: boolean; isWorkbench?: boolean; title?: string},\n): DeployCheck {\n const studioUrl = (host: string) => (isExternal ? host : `https://${host}.sanity.studio`)\n\n switch (resolution.type) {\n case 'blocked': {\n return {message: `Deploy target not resolved — ${resolution.message}`, status: 'skip'}\n }\n case 'found': {\n const {appHost} = resolution.application\n const url = resolution.application.url ?? (appHost ? studioUrl(appHost) : null)\n return {\n application: resolution.application,\n message: `Deploys to existing studio ${url}`,\n status: 'pass',\n target: {\n action: 'update',\n id: resolution.application.id,\n title: resolution.application.title,\n type: 'studio',\n url,\n },\n }\n }\n case 'invalid': {\n return {\n // A bad host is a usage error; other invalid targets exit 1\n exitCode: resolution.reason === 'invalid-host' ? exitCodes.USAGE_ERROR : 1,\n message: resolution.message,\n solution: 'Check `studioHost` and `deployment.appId` in sanity.cli.ts',\n status: 'fail',\n }\n }\n case 'needs-input': {\n return {\n exitCode: exitCodes.USAGE_ERROR,\n message: isExternal ? 'No external studio URL configured' : 'No studio hostname configured',\n solution: isExternal\n ? 'Set `studioHost` in sanity.cli.ts, or pass the full URL with --url'\n : 'Set `studioHost` in sanity.cli.ts, or pass a hostname with --url',\n status: 'fail',\n }\n }\n case 'slug-taken': {\n return describeSlugTaken(resolution)\n }\n case 'would-create': {\n const appHost = resolution.appHost\n const url = isWorkbench ? null : studioUrl(appHost)\n const result = {\n status: 'pass',\n target: {action: 'create', id: null, title: title || null, type: 'studio', url},\n } as const\n const titled = title ? ` titled \"${title}\"` : ''\n\n if (isExternal) {\n return {\n message: `Would register external studio at ${appHost}${titled}`,\n ...result,\n }\n }\n\n if (isWorkbench) {\n return {\n message: `Would create a new studio${title ? ` \"${title}\"` : ''} with slug \"${appHost}\" (name availability is checked on deploy)`,\n ...result,\n target: {...result.target, slug: appHost},\n }\n }\n\n return {\n message: `Would create studio hostname ${url}${titled} (name availability is checked on deploy)`,\n ...result,\n }\n }\n }\n}\n\n/**\n * Reports the studio deploy target as a check and returns the resolved target;\n * `isWorkbenchApp` selects the backend. Both modes run it — a real deploy uses\n * it to reject a bad `appId` before building.\n */\nexport async function checkStudioTarget(\n reporter: DeployCheckReporter,\n options:\n | {\n appId: string | undefined\n isExternal: boolean\n isWorkbenchApp?: false\n projectId: string | undefined\n studioHost: string | undefined\n title: string | undefined\n urlFlag: string | undefined\n }\n | {\n appId: string | undefined\n isWorkbenchApp: true\n organizationId?: string\n slug: string\n title?: string\n },\n): Promise<DeployCheck | null> {\n const {title} = options\n const resolve = options.isWorkbenchApp\n ? resolveWorkbenchStudio(options)\n : resolveStudioDeployTarget(options)\n // A workbench studio's target is its slug, even when its build is hosted externally.\n const isExternal = options.isWorkbenchApp ? false : options.isExternal\n\n return runStep(reporter, {\n debug: deployDebug,\n formatError: (err) => `Failed to resolve deploy target: ${getErrorMessage(err)}`,\n name: 'target',\n work: async () => {\n const check = describeStudioTarget(await resolve, {\n isExternal,\n isWorkbench: !!options.isWorkbenchApp,\n title,\n })\n reporter.report(check)\n return check\n },\n })\n}\n"],"names":["exitCodes","getLocalPackageVersion","getErrorMessage","getCoreAppUrl","spinner","readBuiltManifest","resolveAppIdIssue","runStep","APP_ID_NOT_FOUND_IN_ORGANIZATION","getAutoUpdateIssueMessage","getAutoUpdateMigrationHint","resolveAutoUpdates","checkDir","deployDebug","resolveAppDeployTarget","resolveStudioDeployTarget","resolveWorkbenchApp","resolveWorkbenchStudio","normalizeUrl","validateUrl","checkPackageVersion","reporter","moduleName","workDir","version","report","message","status","solution","checkAutoUpdates","cliConfig","flags","enabled","issue","type","autoUpdates","checkAppId","checkExternalUrl","appId","url","undefined","exitCode","USAGE_ERROR","normalized","validation","hash","origin","pathname","search","URL","checkBuild","build","skipReason","successMessage","result","debug","formatError","err","name","work","verifyOutputDir","isWorkbenchApp","sourceDir","spin","start","mfManifest","succeed","fail","describeAppTarget","resolution","title","application","appHost","organizationId","id","target","action","existing","length","describeSlugTaken","slug","describeAppTargetError","statusCode","checkAppTarget","options","hasAppView","check","create","describeStudioTarget","isExternal","isWorkbench","studioUrl","host","reason","titled","checkStudioTarget","resolve"],"mappings":"AAAA,SAAwBA,SAAS,EAAEC,sBAAsB,QAAO,mBAAkB;AAClF,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,aAAa,QAAO,wBAAuB;AACnD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,iBAAiB,QAAO,8BAA6B;AAE7D,SAAQC,iBAAiB,QAAO,sBAAqB;AACrD,SAAwCC,OAAO,QAAO,uBAAsB;AAC5E,SAAQC,gCAAgC,QAAO,8BAA6B;AAC5E,SACEC,yBAAyB,EACzBC,0BAA0B,EAC1BC,kBAAkB,QACb,+BAA8B;AACrC,SAAQC,QAAQ,QAAO,gBAA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}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deployChecks.ts"],"sourcesContent":["import {type CliConfig, exitCodes, getLocalPackageVersion} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {getCoreAppUrl} from '@sanity/cli-core/util'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {readBuiltManifest} from '@sanity/workbench-cli/build'\n\nimport {resolveAppIdIssue} from '../../util/appId.js'\nimport {type Check, type CheckReporter, runStep} from '../../util/checks.js'\nimport {APP_ID_NOT_FOUND_IN_ORGANIZATION} from '../../util/errorMessages.js'\nimport {\n getAutoUpdateIssueMessage,\n getAutoUpdateMigrationHint,\n resolveAutoUpdates,\n} from '../build/shouldAutoUpdate.js'\nimport {checkDir} from './checkDir.js'\nimport {deployDebug} from './deployDebug.js'\nimport {\n type AppDeployTargetResolution,\n type DeployTargetApp,\n resolveAppDeployTarget,\n resolveStudioDeployTarget,\n resolveWorkbenchApp,\n resolveWorkbenchStudio,\n type StudioDeployTargetResolution,\n} from './resolveDeployTarget.js'\nimport {getDeployErrorMessage} from './serviceUnavailable.js'\nimport {type DeployFlags} from './types.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\n/**\n * Where a deploy resolves to, computed once from the deploy-target verdict. The\n * dry-run report and its JSON both read this, so the human and machine outputs\n * can't drift.\n */\nexport interface DeployTarget {\n /** Whether the deploy creates a new application/studio or updates an existing one. */\n action: 'create' | 'update'\n /** `null` until the deploy creates the application. */\n id: string | null\n title: string | null\n type: 'coreApp' | 'studio'\n url: string | null\n\n /** Absent on a plain app, whose backend reports `appHost` instead. */\n slug?: string\n}\n\nexport interface DeployCheck extends Check {\n /** The backend's record, verbatim; `--json` reports it once the deploy succeeds. */\n application?: object\n /** Set on the deploy-target check with the resolved target both reporters read. */\n target?: DeployTarget\n}\n\nexport type DeployCheckReporter = CheckReporter<DeployCheck>\n\nexport async function checkPackageVersion(\n reporter: DeployCheckReporter,\n {moduleName, workDir}: {moduleName: string; workDir: string},\n): Promise<string | null> {\n const version = await getLocalPackageVersion(moduleName, workDir)\n reporter.report(\n version\n ? {message: `Using ${moduleName} ${version}`, status: 'pass'}\n : {\n message: `Failed to find installed ${moduleName} version`,\n solution: `Install ${moduleName} in this project`,\n status: 'fail',\n },\n )\n return version\n}\n\nexport function checkAutoUpdates(\n reporter: DeployCheckReporter,\n {cliConfig, flags}: {cliConfig: CliConfig; flags: DeployFlags},\n): boolean {\n const {enabled, issue} = resolveAutoUpdates({cliConfig, flags})\n\n if (issue) {\n reporter.report({\n message: getAutoUpdateIssueMessage(issue),\n // A config conflict makes a real deploy refuse to run; deprecations only warn\n status: issue.type === 'conflicting-config' ? 'fail' : 'warn',\n })\n\n // The deprecated top-level config also gets the styled migration edit, the\n // same second warning the build/dev path prints through shouldAutoUpdate.\n if (issue.type === 'deprecated-config') {\n reporter.report({\n message: getAutoUpdateMigrationHint(cliConfig.autoUpdates),\n status: 'warn',\n })\n }\n }\n\n return enabled\n}\n\n/**\n * The dry-run form of the `app.id` config check a real deploy runs in\n * `findUserApplication`: a conflict fails (both `app.id` and `deployment.appId`\n * set), the deprecated config alone warns.\n */\nexport function checkAppId(\n reporter: DeployCheckReporter,\n {cliConfig}: {cliConfig: CliConfig},\n): void {\n const issue = resolveAppIdIssue(cliConfig)\n if (issue === 'conflicting-config') {\n reporter.report({\n message: 'Both `app.id` (deprecated) and `deployment.appId` are set',\n solution: 'Remove `app.id` from sanity.cli.ts',\n status: 'fail',\n })\n } else if (issue === 'deprecated-config') {\n reporter.report({\n message: 'The `app.id` config is deprecated',\n solution: 'Move it to `deployment.appId` in sanity.cli.ts',\n status: 'warn',\n })\n }\n}\n\n/**\n * The origin a federated studio deployed with --external is registered\n * at. Only a first deploy registers one; a redeploy keeps the URL it has.\n */\nexport function checkExternalUrl(\n reporter: DeployCheckReporter,\n {appId, url}: {appId: string | undefined; url: string | undefined},\n): string | undefined {\n if (appId) return undefined\n\n if (!url) {\n reporter.report({\n exitCode: exitCodes.USAGE_ERROR,\n message: 'A first external deploy needs the URL your host serves the build from',\n solution: 'Pass it with --url, for example --url https://studio.example.com',\n status: 'fail',\n })\n return undefined\n }\n\n const normalized = normalizeUrl(url)\n const validation = validateUrl(normalized)\n if (validation !== true) {\n reporter.report({\n exitCode: exitCodes.USAGE_ERROR,\n message: validation,\n solution:\n 'Pass --url with an http or https URL, for example --url https://studio.example.com',\n status: 'fail',\n })\n return undefined\n }\n\n // The Dashboard loads the remote from the origin root, so a path would never be fetched.\n const {hash, origin, pathname, search} = new URL(normalized)\n if (pathname !== '/' || search || hash) {\n reporter.report({\n exitCode: exitCodes.USAGE_ERROR,\n message: '--url must be an origin with no path, query or hash',\n solution:\n 'Pass the origin your host serves the build from, for example --url https://studio.example.com',\n status: 'fail',\n })\n return undefined\n }\n\n reporter.report({message: `Registers at ${origin}`, status: 'pass'})\n return origin\n}\n\nexport async function checkBuild<T>(\n reporter: DeployCheckReporter,\n {\n build,\n skipReason,\n successMessage,\n }: {build: () => Promise<T>; skipReason: string | undefined; successMessage: string},\n): Promise<T | undefined> {\n if (skipReason) {\n reporter.report({message: skipReason, status: 'skip'})\n return undefined\n }\n\n const result = await runStep(reporter, {\n debug: deployDebug,\n formatError: (err) => `Build failed: ${getErrorMessage(err)}`,\n name: 'build',\n solution: 'Fix the build error above, then retry',\n work: async () => {\n const result = await build()\n reporter.report({message: successMessage, status: 'pass'})\n return result\n },\n })\n return result ?? undefined\n}\n\n/**\n * The deploy directory must exist and hold the right build output: a federation\n * remote for a workbench app, an `index.html` SPA otherwise.\n */\nexport async function verifyOutputDir({\n isWorkbenchApp,\n reporter,\n sourceDir,\n}: {\n isWorkbenchApp: boolean\n reporter: DeployCheckReporter\n sourceDir: string\n}): Promise<Record<string, unknown> | undefined> {\n const spin = spinner('Verifying local content...').start()\n let mfManifest: Record<string, unknown> | undefined\n try {\n if (isWorkbenchApp) mfManifest = await readBuiltManifest(sourceDir)\n else await checkDir(sourceDir)\n spin.succeed()\n } catch (err) {\n spin.fail()\n deployDebug('Error checking directory', err)\n reporter.report({\n message: getErrorMessage(err),\n solution: 'Run the build first, or check the output directory',\n status: 'fail',\n })\n }\n return mfManifest\n}\n\n/**\n * The single diagnosis for each app deploy-target verdict, shared by the\n * dry-run report and the real deploy's unattended error paths so message,\n * fix, and exit code can't drift between the two.\n */\nexport function describeAppTarget(\n resolution: AppDeployTargetResolution,\n {title}: {title?: string} = {},\n): DeployCheck {\n switch (resolution.type) {\n case 'blocked': {\n return {message: `Deploy target not resolved — ${resolution.message}`, status: 'skip'}\n }\n case 'found': {\n const {application} = resolution\n const title = application.title ?? application.appHost\n const url = application.url ?? getCoreAppUrl(application.organizationId, application.id)\n return {\n application,\n message: `Deploys to existing application \"${title}\" at ${url}`,\n status: 'pass',\n target: {\n action: 'update',\n id: application.id,\n title: application.title,\n type: 'coreApp',\n url,\n },\n }\n }\n case 'invalid': {\n return {\n message: APP_ID_NOT_FOUND_IN_ORGANIZATION,\n solution: 'Check `deployment.appId` matches an app in your organization',\n status: 'fail',\n }\n }\n case 'needs-input': {\n return {\n exitCode: exitCodes.USAGE_ERROR,\n message: `No \\`deployment.appId\\` configured (${resolution.existing.length} existing ${resolution.existing.length === 1 ? 'application' : 'applications'} to choose from)`,\n solution:\n 'Set `deployment.appId` in sanity.cli.ts to deploy to an existing app, or run `sanity deploy --create --title \"<name>\" --yes` to create a new one',\n status: 'fail',\n }\n }\n case 'slug-taken': {\n return describeSlugTaken(resolution)\n }\n // Without --title, creating an app needs a prompt no unattended run can answer\n case 'would-create': {\n const {appHost} = resolution\n if (title) {\n return {\n message: `Would create a new application \"${title}\"${appHost ? ` with slug \"${appHost}\"` : ''}`,\n status: 'pass',\n target: {\n action: 'create',\n id: null,\n ...(appHost ? {slug: appHost} : {}),\n title,\n type: 'coreApp',\n url: null,\n },\n }\n }\n return {\n exitCode: exitCodes.USAGE_ERROR,\n message: 'No application to deploy to — creating one needs a title',\n solution:\n 'Pass `--title \"<name>\"` or set `app.title` in sanity.cli.ts to create one, or set `deployment.appId` to deploy to an existing app',\n status: 'fail',\n }\n }\n }\n}\n\n/** One diagnosis for both the app and studio verdicts: they share a slug namespace. */\nfunction describeSlugTaken({\n appHost,\n existing,\n}: {\n appHost: string\n existing: DeployTargetApp\n}): DeployCheck {\n return {\n application: existing,\n exitCode: exitCodes.USAGE_ERROR,\n message: `An application already exists at slug \"${appHost}\" in this organization (app ID ${existing.id})`,\n solution: `Add \\`deployment: {appId: '${existing.id}'}\\` to sanity.cli.ts to redeploy it`,\n status: 'fail',\n target: {\n action: 'update',\n id: existing.id,\n title: existing.title,\n type: existing.type,\n url: existing.url ?? null,\n },\n }\n}\n\nexport function describeAppTargetError(err: unknown, organizationId: string | undefined): string {\n return (err as {statusCode?: number})?.statusCode === 403\n ? `You don’t have permission to view applications for the configured organization ID (\"${organizationId}\"). Verify the organization ID, or ask your organization’s admin for access.`\n : `Failed to resolve deploy target: ${getDeployErrorMessage(err)}`\n}\n\n/**\n * Reports the app deploy target as a check and returns the resolved target;\n * `isWorkbenchApp` selects the backend. Both modes run it — a real deploy uses\n * it to reject a bad `appId` before building.\n */\nexport async function checkAppTarget(\n reporter: DeployCheckReporter,\n options:\n | {\n appId: string | undefined\n create?: boolean\n isWorkbenchApp?: false\n organizationId: string | undefined\n title?: string\n }\n | {\n appId: string | undefined\n hasAppView: boolean\n isWorkbenchApp: true\n organizationId?: string\n slug?: string\n title?: string\n },\n): Promise<DeployCheck | null> {\n const {title} = options\n if (options.isWorkbenchApp) {\n const {appId, hasAppView, organizationId, slug} = options\n return runStep(reporter, {\n debug: deployDebug,\n name: 'target',\n work: async () => {\n const resolution = await resolveWorkbenchApp({appId, hasAppView, organizationId, slug})\n const check = describeAppTarget(resolution, {title})\n reporter.report(check)\n return check\n },\n })\n }\n\n const {appId, create, organizationId} = options\n return runStep(reporter, {\n debug: deployDebug,\n formatError: (err) => describeAppTargetError(err, organizationId),\n name: 'target',\n work: async () => {\n const check = describeAppTarget(\n await resolveAppDeployTarget({appId, create, organizationId}),\n {\n title,\n },\n )\n reporter.report(check)\n return check\n },\n })\n}\n\n/** Same contract as {@link describeAppTarget}, for the studio verdicts. */\nexport function describeStudioTarget(\n resolution: StudioDeployTargetResolution,\n {isExternal, isWorkbench, title}: {isExternal: boolean; isWorkbench?: boolean; title?: string},\n): DeployCheck {\n const studioUrl = (host: string) => (isExternal ? host : `https://${host}.sanity.studio`)\n\n switch (resolution.type) {\n case 'blocked': {\n return {message: `Deploy target not resolved — ${resolution.message}`, status: 'skip'}\n }\n case 'found': {\n const {appHost} = resolution.application\n const url = resolution.application.url ?? (appHost ? studioUrl(appHost) : null)\n return {\n application: resolution.application,\n message: `Deploys to existing studio ${url}`,\n status: 'pass',\n target: {\n action: 'update',\n id: resolution.application.id,\n title: resolution.application.title,\n type: 'studio',\n url,\n },\n }\n }\n case 'invalid': {\n return {\n // A bad host is a usage error; other invalid targets exit 1\n exitCode: resolution.reason === 'invalid-host' ? exitCodes.USAGE_ERROR : 1,\n message: resolution.message,\n solution: 'Check `studioHost` and `deployment.appId` in sanity.cli.ts',\n status: 'fail',\n }\n }\n case 'needs-input': {\n return {\n exitCode: exitCodes.USAGE_ERROR,\n message: isExternal ? 'No external studio URL configured' : 'No studio hostname configured',\n solution: isExternal\n ? 'Set `studioHost` in sanity.cli.ts, or pass the full URL with --url'\n : 'Set `studioHost` in sanity.cli.ts, or pass a hostname with --url',\n status: 'fail',\n }\n }\n case 'slug-taken': {\n return describeSlugTaken(resolution)\n }\n case 'would-create': {\n const appHost = resolution.appHost\n const url = isWorkbench ? null : studioUrl(appHost)\n const result = {\n status: 'pass',\n target: {action: 'create', id: null, title: title || null, type: 'studio', url},\n } as const\n const titled = title ? ` titled \"${title}\"` : ''\n\n if (isExternal) {\n return {\n message: `Would register external studio at ${appHost}${titled}`,\n ...result,\n }\n }\n\n if (isWorkbench) {\n return {\n message: `Would create a new studio${title ? ` \"${title}\"` : ''} with slug \"${appHost}\" (name availability is checked on deploy)`,\n ...result,\n target: {...result.target, slug: appHost},\n }\n }\n\n return {\n message: `Would create studio hostname ${url}${titled} (name availability is checked on deploy)`,\n ...result,\n }\n }\n }\n}\n\n/**\n * Reports the studio deploy target as a check and returns the resolved target;\n * `isWorkbenchApp` selects the backend. Both modes run it — a real deploy uses\n * it to reject a bad `appId` before building.\n */\nexport async function checkStudioTarget(\n reporter: DeployCheckReporter,\n options:\n | {\n appId: string | undefined\n isExternal: boolean\n isWorkbenchApp?: false\n projectId: string | undefined\n studioHost: string | undefined\n title: string | undefined\n urlFlag: string | undefined\n }\n | {\n appId: string | undefined\n isWorkbenchApp: true\n organizationId?: string\n slug: string\n title?: string\n },\n): Promise<DeployCheck | null> {\n const {title} = options\n const resolve = options.isWorkbenchApp\n ? resolveWorkbenchStudio(options)\n : resolveStudioDeployTarget(options)\n // A workbench studio's target is its slug, even when its build is hosted externally.\n const isExternal = options.isWorkbenchApp ? false : options.isExternal\n\n return runStep(reporter, {\n debug: deployDebug,\n formatError: (err) => `Failed to resolve deploy target: ${getDeployErrorMessage(err)}`,\n name: 'target',\n work: async () => {\n const check = describeStudioTarget(await resolve, {\n isExternal,\n isWorkbench: !!options.isWorkbenchApp,\n title,\n })\n reporter.report(check)\n return check\n },\n })\n}\n"],"names":["exitCodes","getLocalPackageVersion","getErrorMessage","getCoreAppUrl","spinner","readBuiltManifest","resolveAppIdIssue","runStep","APP_ID_NOT_FOUND_IN_ORGANIZATION","getAutoUpdateIssueMessage","getAutoUpdateMigrationHint","resolveAutoUpdates","checkDir","deployDebug","resolveAppDeployTarget","resolveStudioDeployTarget","resolveWorkbenchApp","resolveWorkbenchStudio","getDeployErrorMessage","normalizeUrl","validateUrl","checkPackageVersion","reporter","moduleName","workDir","version","report","message","status","solution","checkAutoUpdates","cliConfig","flags","enabled","issue","type","autoUpdates","checkAppId","checkExternalUrl","appId","url","undefined","exitCode","USAGE_ERROR","normalized","validation","hash","origin","pathname","search","URL","checkBuild","build","skipReason","successMessage","result","debug","formatError","err","name","work","verifyOutputDir","isWorkbenchApp","sourceDir","spin","start","mfManifest","succeed","fail","describeAppTarget","resolution","title","application","appHost","organizationId","id","target","action","existing","length","describeSlugTaken","slug","describeAppTargetError","statusCode","checkAppTarget","options","hasAppView","check","create","describeStudioTarget","isExternal","isWorkbench","studioUrl","host","reason","titled","checkStudioTarget","resolve"],"mappings":"AAAA,SAAwBA,SAAS,EAAEC,sBAAsB,QAAO,mBAAkB;AAClF,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,aAAa,QAAO,wBAAuB;AACnD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,iBAAiB,QAAO,8BAA6B;AAE7D,SAAQC,iBAAiB,QAAO,sBAAqB;AACrD,SAAwCC,OAAO,QAAO,uBAAsB;AAC5E,SAAQC,gCAAgC,QAAO,8BAA6B;AAC5E,SACEC,yBAAyB,EACzBC,0BAA0B,EAC1BC,kBAAkB,QACb,+BAA8B;AACrC,SAAQC,QAAQ,QAAO,gBAAe;AACtC,SAAQC,WAAW,QAAO,mBAAkB;AAC5C,SAGEC,sBAAsB,EACtBC,yBAAyB,EACzBC,mBAAmB,EACnBC,sBAAsB,QAEjB,2BAA0B;AACjC,SAAQC,qBAAqB,QAAO,0BAAyB;AAE7D,SAAQC,YAAY,EAAEC,WAAW,QAAO,gBAAe;AA6BvD,OAAO,eAAeC,oBACpBC,QAA6B,EAC7B,EAACC,UAAU,EAAEC,OAAO,EAAwC;IAE5D,MAAMC,UAAU,MAAMxB,uBAAuBsB,YAAYC;IACzDF,SAASI,MAAM,CACbD,UACI;QAACE,SAAS,CAAC,MAAM,EAAEJ,WAAW,CAAC,EAAEE,SAAS;QAAEG,QAAQ;IAAM,IAC1D;QACED,SAAS,CAAC,yBAAyB,EAAEJ,WAAW,QAAQ,CAAC;QACzDM,UAAU,CAAC,QAAQ,EAAEN,WAAW,gBAAgB,CAAC;QACjDK,QAAQ;IACV;IAEN,OAAOH;AACT;AAEA,OAAO,SAASK,iBACdR,QAA6B,E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,6BAA6B,EAAEa,MAAMuD,OAAO,yCAAyC,CAAC;oBAChG,GAAGxC,MAAM;gBACX;YACF;IACF;AACF;AAEA;;;;CAIC,GACD,OAAO,eAAeyC,kBACpB1E,QAA6B,EAC7B+D,OAgBK;IAEL,MAAM,EAACd,KAAK,EAAC,GAAGc;IAChB,MAAMY,UAAUZ,QAAQvB,cAAc,GAClC7C,uBAAuBoE,WACvBtE,0BAA0BsE;IAC9B,qFAAqF;IACrF,MAAMK,aAAaL,QAAQvB,cAAc,GAAG,QAAQuB,QAAQK,UAAU;IAEtE,OAAOnF,QAAQe,UAAU;QACvBkC,OAAO3C;QACP4C,aAAa,CAACC,MAAQ,CAAC,iCAAiC,EAAExC,sBAAsBwC,MAAM;QACtFC,MAAM;QACNC,MAAM;YACJ,MAAM2B,QAAQE,qBAAqB,MAAMQ,SAAS;gBAChDP;gBACAC,aAAa,CAAC,CAACN,QAAQvB,cAAc;gBACrCS;YACF;YACAjD,SAASI,MAAM,CAAC6D;YAChB,OAAOA;QACT;IACF;AACF"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { CLIError } from '@oclif/core/errors';
|
|
2
2
|
import { exitCodes } from '@sanity/cli-core';
|
|
3
|
-
import {
|
|
3
|
+
import { JsonOutputError } from '@sanity/cli-core/errors';
|
|
4
4
|
import { createCollectingReporter, createFailFastReporter } from '../../util/checks.js';
|
|
5
5
|
import { toStderrOutput } from '../../util/toStderrOutput.js';
|
|
6
6
|
import { deployDebug } from './deployDebug.js';
|
|
7
7
|
import { deploymentPlanToJson, isDeployable, renderDeploymentPlan } from './deploymentPlan.js';
|
|
8
|
+
import { getDeployErrorMessage } from './serviceUnavailable.js';
|
|
8
9
|
/**
|
|
9
10
|
* Runs a deploy in the mode the flags select: a real deploy fails fast and
|
|
10
11
|
* mutates, `--dry-run` drives the same `run` sequence read-only and renders a
|
|
@@ -98,7 +99,7 @@ import { deploymentPlanToJson, isDeployable, renderDeploymentPlan } from './depl
|
|
|
98
99
|
deployDebug(`Error deploying ${type === 'coreApp' ? 'application' : 'studio'}`, error);
|
|
99
100
|
return {
|
|
100
101
|
exit: exitCodes.RUNTIME_ERROR,
|
|
101
|
-
message: `Error deploying ${type === 'coreApp' ? 'application' : 'studio'}: ${
|
|
102
|
+
message: `Error deploying ${type === 'coreApp' ? 'application' : 'studio'}: ${getDeployErrorMessage(error)}`
|
|
102
103
|
};
|
|
103
104
|
}
|
|
104
105
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/deployRunner.ts"],"sourcesContent":["import {CLIError} from '@oclif/core/errors'\nimport {exitCodes, type Output} from '@sanity/cli-core'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deployRunner.ts"],"sourcesContent":["import {CLIError} from '@oclif/core/errors'\nimport {exitCodes, type Output} from '@sanity/cli-core'\nimport {JsonOutputError} from '@sanity/cli-core/errors'\nimport {type WorkbenchDeployPayload} from '@sanity/workbench-cli/deploy'\n\nimport {createCollectingReporter, createFailFastReporter} from '../../util/checks.js'\nimport {toStderrOutput} from '../../util/toStderrOutput.js'\nimport {type DeployCheck, type DeployCheckReporter, type DeployTarget} from './deployChecks.js'\nimport {deployDebug} from './deployDebug.js'\nimport {\n type DeploymentFile,\n type DeploymentPlan,\n deploymentPlanToJson,\n isDeployable,\n renderDeploymentPlan,\n} from './deploymentPlan.js'\nimport {getDeployErrorMessage} from './serviceUnavailable.js'\nimport {type DeployAppOptions} from './types.js'\n\nexport interface DeployResult {\n application: object | null\n payload: DeployPayload\n\n action?: DeployTarget['action']\n /** Resolved server-side, so it stays out of the local payload. */\n installationId?: string\n url?: string | null\n}\n\n/** Collected locally, so a dry run reports it too. */\nexport interface DeployPayload extends Partial<WorkbenchDeployPayload> {\n /** The configured `deployment.appId`; `null` when the deploy would mint one. */\n appId: string | null\n isAutoUpdating: boolean\n type: 'coreApp' | 'studio'\n version: string | null\n\n /**\n * The aspect-document sync a media-library config deploy will run: every\n * config field is upserted, stored definitions without a matching config\n * field are deleted (the config mirrors into the library). Collected during\n * planning, so a `--dry-run --json` consumer sees the deletions too.\n */\n aspectSync?: {\n deleteIds: string[]\n mediaLibraryId: string\n upsertIds: string[]\n }\n organizationId?: string\n projectId?: string\n}\n\n/**\n * The parts of a deploy that differ between core apps and studios. The shared\n * sequence — mode selection, error handling, the dry-run plan, `--json` — lives\n * in `runDeploy`.\n */\nexport interface DeploySpec {\n /** Files a real deploy would upload, listed only for the dry-run plan. */\n listFiles: (options: DeployAppOptions) => Promise<DeploymentFile[]>\n /** The step sequence; every step reports through `reporter`. */\n run: (options: DeployAppOptions, reporter: DeployCheckReporter) => Promise<DeployResult | void>\n type: 'coreApp' | 'studio'\n}\n\n/**\n * Runs a deploy in the mode the flags select: a real deploy fails fast and\n * mutates, `--dry-run` drives the same `run` sequence read-only and renders a\n * plan, and `--json` emits the same information as machine-readable JSON.\n */\nexport async function runDeploy(options: DeployAppOptions, spec: DeploySpec): Promise<void> {\n const {output} = options\n const json = !!options.flags.json\n const emitJson = (payload: unknown) => output.logJson(payload)\n let failurePayload: unknown\n\n // The JSON payload owns stdout, so the run's progress logs go to stderr; only\n // the final JSON.stringify writes to stdout.\n const runOptions = json ? {...options, output: toStderrOutput(output)} : options\n\n try {\n if (options.flags['dry-run']) {\n const plan = await collectPlan(runOptions, spec)\n if (json) {\n const payload = deploymentPlanToJson(plan)\n if (isDeployable(plan)) emitJson(payload)\n else failurePayload = payload\n } else renderDeploymentPlan(plan, output)\n exitIfBlocked(plan, output)\n return\n }\n\n const result = await spec.run(runOptions, createFailFastReporter(runOptions.output))\n if (json && result) emitJson({deployed: true, reason: null, ...result})\n } catch (error) {\n const failure = normalizeFailure(error, spec.type)\n // Preserve the blocked plan or the existing deployment failure envelope.\n if (json && !options.flags['dry-run']) {\n failurePayload = {\n application: null,\n deployed: false,\n error: {message: failure.message},\n payload: null,\n reason: failure.message,\n }\n }\n if (json && failurePayload !== undefined) {\n throw new JsonOutputError(failure.message, failurePayload, failure.exit)\n }\n output.error(failure.message, {exit: failure.exit})\n }\n}\n\n/** Runs the step sequence read-only and gathers the plan a dry run reports. */\nasync function collectPlan(options: DeployAppOptions, spec: DeploySpec): Promise<DeploymentPlan> {\n const reporter = createCollectingReporter<DeployCheck>()\n const result = await spec.run(options, reporter)\n const plan: DeploymentPlan = {\n checks: reporter.results,\n files: [],\n payload: result?.payload ?? null,\n target:\n reporter.results.find((check) => check.target && check.status !== 'fail')?.target ?? null,\n type: spec.type,\n }\n // A blocked deploy uploads nothing, so only enumerate files for a deployable plan.\n if (isDeployable(plan)) plan.files = await spec.listFiles(options)\n return plan\n}\n\n/** Exits like a real (fail-fast) deploy would, on the first failing check's exit code. */\nfunction exitIfBlocked(plan: DeploymentPlan, output: Output): void {\n if (isDeployable(plan)) return\n const failed = plan.checks.find((check) => check.status === 'fail')\n output.error('Deploy blocked by failing checks.', {exit: failed?.exitCode ?? 1})\n}\n\n/** The one failure diagnosis both the stderr message and the `--json` envelope read. */\nfunction normalizeFailure(\n error: unknown,\n type: 'coreApp' | 'studio',\n): {exit: number; message: string} {\n // Ctrl+C on an interactive prompt isn't a real failure\n if (error instanceof Error && error.name === 'ExitPromptError') {\n return {exit: exitCodes.RUNTIME_ERROR, message: 'Deployment cancelled by user'}\n }\n // A failed check already carries its own message and exit code\n if (error instanceof CLIError) {\n return {exit: error.oclif?.exit ?? 1, message: error.message}\n }\n deployDebug(`Error deploying ${type === 'coreApp' ? 'application' : 'studio'}`, error)\n return {\n exit: exitCodes.RUNTIME_ERROR,\n message: `Error deploying ${type === 'coreApp' ? 'application' : 'studio'}: ${getDeployErrorMessage(error)}`,\n }\n}\n"],"names":["CLIError","exitCodes","JsonOutputError","createCollectingReporter","createFailFastReporter","toStderrOutput","deployDebug","deploymentPlanToJson","isDeployable","renderDeploymentPlan","getDeployErrorMessage","runDeploy","options","spec","output","json","flags","emitJson","payload","logJson","failurePayload","runOptions","plan","collectPlan","exitIfBlocked","result","run","deployed","reason","error","failure","normalizeFailure","type","application","message","undefined","exit","reporter","checks","results","files","target","find","check","status","listFiles","failed","exitCode","Error","name","RUNTIME_ERROR","oclif"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,qBAAoB;AAC3C,SAAQC,SAAS,QAAoB,mBAAkB;AACvD,SAAQC,eAAe,QAAO,0BAAyB;AAGvD,SAAQC,wBAAwB,EAAEC,sBAAsB,QAAO,uBAAsB;AACrF,SAAQC,cAAc,QAAO,+BAA8B;AAE3D,SAAQC,WAAW,QAAO,mBAAkB;AAC5C,SAGEC,oBAAoB,EACpBC,YAAY,EACZC,oBAAoB,QACf,sBAAqB;AAC5B,SAAQC,qBAAqB,QAAO,0BAAyB;AAiD7D;;;;CAIC,GACD,OAAO,eAAeC,UAAUC,OAAyB,EAAEC,IAAgB;IACzE,MAAM,EAACC,MAAM,EAAC,GAAGF;IACjB,MAAMG,OAAO,CAAC,CAACH,QAAQI,KAAK,CAACD,IAAI;IACjC,MAAME,WAAW,CAACC,UAAqBJ,OAAOK,OAAO,CAACD;IACtD,IAAIE;IAEJ,8EAA8E;IAC9E,6CAA6C;IAC7C,MAAMC,aAAaN,OAAO;QAAC,GAAGH,OAAO;QAAEE,QAAQT,eAAeS;IAAO,IAAIF;IAEzE,IAAI;QACF,IAAIA,QAAQI,KAAK,CAAC,UAAU,EAAE;YAC5B,MAAMM,OAAO,MAAMC,YAAYF,YAAYR;YAC3C,IAAIE,MAAM;gBACR,MAAMG,UAAUX,qBAAqBe;gBACrC,IAAId,aAAac,OAAOL,SAASC;qBAC5BE,iBAAiBF;YACxB,OAAOT,qBAAqBa,MAAMR;YAClCU,cAAcF,MAAMR;YACpB;QACF;QAEA,MAAMW,SAAS,MAAMZ,KAAKa,GAAG,CAACL,YAAYjB,uBAAuBiB,WAAWP,MAAM;QAClF,IAAIC,QAAQU,QAAQR,SAAS;YAACU,UAAU;YAAMC,QAAQ;YAAM,GAAGH,MAAM;QAAA;IACvE,EAAE,OAAOI,OAAO;QACd,MAAMC,U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ACdG,IAA0B;IAE1B,uDAAuD;IACvD,IAAIH,iBAAiBmB,SAASnB,MAAMoB,IAAI,KAAK,mBAAmB;QAC9D,OAAO;YAACb,MAAMnC,UAAUiD,aAAa;YAAEhB,SAAS;QAA8B;IAChF;IACA,+DAA+D;IAC/D,IAAIL,iBAAiB7B,UAAU;QAC7B,OAAO;YAACoC,MAAMP,MAAMsB,KAAK,EAAEf,QAAQ;YAAGF,SAASL,MAAMK,OAAO;QAAA;IAC9D;IACA5B,YAAY,CAAC,gBAAgB,EAAE0B,SAAS,YAAY,gBAAgB,UAAU,EAAEH;IAChF,OAAO;QACLO,MAAMnC,UAAUiD,aAAa;QAC7BhB,SAAS,CAAC,gBAAgB,EAAEF,SAAS,YAAY,gBAAgB,SAAS,EAAE,EAAEtB,sBAAsBmB,QAAQ;IAC9G;AACF"}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* adapter that turns the resolveDeployTarget verdicts into prompts, creation,
|
|
4
4
|
* and exits. Dry runs consume the same verdicts read-only (see deployChecks).
|
|
5
5
|
*/ import { exitCodes } from '@sanity/cli-core';
|
|
6
|
-
import { getErrorMessage } from '@sanity/cli-core/errors';
|
|
7
6
|
import { select, Separator, spinner } from '@sanity/cli-core/ux';
|
|
8
7
|
import { createUserApplication } from '../../services/userApplications.js';
|
|
9
8
|
import { getAppId } from '../../util/appId.js';
|
|
@@ -11,6 +10,7 @@ import { createFailFastReporter } from '../../util/checks.js';
|
|
|
11
10
|
import { describeAppTarget, describeAppTargetError, describeStudioTarget } from './deployChecks.js';
|
|
12
11
|
import { deployDebug } from './deployDebug.js';
|
|
13
12
|
import { resolveAppDeployTarget, resolveStudioDeployTarget } from './resolveDeployTarget.js';
|
|
13
|
+
import { describeServiceUnavailable, getDeployErrorMessage } from './serviceUnavailable.js';
|
|
14
14
|
export async function findUserApplication(options) {
|
|
15
15
|
const { cliConfig, create, organizationId, output, title, unattended = false } = options;
|
|
16
16
|
const spin = spinner('Checking application info...').start();
|
|
@@ -73,7 +73,7 @@ export async function findUserApplicationForStudio(options) {
|
|
|
73
73
|
} catch (error) {
|
|
74
74
|
spin.fail();
|
|
75
75
|
deployDebug('Error finding user application', error);
|
|
76
|
-
output.error(`Failed to resolve deploy target: ${
|
|
76
|
+
output.error(`Failed to resolve deploy target: ${getDeployErrorMessage(error)}`, {
|
|
77
77
|
exit: exitCodes.RUNTIME_ERROR
|
|
78
78
|
});
|
|
79
79
|
return {
|
|
@@ -180,7 +180,8 @@ export async function findUserApplicationForStudio(options) {
|
|
|
180
180
|
}
|
|
181
181
|
// otherwise, it's a fatal error
|
|
182
182
|
deployDebug('Error creating user application from config', e);
|
|
183
|
-
|
|
183
|
+
const failure = urlType === 'external' ? 'Error registering external studio' : 'Error creating studio hostname';
|
|
184
|
+
output.error(`${failure}: ${describeServiceUnavailable(e) ?? (e instanceof Error ? e.message : e)}`, {
|
|
184
185
|
exit: exitCodes.RUNTIME_ERROR
|
|
185
186
|
});
|
|
186
187
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/findUserApplication.ts"],"sourcesContent":["/**\n * Finds (or creates) the user application a deploy targets — the interactive\n * adapter that turns the resolveDeployTarget verdicts into prompts, creation,\n * and exits. Dry runs consume the same verdicts read-only (see deployChecks).\n */\n\nimport {type CliConfig, exitCodes, type Output} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {select, Separator, spinner} from '@sanity/cli-core/ux'\n\nimport {\n createUserApplication,\n type UserApplication,\n type UserApplicationResolved,\n} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {createFailFastReporter} from '../../util/checks.js'\nimport {describeAppTarget, describeAppTargetError, describeStudioTarget} from './deployChecks.js'\nimport {deployDebug} from './deployDebug.js'\nimport {resolveAppDeployTarget, resolveStudioDeployTarget} from './resolveDeployTarget.js'\n\ninterface FindUserApplicationOptions {\n cliConfig: CliConfig\n organizationId: string\n output: Output\n\n create?: boolean\n title?: string\n unattended?: boolean\n}\n\nexport async function findUserApplication(\n options: FindUserApplicationOptions,\n): Promise<UserApplicationResolved | null> {\n const {cliConfig, create, organizationId, output, title, unattended = false} = options\n const spin = spinner('Checking application info...').start()\n\n let resolution\n try {\n resolution = await resolveAppDeployTarget({appId: getAppId(cliConfig), create, organizationId})\n deployDebug('Resolved app deploy target', resolution)\n } catch (error) {\n spin.clear()\n deployDebug('Error finding user application for app', error)\n output.error(describeAppTargetError(error, organizationId), {exit: exitCodes.RUNTIME_ERROR})\n return null\n }\n\n if (resolution.type === 'found') {\n spin.succeed()\n return resolution.application\n }\n\n // null tells the caller to create. Unattended runs can only create with a\n // title; picking among existing apps (needs-input) always needs a prompt.\n if (resolution.type === 'would-create' && (!unattended || title)) {\n spin.info('No application ID configured')\n return null\n }\n if (resolution.type === 'needs-input' && !unattended) {\n spin.info('No application ID configured')\n return promptForExistingApp(resolution.existing)\n }\n\n spin.clear()\n // 'blocked' diagnoses as a skip (its root cause fails an earlier check), so it\n // needs an explicit exit here to not fall through to application creation\n if (resolution.type === 'blocked') {\n output.error(resolution.message, {exit: exitCodes.RUNTIME_ERROR})\n return null\n }\n createFailFastReporter(output).report(describeAppTarget(resolution))\n return null\n}\n\ninterface FindUserApplicationForStudioOptions {\n isExternal: boolean\n output: Output\n projectId: string\n\n appId?: string\n studioHost?: string\n title?: string\n unattended?: boolean\n urlFlag?: string\n}\n\nexport async function findUserApplicationForStudio(\n options: FindUserApplicationForStudioOptions,\n): Promise<{application: UserApplication | null; created: boolean}> {\n const {\n appId,\n isExternal,\n output,\n projectId,\n studioHost,\n title,\n unattended = false,\n urlFlag,\n } = options\n const urlType = isExternal ? 'external' : 'internal'\n const spin = spinner('Checking project info').start()\n\n let resolution\n try {\n resolution = await resolveStudioDeployTarget({\n appId,\n isExternal,\n projectId,\n studioHost,\n urlFlag,\n })\n deployDebug('Resolved studio deploy target', resolution)\n } catch (error) {\n spin.fail()\n deployDebug('Error finding user application', error)\n output.error(`Failed to resolve deploy target: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n return {application: null, created: false}\n }\n\n if (resolution.type === 'found') {\n spin.succeed()\n return {application: resolution.application, created: false}\n }\n\n // The configured host isn't registered yet — a deploy registers it without\n // prompting, so this returns a newly created studio.\n if (resolution.type === 'would-create') {\n spin.succeed()\n const application = await createFromConfiguredHost({\n appHost: resolution.appHost,\n output,\n projectId,\n title,\n urlType,\n })\n return {application, created: application !== null}\n }\n\n if (resolution.type === 'needs-input' && !unattended) {\n spin.succeed()\n // Nothing to select from — the caller prompts for a brand new host\n if (resolution.existing.length === 0) return {application: null, created: false}\n // A selected existing studio is an update; \"new\" returns null and the caller registers it.\n return {\n application: await promptForExistingStudio({existing: resolution.existing, urlType}),\n created: false,\n }\n }\n\n spin.fail()\n // 'blocked' diagnoses as a skip (its root cause fails an earlier check), so it\n // needs an explicit exit here\n if (resolution.type === 'blocked') {\n output.error(resolution.message, {exit: exitCodes.RUNTIME_ERROR})\n return {application: null, created: false}\n }\n createFailFastReporter(output).report(describeStudioTarget(resolution, {isExternal}))\n return {application: null, created: false}\n}\n\n/**\n * The host is configured (studioHost or --url) but not registered yet:\n * a deploy registers it without prompting.\n */\nasync function createFromConfiguredHost({\n appHost,\n output,\n projectId,\n title,\n urlType,\n}: {\n appHost: string\n output: Output\n projectId: string\n title?: string\n urlType: 'external' | 'internal'\n}): Promise<UserApplication | null> {\n if (urlType === 'external') {\n output.log('Your project has not been registered with an external studio URL.')\n output.log(`Registering ${appHost}`)\n } else {\n output.log('Your project has not been assigned a studio hostname.')\n output.log(`Creating https://${appHost}.sanity.studio`)\n }\n output.log('')\n\n const spin = spinner(\n urlType === 'external' ? 'Registering external studio' : 'Creating studio hostname',\n ).start()\n\n try {\n const response = await createUserApplication({\n appType: 'studio',\n body: {appHost, title, type: 'studio', urlType},\n projectId,\n })\n spin.succeed()\n return response\n } catch (e) {\n spin.fail()\n // if the name is taken, it should return a 409 so we relay to the user\n if ([402, 409].includes(e?.statusCode)) {\n output.error(e?.response?.body?.message || 'Bad request', {exit: exitCodes.RUNTIME_ERROR})\n return null\n }\n // otherwise, it's a fatal error\n deployDebug('Error creating user application from config', e)\n output.error(\n `Error creating user application from config: ${e instanceof Error ? e.message : e}`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n return null\n }\n}\n\nasync function promptForExistingApp(\n existing: UserApplicationResolved[],\n): Promise<UserApplicationResolved | null> {\n const choices = existing.map((app) => ({name: app.title ?? app.appHost, value: app.appHost}))\n\n const selected = await select({\n choices: [\n {name: 'New application deployment', value: 'NEW_APP'},\n new Separator(' ════ Existing applications: ════ '),\n ...choices,\n ],\n loop: false,\n message: 'Would you like to create a new application deployment, or deploy to an existing one?',\n pageSize: 10,\n })\n\n if (selected === 'NEW_APP') {\n return null\n }\n\n return existing.find((app) => app.appHost === selected)!\n}\n\nasync function promptForExistingStudio({\n existing,\n urlType,\n}: {\n existing: UserApplication[]\n urlType: 'external' | 'internal'\n}): Promise<UserApplication | null> {\n const newLabel =\n urlType === 'external' ? 'Register new external studio URL' : 'Create new studio hostname'\n const selectMessage =\n urlType === 'external'\n ? 'Select existing external studio, or register a new one'\n : 'Select existing studio hostname, or create a new one'\n\n const choices = existing.map((app) => ({name: app.title ?? app.appHost, value: app.appHost}))\n\n const selected = await select({\n choices: [{name: newLabel, value: 'NEW_STUDIO'}, new Separator(), ...choices],\n message: selectMessage,\n })\n\n if (selected === 'NEW_STUDIO') {\n return null\n }\n\n return existing.find((app) => app.appHost === selected)!\n}\n"],"names":["exitCodes","getErrorMessage","select","Separator","spinner","createUserApplication","getAppId","createFailFastReporter","describeAppTarget","describeAppTargetError","describeStudioTarget","deployDebug","resolveAppDeployTarget","resolveStudioDeployTarget","findUserApplication","options","cliConfig","create","organizationId","output","title","unattended","spin","start","resolution","appId","error","clear","exit","RUNTIME_ERROR","type","succeed","application","info","promptForExistingApp","existing","message","report","findUserApplicationForStudio","isExternal","projectId","studioHost","urlFlag","urlType","fail","created","createFromConfiguredHost","appHost","length","promptForExistingStudio","log","response","appType","body","e","includes","statusCode","Error","choices","map","app","name","value","selected","loop","pageSize","find","newLabel","selectMessage"],"mappings":"AAAA;;;;CAIC,GAED,SAAwBA,SAAS,QAAoB,mBAAkB;AACvE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,MAAM,EAAEC,SAAS,EAAEC,OAAO,QAAO,sBAAqB;AAE9D,SACEC,qBAAqB,QAGhB,qCAAoC;AAC3C,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,sBAAsB,QAAO,uBAAsB;AAC3D,SAAQC,iBAAiB,EAAEC,sBAAsB,EAAEC,oBAAoB,QAAO,oBAAmB;AACjG,SAAQC,WAAW,QAAO,mBAAkB;AAC5C,SAAQC,sBAAsB,EAAEC,yBAAyB,QAAO,2BAA0B;AAY1F,OAAO,eAAeC,oBACpBC,OAAmC;IAEnC,MAAM,EAACC,SAAS,EAAEC,MAAM,EAAEC,cAAc,EAAEC,MAAM,EAAEC,KAAK,EAAEC,aAAa,KAAK,EAAC,GAAGN;IAC/E,MAAMO,OAAOlB,QAAQ,gCAAgCmB,KAAK;IAE1D,IAAIC;IACJ,IAAI;QACFA,aAAa,MAAMZ,uBAAuB;YAACa,OAAOnB,SAASU;YAAYC;YAAQC;QAAc;QAC7FP,YAAY,8BAA8Ba;IAC5C,EAAE,OAAOE,OAAO;QACdJ,KAAKK,KAAK;QACVhB,YAAY,0CAA0Ce;QACtDP,OAAOO,KAAK,CAACjB,uBAAuBiB,OAAOR,iBAAiB;YAACU,MAAM5B,UAAU6B,aAAa;QAAA;QAC1F,OAAO;IACT;IAEA,IAAIL,WAAWM,IAAI,KAAK,SAAS;QAC/BR,KAAKS,OAAO;QACZ,OAAOP,WAAWQ,WAAW;IAC/B;IAEA,0EAA0E;IAC1E,0EAA0E;IAC1E,IAAIR,WAAWM,IAAI,KAAK,kBAAmB,CAAA,CAACT,cAAcD,KAAI,GAAI;QAChEE,KAAKW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AS,CAAA;YAACC,MAAMD,IAAIxC,KAAK,IAAIwC,IAAIb,OAAO;YAAEe,OAAOF,IAAIb,OAAO;QAAA,CAAA;IAE1F,MAAMgB,WAAW,MAAM7D,OAAO;QAC5BwD,SAAS;YAAC;gBAACG,MAAMM;gBAAUL,OAAO;YAAY;YAAG,IAAI3D;eAAgBuD;SAAQ;QAC7EtB,SAASgC;IACX;IAEA,IAAIL,aAAa,cAAc;QAC7B,OAAO;IACT;IAEA,OAAO5B,SAAS+B,IAAI,CAAC,CAACN,MAAQA,IAAIb,OAAO,KAAKgB;AAChD"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/findUserApplication.ts"],"sourcesContent":["/**\n * Finds (or creates) the user application a deploy targets — the interactive\n * adapter that turns the resolveDeployTarget verdicts into prompts, creation,\n * and exits. Dry runs consume the same verdicts read-only (see deployChecks).\n */\n\nimport {type CliConfig, exitCodes, type Output} from '@sanity/cli-core'\nimport {select, Separator, spinner} from '@sanity/cli-core/ux'\n\nimport {\n createUserApplication,\n type UserApplication,\n type UserApplicationResolved,\n} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {createFailFastReporter} from '../../util/checks.js'\nimport {describeAppTarget, describeAppTargetError, describeStudioTarget} from './deployChecks.js'\nimport {deployDebug} from './deployDebug.js'\nimport {resolveAppDeployTarget, resolveStudioDeployTarget} from './resolveDeployTarget.js'\nimport {describeServiceUnavailable, getDeployErrorMessage} from './serviceUnavailable.js'\n\ninterface FindUserApplicationOptions {\n cliConfig: CliConfig\n organizationId: string\n output: Output\n\n create?: boolean\n title?: string\n unattended?: boolean\n}\n\nexport async function findUserApplication(\n options: FindUserApplicationOptions,\n): Promise<UserApplicationResolved | null> {\n const {cliConfig, create, organizationId, output, title, unattended = false} = options\n const spin = spinner('Checking application info...').start()\n\n let resolution\n try {\n resolution = await resolveAppDeployTarget({appId: getAppId(cliConfig), create, organizationId})\n deployDebug('Resolved app deploy target', resolution)\n } catch (error) {\n spin.clear()\n deployDebug('Error finding user application for app', error)\n output.error(describeAppTargetError(error, organizationId), {exit: exitCodes.RUNTIME_ERROR})\n return null\n }\n\n if (resolution.type === 'found') {\n spin.succeed()\n return resolution.application\n }\n\n // null tells the caller to create. Unattended runs can only create with a\n // title; picking among existing apps (needs-input) always needs a prompt.\n if (resolution.type === 'would-create' && (!unattended || title)) {\n spin.info('No application ID configured')\n return null\n }\n if (resolution.type === 'needs-input' && !unattended) {\n spin.info('No application ID configured')\n return promptForExistingApp(resolution.existing)\n }\n\n spin.clear()\n // 'blocked' diagnoses as a skip (its root cause fails an earlier check), so it\n // needs an explicit exit here to not fall through to application creation\n if (resolution.type === 'blocked') {\n output.error(resolution.message, {exit: exitCodes.RUNTIME_ERROR})\n return null\n }\n createFailFastReporter(output).report(describeAppTarget(resolution))\n return null\n}\n\ninterface FindUserApplicationForStudioOptions {\n isExternal: boolean\n output: Output\n projectId: string\n\n appId?: string\n studioHost?: string\n title?: string\n unattended?: boolean\n urlFlag?: string\n}\n\nexport async function findUserApplicationForStudio(\n options: FindUserApplicationForStudioOptions,\n): Promise<{application: UserApplication | null; created: boolean}> {\n const {\n appId,\n isExternal,\n output,\n projectId,\n studioHost,\n title,\n unattended = false,\n urlFlag,\n } = options\n const urlType = isExternal ? 'external' : 'internal'\n const spin = spinner('Checking project info').start()\n\n let resolution\n try {\n resolution = await resolveStudioDeployTarget({\n appId,\n isExternal,\n projectId,\n studioHost,\n urlFlag,\n })\n deployDebug('Resolved studio deploy target', resolution)\n } catch (error) {\n spin.fail()\n deployDebug('Error finding user application', error)\n output.error(`Failed to resolve deploy target: ${getDeployErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n return {application: null, created: false}\n }\n\n if (resolution.type === 'found') {\n spin.succeed()\n return {application: resolution.application, created: false}\n }\n\n // The configured host isn't registered yet — a deploy registers it without\n // prompting, so this returns a newly created studio.\n if (resolution.type === 'would-create') {\n spin.succeed()\n const application = await createFromConfiguredHost({\n appHost: resolution.appHost,\n output,\n projectId,\n title,\n urlType,\n })\n return {application, created: application !== null}\n }\n\n if (resolution.type === 'needs-input' && !unattended) {\n spin.succeed()\n // Nothing to select from — the caller prompts for a brand new host\n if (resolution.existing.length === 0) return {application: null, created: false}\n // A selected existing studio is an update; \"new\" returns null and the caller registers it.\n return {\n application: await promptForExistingStudio({existing: resolution.existing, urlType}),\n created: false,\n }\n }\n\n spin.fail()\n // 'blocked' diagnoses as a skip (its root cause fails an earlier check), so it\n // needs an explicit exit here\n if (resolution.type === 'blocked') {\n output.error(resolution.message, {exit: exitCodes.RUNTIME_ERROR})\n return {application: null, created: false}\n }\n createFailFastReporter(output).report(describeStudioTarget(resolution, {isExternal}))\n return {application: null, created: false}\n}\n\n/**\n * The host is configured (studioHost or --url) but not registered yet:\n * a deploy registers it without prompting.\n */\nasync function createFromConfiguredHost({\n appHost,\n output,\n projectId,\n title,\n urlType,\n}: {\n appHost: string\n output: Output\n projectId: string\n title?: string\n urlType: 'external' | 'internal'\n}): Promise<UserApplication | null> {\n if (urlType === 'external') {\n output.log('Your project has not been registered with an external studio URL.')\n output.log(`Registering ${appHost}`)\n } else {\n output.log('Your project has not been assigned a studio hostname.')\n output.log(`Creating https://${appHost}.sanity.studio`)\n }\n output.log('')\n\n const spin = spinner(\n urlType === 'external' ? 'Registering external studio' : 'Creating studio hostname',\n ).start()\n\n try {\n const response = await createUserApplication({\n appType: 'studio',\n body: {appHost, title, type: 'studio', urlType},\n projectId,\n })\n spin.succeed()\n return response\n } catch (e) {\n spin.fail()\n // if the name is taken, it should return a 409 so we relay to the user\n if ([402, 409].includes(e?.statusCode)) {\n output.error(e?.response?.body?.message || 'Bad request', {exit: exitCodes.RUNTIME_ERROR})\n return null\n }\n // otherwise, it's a fatal error\n deployDebug('Error creating user application from config', e)\n const failure =\n urlType === 'external'\n ? 'Error registering external studio'\n : 'Error creating studio hostname'\n output.error(\n `${failure}: ${describeServiceUnavailable(e) ?? (e instanceof Error ? e.message : e)}`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n return null\n }\n}\n\nasync function promptForExistingApp(\n existing: UserApplicationResolved[],\n): Promise<UserApplicationResolved | null> {\n const choices = existing.map((app) => ({name: app.title ?? app.appHost, value: app.appHost}))\n\n const selected = await select({\n choices: [\n {name: 'New application deployment', value: 'NEW_APP'},\n new Separator(' ════ Existing applications: ════ '),\n ...choices,\n ],\n loop: false,\n message: 'Would you like to create a new application deployment, or deploy to an existing one?',\n pageSize: 10,\n })\n\n if (selected === 'NEW_APP') {\n return null\n }\n\n return existing.find((app) => app.appHost === selected)!\n}\n\nasync function promptForExistingStudio({\n existing,\n urlType,\n}: {\n existing: UserApplication[]\n urlType: 'external' | 'internal'\n}): Promise<UserApplication | null> {\n const newLabel =\n urlType === 'external' ? 'Register new external studio URL' : 'Create new studio hostname'\n const selectMessage =\n urlType === 'external'\n ? 'Select existing external studio, or register a new one'\n : 'Select existing studio hostname, or create a new one'\n\n const choices = existing.map((app) => ({name: app.title ?? app.appHost, value: app.appHost}))\n\n const selected = await select({\n choices: [{name: newLabel, value: 'NEW_STUDIO'}, new Separator(), ...choices],\n message: selectMessage,\n })\n\n if (selected === 'NEW_STUDIO') {\n return null\n }\n\n return existing.find((app) => app.appHost === selected)!\n}\n"],"names":["exitCodes","select","Separator","spinner","createUserApplication","getAppId","createFailFastReporter","describeAppTarget","describeAppTargetError","describeStudioTarget","deployDebug","resolveAppDeployTarget","resolveStudioDeployTarget","describeServiceUnavailable","getDeployErrorMessage","findUserApplication","options","cliConfig","create","organizationId","output","title","unattended","spin","start","resolution","appId","error","clear","exit","RUNTIME_ERROR","type","succeed","application","info","promptForExistingApp","existing","message","report","findUserApplicationForStudio","isExternal","projectId","studioHost","urlFlag","urlType","fail","created","createFromConfiguredHost","appHost","length","promptForExistingStudio","log","response","appType","body","e","includes","statusCode","failure","Error","choices","map","app","name","value","selected","loop","pageSize","find","newLabel","selectMessage"],"mappings":"AAAA;;;;CAIC,GAED,SAAwBA,SAAS,QAAoB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