@sanity/cli 8.36.0 → 8.37.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/dist/actions/deploy/deployApp.js +20 -7
- package/dist/actions/deploy/deployApp.js.map +1 -1
- package/dist/actions/deploy/deployChecks.js +2 -1
- package/dist/actions/deploy/deployChecks.js.map +1 -1
- package/dist/actions/deploy/deployDashboardConfig.js +11 -5
- package/dist/actions/deploy/deployDashboardConfig.js.map +1 -1
- package/dist/actions/deploy/deployRunner.js.map +1 -1
- package/dist/actions/deploy/deployStudio.js +24 -7
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/deploy/resolveDeployTarget.js +2 -2
- package/dist/actions/deploy/resolveDeployTarget.js.map +1 -1
- package/dist/actions/targets/resolveCommandTarget.js +130 -0
- package/dist/actions/targets/resolveCommandTarget.js.map +1 -0
- package/dist/actions/undeploy/runUndeploy.js +19 -3
- package/dist/actions/undeploy/runUndeploy.js.map +1 -1
- package/dist/commands/build.js +8 -1
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/documents/query.js +26 -11
- package/dist/commands/documents/query.js.map +1 -1
- package/dist/prompts/promptForProject.js +9 -3
- package/dist/prompts/promptForProject.js.map +1 -1
- package/dist/services/blueprints.js +18 -0
- package/dist/services/blueprints.js.map +1 -0
- package/dist/util/checkoutBlueprint.js +33 -0
- package/dist/util/checkoutBlueprint.js.map +1 -0
- package/dist/util/sharedFlags.js +10 -0
- package/dist/util/sharedFlags.js.map +1 -1
- package/oclif.manifest.json +103 -96
- package/package.json +4 -4
|
@@ -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 {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;
|
|
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 deployedBy?: string | null\n /** Resolved server-side, so it stays out of the local payload. */\n installationId?: string\n organizationName?: string | null\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;AAmD7D;;;;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,U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ity/cli-build/_internal/extract';
|
|
5
5
|
import { exitCodes } from '@sanity/cli-core';
|
|
6
6
|
import { spinner } from '@sanity/cli-core/ux';
|
|
7
|
-
import { createStudio, deployWorkbenchApp, fetchDeploySummaryDetails, formatDeploySummary, getApplicationUrl, getWorkbench, getWorkbenchUrl, readAppIcon, selectWorkbenchAppId, toWorkbenchPayload } from '@sanity/workbench-cli/deploy';
|
|
7
|
+
import { createStudio, deployWorkbenchApp, fetchDeploySummaryDetails, fetchOrganizationSummary, formatDeploySummary, getApplicationUrl, getWorkbench, getWorkbenchUrl, readAppIcon, selectWorkbenchAppId, toWorkbenchPayload } from '@sanity/workbench-cli/deploy';
|
|
8
8
|
import { c as createTar } from 'tar';
|
|
9
9
|
import { createDeployment } from '../../services/userApplications.js';
|
|
10
10
|
import { getAppId } from '../../util/appId.js';
|
|
@@ -67,6 +67,10 @@ export function deployStudio(options) {
|
|
|
67
67
|
let workbenchApp;
|
|
68
68
|
let externalUrl;
|
|
69
69
|
let targetAppId = appId;
|
|
70
|
+
// Every Dashboard URL below is built on the org's host slug (`--json` included); the
|
|
71
|
+
// deployer lookup overlaps the build.
|
|
72
|
+
const organization = workbench && organizationId ? fetchOrganizationSummary(organizationId) : undefined;
|
|
73
|
+
const summaryDetails = organization && organizationId ? fetchDeploySummaryDetails(organizationId, organization) : undefined;
|
|
70
74
|
if (workbench) {
|
|
71
75
|
reporter.report(organizationId ? {
|
|
72
76
|
message: `Organization: ${organizationId}`,
|
|
@@ -84,6 +88,7 @@ export function deployStudio(options) {
|
|
|
84
88
|
});
|
|
85
89
|
workbenchApp = (await checkStudioTarget(reporter, {
|
|
86
90
|
appId: targetAppId,
|
|
91
|
+
hostSlug: (await organization)?.hostSlug,
|
|
87
92
|
isWorkbenchApp: true,
|
|
88
93
|
organizationId,
|
|
89
94
|
slug: workbench.slug,
|
|
@@ -115,7 +120,6 @@ export function deployStudio(options) {
|
|
|
115
120
|
// Read up front so a bad icon path fails before we create or build.
|
|
116
121
|
const appIcon = !dryRun && workbench?.icon ? await readAppIcon(workDir, workbench.icon) : undefined;
|
|
117
122
|
const startedAt = Date.now();
|
|
118
|
-
const summaryDetails = workbench && organizationId && !flags.json ? fetchDeploySummaryDetails(organizationId) : undefined;
|
|
119
123
|
// Create the studio before the build so the bundle carries its real id. A
|
|
120
124
|
// redeploy already has it from `deployment.appId`; a dry run skips creation.
|
|
121
125
|
let applicationId = targetAppId;
|
|
@@ -221,26 +225,30 @@ export function deployStudio(options) {
|
|
|
221
225
|
workDir,
|
|
222
226
|
workspaces: toWorkspaces(studioManifest)
|
|
223
227
|
});
|
|
228
|
+
const hostSlug = (await organization)?.hostSlug;
|
|
224
229
|
const url = getApplicationUrl({
|
|
225
230
|
id: applicationId,
|
|
226
231
|
organizationId,
|
|
227
232
|
slug: workbench.slug,
|
|
228
233
|
type: 'studio'
|
|
229
|
-
});
|
|
234
|
+
}, hostSlug);
|
|
230
235
|
const durationMs = Date.now() - startedAt;
|
|
236
|
+
const { organizationName = null, userName = null } = await summaryDetails ?? {};
|
|
231
237
|
output.log(formatDeploySummary({
|
|
232
|
-
...await summaryDetails,
|
|
233
238
|
applicationId,
|
|
234
239
|
created: applicationCreated,
|
|
235
240
|
durationMs,
|
|
236
241
|
organizationId,
|
|
242
|
+
organizationName,
|
|
237
243
|
showAppIdHint: !appId,
|
|
238
244
|
title: appTitle,
|
|
239
245
|
type: 'studio',
|
|
240
|
-
url
|
|
246
|
+
url,
|
|
247
|
+
userName
|
|
241
248
|
}));
|
|
242
249
|
if (isExternallyHosted) logExternalHost({
|
|
243
250
|
built: flags.build,
|
|
251
|
+
hostSlug,
|
|
244
252
|
organizationId,
|
|
245
253
|
output,
|
|
246
254
|
sourceDir
|
|
@@ -248,6 +256,8 @@ export function deployStudio(options) {
|
|
|
248
256
|
return {
|
|
249
257
|
action: applicationCreated ? 'create' : 'update',
|
|
250
258
|
application: workbenchApp ?? null,
|
|
259
|
+
deployedBy: userName,
|
|
260
|
+
organizationName,
|
|
251
261
|
payload,
|
|
252
262
|
url
|
|
253
263
|
};
|
|
@@ -433,12 +443,19 @@ function toWorkspaces(manifest) {
|
|
|
433
443
|
title: workspace.title
|
|
434
444
|
}));
|
|
435
445
|
}
|
|
436
|
-
/** Tells the customer what their host must do for the Dashboard to load the studio from it. */ function logExternalHost({ built, organizationId, output, sourceDir }) {
|
|
446
|
+
/** Tells the customer what their host must do for the Dashboard to load the studio from it. */ function logExternalHost({ built, hostSlug, organizationId, output, sourceDir }) {
|
|
437
447
|
const dir = `${relative(process.cwd(), sourceDir) || '.'}/`;
|
|
448
|
+
// The Dashboard is served on both the org ID host and the slug host, so the studio's host must allow both.
|
|
449
|
+
const origins = [
|
|
450
|
+
getWorkbenchUrl(organizationId),
|
|
451
|
+
getWorkbenchUrl(organizationId, hostSlug)
|
|
452
|
+
];
|
|
438
453
|
output.log(`
|
|
439
454
|
The Dashboard loads this studio from your host, which must:
|
|
440
455
|
1. Serve ${dir} unchanged at the root of its URL (/mf-manifest.json, /remoteEntry-*.js, /static/*)
|
|
441
|
-
2. Send Access-Control-Allow-Origin for ${
|
|
456
|
+
2. Send Access-Control-Allow-Origin for ${[
|
|
457
|
+
...new Set(origins)
|
|
458
|
+
].join(' and ')}
|
|
442
459
|
3. Respond without cookies or a sign-in${built ? `\n\nThis deploy rebuilt ${dir}: copy it to your host before opening the studio in the Dashboard.` : ''}`);
|
|
443
460
|
}
|
|
444
461
|
function studioBuildSkipReason({ build, isLegacyExternal }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/deployStudio.ts"],"sourcesContent":["import {basename, dirname, relative} from 'node:path'\nimport {styleText} from 'node:util'\nimport {createGzip, type Gzip} from 'node:zlib'\n\nimport {formatSchemaValidation, SchemaExtractionError} from '@sanity/cli-build/_internal/extract'\nimport {exitCodes} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {\n type BrettAccess,\n type BrettWorkspace,\n createStudio,\n deployWorkbenchApp,\n fetchDeploySummaryDetails,\n formatDeploySummary,\n getApplicationUrl,\n getWorkbench,\n getWorkbenchUrl,\n readAppIcon,\n selectWorkbenchAppId,\n toWorkbenchPayload,\n} from '@sanity/workbench-cli/deploy'\nimport {type StudioManifest} from 'sanity'\nimport {c as createTar} from 'tar'\n\nimport {createDeployment, type UserApplication} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {NO_ORGANIZATION_ID, NO_PROJECT_ID} from '../../util/errorMessages.js'\nimport {buildStudio} from '../build/buildStudio.js'\nimport {checkBlueprintManaged} from './blueprintManaged.js'\nimport {createStudioUserApplication} from './createUserApplication.js'\nimport {\n checkAutoUpdates,\n checkBuild,\n checkExternalUrl,\n checkPackageVersion,\n checkStudioTarget,\n type DeployCheckReporter,\n verifyOutputDir,\n} from './deployChecks.js'\nimport {deployDebug} from './deployDebug.js'\nimport {listDeploymentFiles, reportInterfaces} from './deploymentPlan.js'\nimport {type DeployPayload, type DeployResult, runDeploy} from './deployRunner.js'\nimport {deployStudioSchemasAndManifests} from './deployStudioSchemasAndManifests.js'\nimport {findUserApplicationForStudio} from './findUserApplication.js'\nimport {type DeployAppOptions} from './types.js'\n\nconst STUDIO_PACKAGE = 'sanity'\n\nexport function deployStudio(options: DeployAppOptions): Promise<void> {\n return runDeploy(options, {\n listFiles: ({flags, projectRoot, sourceDir}) =>\n flags.external ? Promise.resolve([]) : listDeploymentFiles(sourceDir, projectRoot.directory),\n run: runStudioDeployment,\n type: 'studio',\n })\n}\n\n/** Validates the deploy, extracts and uploads the schema, and ships the build. */\nasync function runStudioDeployment(\n options: DeployAppOptions,\n reporter: DeployCheckReporter,\n): Promise<DeployResult | void> {\n const {cliConfig, flags, output, sourceDir} = options\n const workDir = options.projectRoot.directory\n const isExternal = !!flags.external\n const workbench = getWorkbench(cliConfig)\n const isWorkbenchApp = workbench !== null\n const projectId = cliConfig.api?.projectId\n const organizationId = cliConfig.app?.organizationId\n const appId = getAppId(cliConfig)\n const dryRun = !!flags['dry-run']\n // A legacy external studio only registers its URL; a federated one is built\n // and deployed like a hosted one, minus the upload.\n const isLegacyExternal = isExternal && !isWorkbenchApp\n\n const appTitle = workbench ? flags.title?.trim() || workbench.title : ''\n\n const isAutoUpdating = checkAutoUpdates(reporter, {cliConfig, flags})\n\n const version = await checkPackageVersion(reporter, {\n moduleName: STUDIO_PACKAGE,\n workDir,\n })\n\n reporter.report(\n projectId\n ? {message: `Project: ${projectId}`, status: 'pass'}\n : {\n message: NO_PROJECT_ID,\n solution: 'Add `api.projectId` to sanity.cli.ts',\n status: 'fail',\n },\n )\n\n await checkBlueprintManaged(reporter, {kind: 'studio', projectRootDir: workDir})\n\n // Workbench studios deploy to Brett (which needs the org); plain studios\n // resolve/create on user-applications, unchanged.\n let application: UserApplication | null = null\n let studioCreated = false\n let workbenchApp: {externalUrl?: string | null} | undefined\n let externalUrl: string | undefined\n let targetAppId = appId\n if (workbench) {\n reporter.report(\n organizationId\n ? {message: `Organization: ${organizationId}`, status: 'pass'}\n : {\n message: NO_ORGANIZATION_ID,\n solution: 'Add `app.organizationId` to sanity.cli.ts',\n status: 'fail',\n },\n )\n targetAppId = await selectWorkbenchAppId({appId, flags, organizationId, type: 'studio'})\n workbenchApp = (\n await checkStudioTarget(reporter, {\n appId: targetAppId,\n isWorkbenchApp: true,\n organizationId,\n slug: workbench.slug,\n title: appTitle,\n })\n )?.application\n if (isExternal) externalUrl = checkExternalUrl(reporter, {appId: targetAppId, url: flags.url})\n } else {\n ;({application, created: studioCreated} = await resolveStudioApplication(options, {\n dryRun,\n reporter,\n }))\n }\n // A redeploy follows how the application was registered, so --external is only needed once.\n const isExternallyHosted = isExternal || !!workbenchApp?.externalUrl\n\n // A first deploy mints the app id and the build inlines it; --no-build would\n // ship an existing bundle carrying a different id, so it can't be a first deploy.\n if (workbench && !appId && !flags.build) {\n reporter.report({\n exitCode: exitCodes.USAGE_ERROR,\n message: 'A first deploy cannot skip the build (--no-build)',\n solution: 'Drop --no-build so the new application id is inlined into the build',\n status: 'fail',\n })\n }\n\n // Read up front so a bad icon path fails before we create or build.\n const appIcon =\n !dryRun && workbench?.icon ? await readAppIcon(workDir, workbench.icon) : undefined\n\n const startedAt = Date.now()\n const summaryDetails =\n workbench && organizationId && !flags.json\n ? fetchDeploySummaryDetails(organizationId)\n : undefined\n\n // Create the studio before the build so the bundle carries its real id. A\n // redeploy already has it from `deployment.appId`; a dry run skips creation.\n let applicationId = targetAppId\n let applicationCreated = false\n let rollbackApp: (() => Promise<void>) | undefined\n if (!dryRun && workbench && organizationId && !applicationId) {\n const created = await createStudio({\n externalUrl,\n name: workbench.name,\n organizationId,\n projectId,\n slug: workbench.slug,\n title: appTitle,\n visibility: workbench.visibility,\n })\n workbenchApp = created.application\n applicationId = created.application.id\n rollbackApp = created.rollback\n applicationCreated = true\n }\n\n // A record created above is stranded at its slug (and blocks retries) if any\n // step before it fully deploys fails, so undo the creation on failure.\n try {\n const built = await checkBuild(reporter, {\n build: () =>\n buildStudio({\n applicationId: workbench ? applicationId : undefined,\n autoUpdatesEnabled: isAutoUpdating,\n calledFromDeploy: true,\n cliConfig,\n flags,\n outDir: sourceDir,\n output,\n workDir,\n }),\n skipReason: studioBuildSkipReason({build: flags.build, isLegacyExternal}),\n successMessage: 'Studio built',\n })\n\n let mfManifest = built?.mfManifest\n // A federated build has already read its manifest; anything else verifies the directory.\n if (mfManifest === undefined && !isLegacyExternal) {\n mfManifest = await verifyOutputDir({isWorkbenchApp, reporter, sourceDir})\n }\n\n const interfaces = workbench ? reportInterfaces(reporter, workbench) : null\n\n const payload: DeployPayload = {\n appId: appId ?? null,\n isAutoUpdating,\n ...(organizationId ? {organizationId} : {}),\n ...(projectId ? {projectId} : {}),\n type: 'studio',\n version,\n ...toWorkbenchPayload(workbench, {interfaces, title: appTitle}),\n }\n\n // Dry run stops here — everything below mutates.\n if (dryRun) return {application: null, payload}\n\n // A real deploy has already exited if anything failed; landing here without a\n // resolved version means the deploy target was never resolved.\n if (!version) return\n\n const studioManifest = await uploadStudioSchema(options, {\n applicationId: workbench ? applicationId : undefined,\n isExternal: isLegacyExternal,\n })\n // The studio was created (or resolved from `deployment.appId`) before the\n // build, so this only ships the deployment; plain studios use user-applications.\n if (workbench && organizationId && applicationId) {\n if (!mfManifest) throw new Error('The federated build produced no manifest.')\n await deployWorkbenchApp({\n access: toAccess(studioManifest),\n app: cliConfig.app,\n applicationId,\n icon: appIcon,\n isApp: false,\n isAutoUpdating,\n isExternal: isExternallyHosted,\n label: 'Deploying studio',\n mfManifest,\n // Once the deployment is live, a metadata-sync failure must not delete\n // the studio.\n onDeployed: () => {\n rollbackApp = undefined\n },\n slug: workbench.slug,\n sourceDir,\n title: appTitle,\n version,\n visibility: workbench.visibility,\n workDir,\n workspaces: toWorkspaces(studioManifest),\n })\n const url = getApplicationUrl({\n id: applicationId,\n organizationId,\n slug: workbench.slug,\n type: 'studio',\n })\n const durationMs = Date.now() - startedAt\n output.log(\n formatDeploySummary({\n ...(await summaryDetails),\n applicationId,\n created: applicationCreated,\n durationMs,\n organizationId,\n showAppIdHint: !appId,\n title: appTitle,\n type: 'studio',\n url,\n }),\n )\n if (isExternallyHosted)\n logExternalHost({built: flags.build, organizationId, output, sourceDir})\n return {\n action: applicationCreated ? 'create' : 'update',\n application: workbenchApp ?? null,\n payload,\n url,\n }\n }\n\n if (!application) return\n const location = await shipStudioDeployment({\n application,\n isAutoUpdating,\n isExternal,\n options,\n studioManifest,\n version,\n })\n\n return {\n action: studioCreated ? 'create' : 'update',\n application,\n payload,\n url: location,\n }\n } catch (err) {\n await rollbackApp?.()\n throw err\n }\n}\n\n/**\n * Finds the application a real deploy targets, registering a studio host when\n * none is configured. A dry run resolves and reports the target read-only instead.\n */\nasync function resolveStudioApplication(\n options: DeployAppOptions,\n {dryRun, reporter}: {dryRun: boolean; reporter: DeployCheckReporter},\n): Promise<{application: UserApplication | null; created: boolean}> {\n const {cliConfig, flags, output} = options\n const isExternal = !!flags.external\n const appId = getAppId(cliConfig)\n // Sets the title on a newly registered studio; blank falls back to undefined\n const title = flags.title?.trim() || undefined\n\n if (dryRun) {\n await checkStudioTarget(reporter, {\n appId,\n isExternal,\n projectId: cliConfig.api?.projectId,\n studioHost: cliConfig.studioHost,\n title,\n urlFlag: flags.url,\n })\n return {application: null, created: false}\n }\n\n const projectId = cliConfig.api?.projectId ?? ''\n // `created` is true when a configured-but-unregistered host was just registered.\n const {application, created} = await findUserApplicationForStudio({\n appId,\n isExternal,\n output,\n projectId,\n studioHost: cliConfig.studioHost,\n title,\n unattended: !!flags.yes,\n urlFlag: flags.url,\n })\n\n if (!application) {\n if (isExternal) {\n output.log('Your project has not been registered with an external studio URL.')\n output.log('Please enter the full URL where your studio is hosted.')\n } else {\n output.log('Your project has not been assigned a studio hostname.')\n output.log('To deploy your Sanity Studio to our hosted sanity.studio service,')\n output.log('you will need one. Please enter the subdomain you want to use.')\n }\n\n const registered = await createStudioUserApplication({\n projectId,\n title,\n urlType: isExternal ? 'external' : 'internal',\n })\n deployDebug('Created user application', registered)\n return {application: registered, created: true}\n }\n\n deployDebug('Found user application', application)\n return {application, created}\n}\n\n/** Extracts the studio schema and manifest and uploads them to the schema store. */\nasync function uploadStudioSchema(\n options: DeployAppOptions,\n {applicationId, isExternal}: {applicationId?: string; isExternal: boolean},\n): Promise<StudioManifest | null> {\n const {flags, output, projectRoot, sourceDir} = options\n\n let studioManifest: StudioManifest | null = null\n try {\n studioManifest = await deployStudioSchemasAndManifests(\n {\n applicationId,\n configPath: projectRoot.path,\n isExternal,\n outPath: `${sourceDir}/static`,\n schemaRequired: flags['schema-required'],\n verbose: flags.verbose,\n workDir: projectRoot.directory,\n },\n output,\n )\n } catch (error) {\n deployDebug('Error deploying studio schemas and manifests', error)\n if (error instanceof SchemaExtractionError && error.validation?.length) {\n output.error(formatSchemaValidation(error.validation), {exit: exitCodes.RUNTIME_ERROR})\n }\n output.error(`Error deploying studio schemas and manifests: ${error}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (!studioManifest) {\n output.error('Failed to generate studio manifest. Please check your schemas and manifests.', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n return studioManifest\n}\n\nasync function shipStudioDeployment({\n application,\n isAutoUpdating,\n isExternal,\n options,\n studioManifest,\n version,\n}: {\n application: UserApplication\n isAutoUpdating: boolean\n isExternal: boolean\n options: DeployAppOptions\n studioManifest: StudioManifest | null\n version: string\n}): Promise<string> {\n const {cliConfig, output, sourceDir} = options\n\n let tarball: Gzip | undefined\n if (!isExternal) {\n tarball = createTar({cwd: dirname(sourceDir)}, [basename(sourceDir)]).pipe(createGzip())\n }\n\n const spin = spinner(isExternal ? 'Registering studio' : 'Deploying to sanity.studio').start()\n let location: string\n try {\n ;({location} = await createDeployment({\n applicationId: application.id,\n isApp: false,\n isAutoUpdating,\n manifest: studioManifest,\n projectId: cliConfig.api?.projectId,\n tarball,\n version,\n }))\n } catch (error) {\n spin.fail()\n throw error\n }\n spin.succeed()\n\n const named = application.title ? ` — \"${application.title}\"` : ''\n output.log(\n isExternal\n ? `\\nSuccess! Studio registered${named}`\n : `\\nSuccess! Studio deployed to ${styleText('cyan', location)}${named}`,\n )\n\n if (getAppId(cliConfig)) return location\n\n const example = `Example:\nexport default defineCliConfig({\n //…\n deployment: {\n ${styleText('cyan', `appId: '${application.id}'`)},\n },\n //…\n})`\n output.log(`\\nAdd ${styleText('cyan', `appId: '${application.id}'`)}`)\n output.log(`to the \\`deployment\\` section in sanity.cli.js or sanity.cli.ts`)\n output.log(`to avoid prompting for application id on next deploy.`)\n output.log(`\\n${example}`)\n\n return location\n}\n\n/**\n * One `datasets` access entry per unique workspace dataset, with a `resourceId`\n * of `\"<projectId>.<dataset>\"`. Deduped, since workspaces can share a dataset.\n */\nfunction toAccess(manifest: StudioManifest | null): BrettAccess[] {\n const resourceIds = new Set(\n (manifest?.workspaces ?? []).map((w) => `${w.projectId}.${w.dataset}`),\n )\n return [...resourceIds].map(\n (resourceId) => ({resourceId, resourceType: 'dataset'}) satisfies BrettAccess,\n )\n}\n\nfunction toWorkspaces(manifest: StudioManifest | null): BrettWorkspace[] {\n return (manifest?.workspaces ?? []).map((workspace) => ({\n basePath: workspace.basePath,\n dataset: workspace.dataset,\n icon: workspace.icon,\n name: workspace.name,\n projectId: workspace.projectId,\n schemaDescriptorId: workspace.schemaDescriptorId,\n subtitle: workspace.subtitle,\n title: workspace.title,\n }))\n}\n\n/** Tells the customer what their host must do for the Dashboard to load the studio from it. */\nfunction logExternalHost({\n built,\n organizationId,\n output,\n sourceDir,\n}: {\n built: boolean\n organizationId: string\n output: DeployAppOptions['output']\n sourceDir: string\n}): void {\n const dir = `${relative(process.cwd(), sourceDir) || '.'}/`\n output.log(`\nThe Dashboard loads this studio from your host, which must:\n 1. Serve ${dir} unchanged at the root of its URL (/mf-manifest.json, /remoteEntry-*.js, /static/*)\n 2. Send Access-Control-Allow-Origin for ${getWorkbenchUrl(organizationId)}\n 3. Respond without cookies or a sign-in${built ? `\\n\\nThis deploy rebuilt ${dir}: copy it to your host before opening the studio in the Dashboard.` : ''}`)\n}\n\nfunction studioBuildSkipReason({\n build,\n isLegacyExternal,\n}: {\n build: boolean\n isLegacyExternal: boolean\n}) {\n if (isLegacyExternal) return 'Build skipped for externally hosted studios'\n if (!build) return 'Build skipped (--no-build) — validating existing output directory'\n return\n}\n"],"names":["basename","dirname","relative","styleText","createGzip","formatSchemaValidation","SchemaExtractionError","exitCodes","spinner","createStudio","deployWorkbenchApp","fetchDeploySummaryDetails","formatDeploySummary","getApplicationUrl","getWorkbench","getWorkbenchUrl","readAppIcon","selectWorkbenchAppId","toWorkbenchPayload","c","createTar","createDeployment","getAppId","NO_ORGANIZATION_ID","NO_PROJECT_ID","buildStudio","checkBlueprintManaged","createStudioUserApplication","checkAutoUpdates","checkBuild","checkExternalUrl","checkPackageVersion","checkStudioTarget","verifyOutputDir","deployDebug","listDeploymentFiles","reportInterfaces","runDeploy","deployStudioSchemasAndManifests","findUserApplicationForStudio","STUDIO_PACKAGE","deployStudio","options","listFiles","flags","projectRoot","sourceDir","external","Promise","resolve","directory","run","runStudioDeployment","type","reporter","cliConfig","output","workDir","isExternal","workbench","isWorkbenchApp","projectId","api","organizationId","app","appId","dryRun","isLegacyExternal","appTitle","title","trim","isAutoUpdating","version","moduleName","report","message","status","solution","kind","projectRootDir","application","studioCreated","workbenchApp","externalUrl","targetAppId","slug","url","created","resolveStudioApplication","isExternallyHosted","build","exitCode","USAGE_ERROR","appIcon","icon","undefined","startedAt","Date","now","summaryDetails","json","applicationId","applicationCreated","rollbackApp","name","visibility","id","rollback","built","autoUpdatesEnabled","calledFromDeploy","outDir","skipReason","studioBuildSkipReason","successMessage","mfManifest","interfaces","payload","studioManifest","uploadStudioSchema","Error","access","toAccess","isApp","label","onDeployed","workspaces","toWorkspaces","durationMs","log","showAppIdHint","logExternalHost","action","location","shipStudioDeployment","err","studioHost","urlFlag","unattended","yes","registered","urlType","configPath","path","outPath","schemaRequired","verbose","error","validation","length","exit","RUNTIME_ERROR","tarball","cwd","pipe","spin","start","manifest","fail","succeed","named","example","resourceIds","Set","map","w","dataset","resourceId","resourceType","workspace","basePath","schemaDescriptorId","subtitle","dir","process"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,EAAEC,QAAQ,QAAO,YAAW;AACrD,SAAQC,SAAS,QAAO,YAAW;AACnC,SAAQC,UAAU,QAAkB,YAAW;AAE/C,SAAQC,sBAAsB,EAAEC,qBAAqB,QAAO,sCAAqC;AACjG,SAAQC,SAAS,QAAO,mBAAkB;AAC1C,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAGEC,YAAY,EACZC,kBAAkB,EAClBC,yBAAyB,EACzBC,mBAAmB,EACnBC,iBAAiB,EACjBC,YAAY,EACZC,eAAe,EACfC,WAAW,EACXC,oBAAoB,EACpBC,kBAAkB,QACb,+BAA8B;AAErC,SAAQC,KAAKC,SAAS,QAAO,MAAK;AAElC,SAAQC,gBAAgB,QAA6B,qCAAoC;AACz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dP,MAAM,EACNV,SAAS,EAMV;IACC,MAAM+H,MAAM,GAAG3K,SAAS4K,QAAQrB,GAAG,IAAI3G,cAAc,IAAI,CAAC,CAAC;IAC3DU,OAAOyE,GAAG,CAAC,CAAC;;WAEH,EAAE4C,IAAI;0CACyB,EAAE9J,gBAAgBgD,gBAAgB;yCACnC,EAAE6C,QAAQ,CAAC,wBAAwB,EAAEiE,IAAI,kEAAkE,CAAC,GAAG,IAAI;AAC5J;AAEA,SAAS5D,sBAAsB,EAC7BvB,KAAK,EACLvB,gBAAgB,EAIjB;IACC,IAAIA,kBAAkB,OAAO;IAC7B,IAAI,CAACuB,OAAO,OAAO;IACnB;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deployStudio.ts"],"sourcesContent":["import {basename, dirname, relative} from 'node:path'\nimport {styleText} from 'node:util'\nimport {createGzip, type Gzip} from 'node:zlib'\n\nimport {formatSchemaValidation, SchemaExtractionError} from '@sanity/cli-build/_internal/extract'\nimport {exitCodes} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {\n type BrettAccess,\n type BrettWorkspace,\n createStudio,\n deployWorkbenchApp,\n fetchDeploySummaryDetails,\n fetchOrganizationSummary,\n formatDeploySummary,\n getApplicationUrl,\n getWorkbench,\n getWorkbenchUrl,\n readAppIcon,\n selectWorkbenchAppId,\n toWorkbenchPayload,\n} from '@sanity/workbench-cli/deploy'\nimport {type StudioManifest} from 'sanity'\nimport {c as createTar} from 'tar'\n\nimport {createDeployment, type UserApplication} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {NO_ORGANIZATION_ID, NO_PROJECT_ID} from '../../util/errorMessages.js'\nimport {buildStudio} from '../build/buildStudio.js'\nimport {checkBlueprintManaged} from './blueprintManaged.js'\nimport {createStudioUserApplication} from './createUserApplication.js'\nimport {\n checkAutoUpdates,\n checkBuild,\n checkExternalUrl,\n checkPackageVersion,\n checkStudioTarget,\n type DeployCheckReporter,\n verifyOutputDir,\n} from './deployChecks.js'\nimport {deployDebug} from './deployDebug.js'\nimport {listDeploymentFiles, reportInterfaces} from './deploymentPlan.js'\nimport {type DeployPayload, type DeployResult, runDeploy} from './deployRunner.js'\nimport {deployStudioSchemasAndManifests} from './deployStudioSchemasAndManifests.js'\nimport {findUserApplicationForStudio} from './findUserApplication.js'\nimport {type DeployAppOptions} from './types.js'\n\nconst STUDIO_PACKAGE = 'sanity'\n\nexport function deployStudio(options: DeployAppOptions): Promise<void> {\n return runDeploy(options, {\n listFiles: ({flags, projectRoot, sourceDir}) =>\n flags.external ? Promise.resolve([]) : listDeploymentFiles(sourceDir, projectRoot.directory),\n run: runStudioDeployment,\n type: 'studio',\n })\n}\n\n/** Validates the deploy, extracts and uploads the schema, and ships the build. */\nasync function runStudioDeployment(\n options: DeployAppOptions,\n reporter: DeployCheckReporter,\n): Promise<DeployResult | void> {\n const {cliConfig, flags, output, sourceDir} = options\n const workDir = options.projectRoot.directory\n const isExternal = !!flags.external\n const workbench = getWorkbench(cliConfig)\n const isWorkbenchApp = workbench !== null\n const projectId = cliConfig.api?.projectId\n const organizationId = cliConfig.app?.organizationId\n const appId = getAppId(cliConfig)\n const dryRun = !!flags['dry-run']\n // A legacy external studio only registers its URL; a federated one is built\n // and deployed like a hosted one, minus the upload.\n const isLegacyExternal = isExternal && !isWorkbenchApp\n\n const appTitle = workbench ? flags.title?.trim() || workbench.title : ''\n\n const isAutoUpdating = checkAutoUpdates(reporter, {cliConfig, flags})\n\n const version = await checkPackageVersion(reporter, {\n moduleName: STUDIO_PACKAGE,\n workDir,\n })\n\n reporter.report(\n projectId\n ? {message: `Project: ${projectId}`, status: 'pass'}\n : {\n message: NO_PROJECT_ID,\n solution: 'Add `api.projectId` to sanity.cli.ts',\n status: 'fail',\n },\n )\n\n await checkBlueprintManaged(reporter, {kind: 'studio', projectRootDir: workDir})\n\n // Workbench studios deploy to Brett (which needs the org); plain studios\n // resolve/create on user-applications, unchanged.\n let application: UserApplication | null = null\n let studioCreated = false\n let workbenchApp: {externalUrl?: string | null} | undefined\n let externalUrl: string | undefined\n let targetAppId = appId\n // Every Dashboard URL below is built on the org's host slug (`--json` included); the\n // deployer lookup overlaps the build.\n const organization =\n workbench && organizationId ? fetchOrganizationSummary(organizationId) : undefined\n const summaryDetails =\n organization && organizationId\n ? fetchDeploySummaryDetails(organizationId, organization)\n : undefined\n if (workbench) {\n reporter.report(\n organizationId\n ? {message: `Organization: ${organizationId}`, status: 'pass'}\n : {\n message: NO_ORGANIZATION_ID,\n solution: 'Add `app.organizationId` to sanity.cli.ts',\n status: 'fail',\n },\n )\n targetAppId = await selectWorkbenchAppId({appId, flags, organizationId, type: 'studio'})\n workbenchApp = (\n await checkStudioTarget(reporter, {\n appId: targetAppId,\n hostSlug: (await organization)?.hostSlug,\n isWorkbenchApp: true,\n organizationId,\n slug: workbench.slug,\n title: appTitle,\n })\n )?.application\n if (isExternal) externalUrl = checkExternalUrl(reporter, {appId: targetAppId, url: flags.url})\n } else {\n ;({application, created: studioCreated} = await resolveStudioApplication(options, {\n dryRun,\n reporter,\n }))\n }\n // A redeploy follows how the application was registered, so --external is only needed once.\n const isExternallyHosted = isExternal || !!workbenchApp?.externalUrl\n\n // A first deploy mints the app id and the build inlines it; --no-build would\n // ship an existing bundle carrying a different id, so it can't be a first deploy.\n if (workbench && !appId && !flags.build) {\n reporter.report({\n exitCode: exitCodes.USAGE_ERROR,\n message: 'A first deploy cannot skip the build (--no-build)',\n solution: 'Drop --no-build so the new application id is inlined into the build',\n status: 'fail',\n })\n }\n\n // Read up front so a bad icon path fails before we create or build.\n const appIcon =\n !dryRun && workbench?.icon ? await readAppIcon(workDir, workbench.icon) : undefined\n\n const startedAt = Date.now()\n\n // Create the studio before the build so the bundle carries its real id. A\n // redeploy already has it from `deployment.appId`; a dry run skips creation.\n let applicationId = targetAppId\n let applicationCreated = false\n let rollbackApp: (() => Promise<void>) | undefined\n if (!dryRun && workbench && organizationId && !applicationId) {\n const created = await createStudio({\n externalUrl,\n name: workbench.name,\n organizationId,\n projectId,\n slug: workbench.slug,\n title: appTitle,\n visibility: workbench.visibility,\n })\n workbenchApp = created.application\n applicationId = created.application.id\n rollbackApp = created.rollback\n applicationCreated = true\n }\n\n // A record created above is stranded at its slug (and blocks retries) if any\n // step before it fully deploys fails, so undo the creation on failure.\n try {\n const built = await checkBuild(reporter, {\n build: () =>\n buildStudio({\n applicationId: workbench ? applicationId : undefined,\n autoUpdatesEnabled: isAutoUpdating,\n calledFromDeploy: true,\n cliConfig,\n flags,\n outDir: sourceDir,\n output,\n workDir,\n }),\n skipReason: studioBuildSkipReason({build: flags.build, isLegacyExternal}),\n successMessage: 'Studio built',\n })\n\n let mfManifest = built?.mfManifest\n // A federated build has already read its manifest; anything else verifies the directory.\n if (mfManifest === undefined && !isLegacyExternal) {\n mfManifest = await verifyOutputDir({isWorkbenchApp, reporter, sourceDir})\n }\n\n const interfaces = workbench ? reportInterfaces(reporter, workbench) : null\n\n const payload: DeployPayload = {\n appId: appId ?? null,\n isAutoUpdating,\n ...(organizationId ? {organizationId} : {}),\n ...(projectId ? {projectId} : {}),\n type: 'studio',\n version,\n ...toWorkbenchPayload(workbench, {interfaces, title: appTitle}),\n }\n\n // Dry run stops here — everything below mutates.\n if (dryRun) return {application: null, payload}\n\n // A real deploy has already exited if anything failed; landing here without a\n // resolved version means the deploy target was never resolved.\n if (!version) return\n\n const studioManifest = await uploadStudioSchema(options, {\n applicationId: workbench ? applicationId : undefined,\n isExternal: isLegacyExternal,\n })\n // The studio was created (or resolved from `deployment.appId`) before the\n // build, so this only ships the deployment; plain studios use user-applications.\n if (workbench && organizationId && applicationId) {\n if (!mfManifest) throw new Error('The federated build produced no manifest.')\n await deployWorkbenchApp({\n access: toAccess(studioManifest),\n app: cliConfig.app,\n applicationId,\n icon: appIcon,\n isApp: false,\n isAutoUpdating,\n isExternal: isExternallyHosted,\n label: 'Deploying studio',\n mfManifest,\n // Once the deployment is live, a metadata-sync failure must not delete\n // the studio.\n onDeployed: () => {\n rollbackApp = undefined\n },\n slug: workbench.slug,\n sourceDir,\n title: appTitle,\n version,\n visibility: workbench.visibility,\n workDir,\n workspaces: toWorkspaces(studioManifest),\n })\n const hostSlug = (await organization)?.hostSlug\n const url = getApplicationUrl(\n {id: applicationId, organizationId, slug: workbench.slug, type: 'studio'},\n hostSlug,\n )\n const durationMs = Date.now() - startedAt\n const {organizationName = null, userName = null} = (await summaryDetails) ?? {}\n output.log(\n formatDeploySummary({\n applicationId,\n created: applicationCreated,\n durationMs,\n organizationId,\n organizationName,\n showAppIdHint: !appId,\n title: appTitle,\n type: 'studio',\n url,\n userName,\n }),\n )\n if (isExternallyHosted)\n logExternalHost({\n built: flags.build,\n hostSlug,\n organizationId,\n output,\n sourceDir,\n })\n return {\n action: applicationCreated ? 'create' : 'update',\n application: workbenchApp ?? null,\n deployedBy: userName,\n organizationName,\n payload,\n url,\n }\n }\n\n if (!application) return\n const location = await shipStudioDeployment({\n application,\n isAutoUpdating,\n isExternal,\n options,\n studioManifest,\n version,\n })\n\n return {\n action: studioCreated ? 'create' : 'update',\n application,\n payload,\n url: location,\n }\n } catch (err) {\n await rollbackApp?.()\n throw err\n }\n}\n\n/**\n * Finds the application a real deploy targets, registering a studio host when\n * none is configured. A dry run resolves and reports the target read-only instead.\n */\nasync function resolveStudioApplication(\n options: DeployAppOptions,\n {dryRun, reporter}: {dryRun: boolean; reporter: DeployCheckReporter},\n): Promise<{application: UserApplication | null; created: boolean}> {\n const {cliConfig, flags, output} = options\n const isExternal = !!flags.external\n const appId = getAppId(cliConfig)\n // Sets the title on a newly registered studio; blank falls back to undefined\n const title = flags.title?.trim() || undefined\n\n if (dryRun) {\n await checkStudioTarget(reporter, {\n appId,\n isExternal,\n projectId: cliConfig.api?.projectId,\n studioHost: cliConfig.studioHost,\n title,\n urlFlag: flags.url,\n })\n return {application: null, created: false}\n }\n\n const projectId = cliConfig.api?.projectId ?? ''\n // `created` is true when a configured-but-unregistered host was just registered.\n const {application, created} = await findUserApplicationForStudio({\n appId,\n isExternal,\n output,\n projectId,\n studioHost: cliConfig.studioHost,\n title,\n unattended: !!flags.yes,\n urlFlag: flags.url,\n })\n\n if (!application) {\n if (isExternal) {\n output.log('Your project has not been registered with an external studio URL.')\n output.log('Please enter the full URL where your studio is hosted.')\n } else {\n output.log('Your project has not been assigned a studio hostname.')\n output.log('To deploy your Sanity Studio to our hosted sanity.studio service,')\n output.log('you will need one. Please enter the subdomain you want to use.')\n }\n\n const registered = await createStudioUserApplication({\n projectId,\n title,\n urlType: isExternal ? 'external' : 'internal',\n })\n deployDebug('Created user application', registered)\n return {application: registered, created: true}\n }\n\n deployDebug('Found user application', application)\n return {application, created}\n}\n\n/** Extracts the studio schema and manifest and uploads them to the schema store. */\nasync function uploadStudioSchema(\n options: DeployAppOptions,\n {applicationId, isExternal}: {applicationId?: string; isExternal: boolean},\n): Promise<StudioManifest | null> {\n const {flags, output, projectRoot, sourceDir} = options\n\n let studioManifest: StudioManifest | null = null\n try {\n studioManifest = await deployStudioSchemasAndManifests(\n {\n applicationId,\n configPath: projectRoot.path,\n isExternal,\n outPath: `${sourceDir}/static`,\n schemaRequired: flags['schema-required'],\n verbose: flags.verbose,\n workDir: projectRoot.directory,\n },\n output,\n )\n } catch (error) {\n deployDebug('Error deploying studio schemas and manifests', error)\n if (error instanceof SchemaExtractionError && error.validation?.length) {\n output.error(formatSchemaValidation(error.validation), {exit: exitCodes.RUNTIME_ERROR})\n }\n output.error(`Error deploying studio schemas and manifests: ${error}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (!studioManifest) {\n output.error('Failed to generate studio manifest. Please check your schemas and manifests.', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n return studioManifest\n}\n\nasync function shipStudioDeployment({\n application,\n isAutoUpdating,\n isExternal,\n options,\n studioManifest,\n version,\n}: {\n application: UserApplication\n isAutoUpdating: boolean\n isExternal: boolean\n options: DeployAppOptions\n studioManifest: StudioManifest | null\n version: string\n}): Promise<string> {\n const {cliConfig, output, sourceDir} = options\n\n let tarball: Gzip | undefined\n if (!isExternal) {\n tarball = createTar({cwd: dirname(sourceDir)}, [basename(sourceDir)]).pipe(createGzip())\n }\n\n const spin = spinner(isExternal ? 'Registering studio' : 'Deploying to sanity.studio').start()\n let location: string\n try {\n ;({location} = await createDeployment({\n applicationId: application.id,\n isApp: false,\n isAutoUpdating,\n manifest: studioManifest,\n projectId: cliConfig.api?.projectId,\n tarball,\n version,\n }))\n } catch (error) {\n spin.fail()\n throw error\n }\n spin.succeed()\n\n const named = application.title ? ` — \"${application.title}\"` : ''\n output.log(\n isExternal\n ? `\\nSuccess! Studio registered${named}`\n : `\\nSuccess! Studio deployed to ${styleText('cyan', location)}${named}`,\n )\n\n if (getAppId(cliConfig)) return location\n\n const example = `Example:\nexport default defineCliConfig({\n //…\n deployment: {\n ${styleText('cyan', `appId: '${application.id}'`)},\n },\n //…\n})`\n output.log(`\\nAdd ${styleText('cyan', `appId: '${application.id}'`)}`)\n output.log(`to the \\`deployment\\` section in sanity.cli.js or sanity.cli.ts`)\n output.log(`to avoid prompting for application id on next deploy.`)\n output.log(`\\n${example}`)\n\n return location\n}\n\n/**\n * One `datasets` access entry per unique workspace dataset, with a `resourceId`\n * of `\"<projectId>.<dataset>\"`. Deduped, since workspaces can share a dataset.\n */\nfunction toAccess(manifest: StudioManifest | null): BrettAccess[] {\n const resourceIds = new Set(\n (manifest?.workspaces ?? []).map((w) => `${w.projectId}.${w.dataset}`),\n )\n return [...resourceIds].map(\n (resourceId) => ({resourceId, resourceType: 'dataset'}) satisfies BrettAccess,\n )\n}\n\nfunction toWorkspaces(manifest: StudioManifest | null): BrettWorkspace[] {\n return (manifest?.workspaces ?? []).map((workspace) => ({\n basePath: workspace.basePath,\n dataset: workspace.dataset,\n icon: workspace.icon,\n name: workspace.name,\n projectId: workspace.projectId,\n schemaDescriptorId: workspace.schemaDescriptorId,\n subtitle: workspace.subtitle,\n title: workspace.title,\n }))\n}\n\n/** Tells the customer what their host must do for the Dashboard to load the studio from it. */\nfunction logExternalHost({\n built,\n hostSlug,\n organizationId,\n output,\n sourceDir,\n}: {\n built: boolean\n hostSlug?: string | null\n organizationId: string\n output: DeployAppOptions['output']\n sourceDir: string\n}): void {\n const dir = `${relative(process.cwd(), sourceDir) || '.'}/`\n // The Dashboard is served on both the org ID host and the slug host, so the studio's host must allow both.\n const origins = [getWorkbenchUrl(organizationId), getWorkbenchUrl(organizationId, hostSlug)]\n output.log(`\nThe Dashboard loads this studio from your host, which must:\n 1. Serve ${dir} unchanged at the root of its URL (/mf-manifest.json, /remoteEntry-*.js, /static/*)\n 2. Send Access-Control-Allow-Origin for ${[...new Set(origins)].join(' and ')}\n 3. Respond without cookies or a sign-in${built ? `\\n\\nThis deploy rebuilt ${dir}: copy it to your host before opening the studio in the Dashboard.` : ''}`)\n}\n\nfunction studioBuildSkipReason({\n build,\n isLegacyExternal,\n}: {\n build: boolean\n isLegacyExternal: boolean\n}) {\n if (isLegacyExternal) return 'Build skipped for externally hosted studios'\n if (!build) return 'Build skipped (--no-build) — validating existing output directory'\n return\n}\n"],"names":["basename","dirname","relative","styleText","createGzip","formatSchemaValidation","SchemaExtractionError","exitCodes","spinner","createStudio","deployWorkbenchApp","fetchDeploySummaryDetails","fetchOrganizationSummary","formatDeploySummary","getApplicationUrl","getWorkbench","getWorkbenchUrl","readAppIcon","selectWorkbenchAppId","toWorkbenchPayload","c","createTar","createDeployment","getAppId","NO_ORGANIZATION_ID","NO_PROJECT_ID","buildStudio","checkBlueprintManaged","createStudioUserApplication","checkAutoUpdates","checkBuild","checkExternalUrl","checkPackageVersion","checkStudioTarget","verifyOutputDir","deployDebug","listDeploymentFiles","reportInterfaces","runDeploy","deployStudioSchemasAndManifests","findUserApplicationForStudio","STUDIO_PACKAGE","deployStudio","options","listFiles","flags","projectRoot","sourceDir","external","Promise","resolve","directory","run","runStudioDeployment","type","reporter","cliConfig","output","workDir","isExternal","workbench","isWorkbenchApp","projectId","api","organizationId","app","appId","dryRun","isLegacyExternal","appTitle","title","trim","isAutoUpdating","version","moduleName","report","message","status","solution","kind","projectRootDir","application","studioCreated","workbenchApp","externalUrl","targetAppId","organization","undefined","summaryDetails","hostSlug","slug","url","created","resolveStudioApplication","isExternallyHosted","build","exitCode","USAGE_ERROR","appIcon","icon","startedAt","Date","now","applicationId","applicationCreated","rollbackApp","name","visibility","id","rollback","built","autoUpdatesEnabled","calledFromDeploy","outDir","skipReason","studioBuildSkipReason","successMessage","mfManifest","interfaces","payload","studioManifest","uploadStudioSchema","Error","access","toAccess","isApp","label","onDeployed","workspaces","toWorkspaces","durationMs","organizationName","userName","log","showAppIdHint","logExternalHost","action","deployedBy","location","shipStudioDeployment","err","studioHost","urlFlag","unattended","yes","registered","urlType","configPath","path","outPath","schemaRequired","verbose","error","validation","length","exit","RUNTIME_ERROR","tarball","cwd","pipe","spin","start","manifest","fail","succeed","named","example","resourceIds","Set","map","w","dataset","resourceId","resourceType","workspace","basePath","schemaDescriptorId","subtitle","dir","process","origins","join"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,EAAEC,QAAQ,QAAO,YAAW;AACrD,SAAQC,SAAS,QAAO,YAAW;AACnC,SAAQC,UAAU,QAAkB,YAAW;AAE/C,SAAQC,sBAAsB,EAAEC,qBAAqB,QAAO,sCAAqC;AACjG,SAAQC,SAAS,QAAO,mBAAkB;AAC1C,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAGEC,YAAY,EACZC,kBAAkB,EAClBC,yBAAyB,EACzBC,wBAAwB,EACxBC,mBAAmB,EACnBC,iBAAiB,EACjBC,YAAY,EACZC,eAAe,EACfC,WAAW,EACXC,oBAAoB,EACpBC,kBAAkB,QACb,+BAA8B;AAErC,SAAQC,KAAKC,SAAS,QAAO,MAAK;AAElC,SAAQC,gBAAgB,QAA6B,qCAAoC;AACzF,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,kBAAkB,EAAEC,aAAa,QAAO,8BAA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C,WAAWgH,UAAUhH,SAAS;YAC9BkH,oBAAoBF,UAAUE,kBAAkB;YAChDC,UAAUH,UAAUG,QAAQ;YAC5B3G,OAAOwG,UAAUxG,KAAK;QACxB,CAAA;AACF;AAEA,6FAA6F,GAC7F,SAASiE,gBAAgB,EACvBzB,KAAK,EACLrB,QAAQ,EACRzB,cAAc,EACdP,MAAM,EACNV,SAAS,EAOV;IACC,MAAMmI,MAAM,GAAGhL,SAASiL,QAAQrB,GAAG,IAAI/G,cAAc,IAAI,CAAC,CAAC;IAC3D,2GAA2G;IAC3G,MAAMqI,UAAU;QAACpK,gBAAgBgD;QAAiBhD,gBAAgBgD,gBAAgByB;KAAU;IAC5FhC,OAAO4E,GAAG,CAAC,CAAC;;WAEH,EAAE6C,IAAI;0CACyB,EAAE;WAAI,IAAIV,IAAIY;KAAS,CAACC,IAAI,CAAC,SAAS;yCACvC,EAAEvE,QAAQ,CAAC,wBAAwB,EAAEoE,IAAI,kEAAkE,CAAC,GAAG,IAAI;AAC5J;AAEA,SAAS/D,sBAAsB,EAC7BpB,KAAK,EACL3B,gBAAgB,EAIjB;IACC,IAAIA,kBAAkB,OAAO;IAC7B,IAAI,CAAC2B,OAAO,OAAO;IACnB;AACF"}
|
|
@@ -149,8 +149,8 @@ import { normalizeUrl, validateUrl } from './urlUtils.js';
|
|
|
149
149
|
* can name its id instead of a create that would fail.
|
|
150
150
|
*
|
|
151
151
|
* @internal
|
|
152
|
-
*/ export async function resolveWorkbenchApp({ appId, hasAppView = true, organizationId, slug }) {
|
|
153
|
-
const getUrl = (application)=>hasAppView ? getApplicationUrl(application) : getWorkbenchUrl(application.organizationId);
|
|
152
|
+
*/ export async function resolveWorkbenchApp({ appId, hasAppView = true, hostSlug, organizationId, slug }) {
|
|
153
|
+
const getUrl = (application)=>hasAppView ? getApplicationUrl(application, hostSlug) : getWorkbenchUrl(application.organizationId, hostSlug);
|
|
154
154
|
if (appId) return resolveAppById(appId, getUrl);
|
|
155
155
|
if (organizationId && slug) {
|
|
156
156
|
const existing = (await listApplications(organizationId)).find((app)=>app.slug === slug);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/resolveDeployTarget.ts"],"sourcesContent":["import {\n type Application,\n getApplication,\n getApplicationUrl,\n getWorkbenchUrl,\n listApplications,\n} from '@sanity/workbench-cli/deploy'\n\nimport {\n getUserApplication,\n getUserApplications,\n type UserApplication,\n type UserApplicationResolved,\n} from '../../services/userApplications.js'\nimport {APP_ID_NOT_FOUND_IN_ORGANIZATION} from '../../util/errorMessages.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\n/** The application fields a deploy-target verdict carries for reporting. */\nexport interface DeployTargetApp {\n id: string\n title: string | null\n type: 'coreApp' | 'studio'\n\n appHost?: string\n url?: string\n}\n\n/** A coreApp verdict also carries the organization, for the dashboard URL. */\ninterface DeployTargetCoreApp extends DeployTargetApp {\n organizationId: string\n}\n\n/**\n * The read-only outcome of resolving where a deploy would go.\n *\n * - `found` — the deploy targets this existing application\n * - `would-create` — nothing registered yet; a deploy would create it without prompting\n * - `needs-input` — config doesn't determine a target; a deploy would prompt\n * (`existing` lists the applications a prompt would offer)\n * - `invalid` — the configured target can never resolve (bad host, unknown appId)\n * - `blocked` — resolution requires config that's missing (projectId/organizationId)\n *\n * Transport errors (network, permissions) throw — they're not verdicts.\n *\n * The user-applications resolvers carry the full {@link UserApplication} (the\n * real deploy needs it); the workbench resolvers and the report only need\n * {@link DeployTargetApp}, so `App` defaults to that widened shape.\n */\ntype CommonDeployTargetResolution<App = DeployTargetApp> =\n | {application: App; type: 'found'}\n | {existing: App[]; type: 'needs-input'}\n | {message: string; reason: 'app-not-found' | 'invalid-host'; type: 'invalid'}\n | {message: string; type: 'blocked'}\n\nexport type StudioDeployTargetResolution<App = DeployTargetApp> =\n | CommonDeployTargetResolution<App>\n | {appHost: string; existing: App; type: 'slug-taken'}\n | {appHost: string; type: 'would-create'}\n\nexport type AppDeployTargetResolution<App = DeployTargetCoreApp> =\n | CommonDeployTargetResolution<App>\n | {appHost: string; existing: App; type: 'slug-taken'}\n | {appHost?: string; type: 'would-create'}\n\n/**\n * Owns the studio deploy-target rules: the --url flag over studioHost config,\n * appId over appHost precedence, external URL normalization and validation.\n * Both the real deploy and the dry run consume these verdicts.\n *\n * @internal\n */\nexport async function resolveStudioDeployTarget(options: {\n appId: string | undefined\n isExternal: boolean\n projectId: string | undefined\n studioHost: string | undefined\n urlFlag: string | undefined\n}): Promise<StudioDeployTargetResolution<UserApplication>> {\n const {appId, isExternal, projectId, studioHost, urlFlag} = options\n\n // appId wins over host config (and undeploy resolves it the same way): a\n // configured appId deploys even when studioHost is stale or invalid, so it's\n // resolved before any host validation.\n if (appId) {\n if (!projectId) {\n return {message: 'api.projectId is missing', type: 'blocked'}\n }\n const application = await getUserApplication({appId, isSdkApp: false, projectId})\n if (application) {\n return {application, type: 'found'}\n }\n return {\n message: `Cannot find app with app ID ${appId}`,\n reason: 'app-not-found',\n type: 'invalid',\n }\n }\n\n const {error: hostError, host: resolvedHost} = resolveAppHost({\n isExternal,\n studioHost,\n url: urlFlag,\n })\n if (hostError) {\n return {message: hostError, reason: 'invalid-host', type: 'invalid'}\n }\n\n // A host from config hasn't passed through the --url validation yet\n let appHost = resolvedHost\n if (appHost && isExternal) {\n appHost = normalizeUrl(appHost)\n const validation = validateUrl(appHost)\n if (validation !== true) {\n return {message: validation, reason: 'invalid-host', type: 'invalid'}\n }\n }\n\n if (appHost) {\n if (!projectId) {\n return {message: 'api.projectId is missing', type: 'blocked'}\n }\n const application = await getUserApplication({appHost, isSdkApp: false, projectId})\n if (application) {\n return {application, type: 'found'}\n }\n return {appHost, type: 'would-create'}\n }\n\n // Neither appId nor host configured — a deploy would prompt.\n // Without a project there is nothing to list; a deploy would still prompt.\n const existing = projectId ? await listStudioApplications(projectId, isExternal) : []\n return {existing, type: 'needs-input'}\n}\n\n/**\n * Owns the app deploy-target rules: appId lookup, falling back to listing the\n * organization's applications. Both the real deploy and the dry run consume\n * these verdicts.\n *\n * @internal\n */\nexport async function resolveAppDeployTarget(options: {\n appId: string | undefined\n create?: boolean\n organizationId: string | undefined\n}): Promise<AppDeployTargetResolution<UserApplicationResolved>> {\n const {appId, create, organizationId} = options\n\n if (appId) {\n const application = await getUserApplication({appId, isSdkApp: true})\n if (application) {\n return {application, type: 'found'}\n }\n return {\n message: `Cannot find app with app ID ${appId}`,\n reason: 'app-not-found',\n type: 'invalid',\n }\n }\n\n if (!organizationId) {\n return {message: 'app.organizationId is missing', type: 'blocked'}\n }\n\n if (create) {\n return {type: 'would-create'}\n }\n\n const existing = await getUserApplications({appType: 'coreApp', organizationId})\n if (existing?.length) {\n return {existing, type: 'needs-input'}\n }\n\n return {type: 'would-create'}\n}\n\n/**\n * The dry-run counterpart to a workbench app's create-on-deploy: without an\n * `appId`, an org already holding the slug resolves to that app, so the report\n * can name its id instead of a create that would fail.\n *\n * @internal\n */\nexport async function resolveWorkbenchApp({\n appId,\n hasAppView = true,\n organizationId,\n slug,\n}: {\n appId: string | undefined\n hasAppView?: boolean\n organizationId?: string\n slug?: string\n}): Promise<AppDeployTargetResolution> {\n const getUrl = (application: Application) =>\n hasAppView ? getApplicationUrl(application) : getWorkbenchUrl(application.organizationId)\n\n if (appId) return resolveAppById(appId, getUrl)\n\n if (organizationId && slug) {\n const existing = (await listApplications(organizationId)).find((app) => app.slug === slug)\n if (existing) {\n return {\n appHost: slug,\n existing: {...existing, url: getUrl(existing)},\n type: 'slug-taken',\n }\n }\n }\n\n return {appHost: slug, type: 'would-create'}\n}\n\n/**\n * {@link resolveWorkbenchApp} narrowed for a studio, whose slug is always configured.\n *\n * @internal\n */\nexport async function resolveWorkbenchStudio(options: {\n appId: string | undefined\n organizationId?: string\n slug: string\n}): Promise<StudioDeployTargetResolution> {\n const resolution = await resolveWorkbenchApp(options)\n return resolution.type === 'would-create'\n ? {appHost: options.slug, type: 'would-create'}\n : resolution\n}\n\nasync function resolveAppById(\n appId: string,\n getUrl: (application: Application) => string,\n): Promise<CommonDeployTargetResolution<DeployTargetCoreApp>> {\n const application = await getApplication(appId)\n return application\n ? {\n application: {...application, url: getUrl(application)},\n type: 'found',\n }\n : {message: APP_ID_NOT_FOUND_IN_ORGANIZATION, reason: 'app-not-found', type: 'invalid'}\n}\n\nasync function listStudioApplications(\n projectId: string,\n isExternal: boolean,\n): Promise<UserApplication[]> {\n const urlType = isExternal ? 'external' : 'internal'\n const applications = await getUserApplications({appType: 'studio', projectId})\n // External deploys should only see external studios and vice versa\n return applications?.filter((application) => application.urlType === urlType) ?? []\n}\n\nfunction resolveAppHost({\n isExternal,\n studioHost,\n url,\n}: {\n isExternal: boolean\n studioHost: string | undefined\n url: string | undefined\n}): {error?: string; host?: string} {\n if (!url) {\n return {host: studioHost}\n }\n\n if (isExternal) {\n const normalized = normalizeUrl(url)\n const validation = validateUrl(normalized)\n if (validation !== true) {\n return {error: validation}\n }\n return {host: normalized}\n }\n\n // For internal deploys, strip protocol prefix and .sanity.studio suffix if present\n const hostname = url.replace(/^https?:\\/\\//i, '').replace(/\\.sanity\\.studio\\/?$/i, '')\n\n // If the result still looks like a URL (contains dots), the user likely meant --external\n if (hostname.includes('.')) {\n return {\n error: `\"${hostname}\" does not look like a sanity.studio hostname. Did you mean to use --external?`,\n }\n }\n\n // Validate hostname characters (alphanumeric and hyphens only)\n if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(hostname)) {\n return {\n error: `Invalid studio hostname \"${hostname}\". Hostnames can only contain letters, numbers, and hyphens.`,\n }\n }\n\n return {host: hostname}\n}\n"],"names":["getApplication","getApplicationUrl","getWorkbenchUrl","listApplications","getUserApplication","getUserApplications","APP_ID_NOT_FOUND_IN_ORGANIZATION","normalizeUrl","validateUrl","resolveStudioDeployTarget","options","appId","isExternal","projectId","studioHost","urlFlag","message","type","application","isSdkApp","reason","error","hostError","host","resolvedHost","resolveAppHost","url","appHost","validation","existing","listStudioApplications","resolveAppDeployTarget","create","organizationId","appType","length","resolveWorkbenchApp","hasAppView","slug","getUrl","resolveAppById","find","app","resolveWorkbenchStudio","resolution","urlType","applications","filter","normalized","hostname","replace","includes","test"],"mappings":"AAAA,SAEEA,cAAc,EACdC,iBAAiB,EACjBC,eAAe,EACfC,gBAAgB,QACX,+BAA8B;AAErC,SACEC,kBAAkB,EAClBC,mBAAmB,QAGd,qCAAoC;AAC3C,SAAQC,gCAAgC,QAAO,8BAA6B;AAC5E,SAAQC,YAAY,EAAEC,WAAW,QAAO,gBAAe;AAiDvD;;;;;;CAMC,GACD,OAAO,eAAeC,0BAA0BC,OAM/C;IACC,MAAM,EAACC,KAAK,EAAEC,UAAU,EAAEC,SAAS,EAAEC,UAAU,EAAEC,OAAO,EAAC,GAAGL;IAE5D,yEAAyE;IACzE,6EAA6E;IAC7E,uCAAuC;IACvC,IAAIC,OAAO;QACT,IAAI,CAACE,WAAW;YACd,OAAO;gBAACG,SAAS;gBAA4BC,MAAM;YAAS;QAC9D;QACA,MAAMC,cAAc,MAAMd,mBAAmB;YAACO;YAAOQ,UAAU;YAAON;QAAS;QAC/E,IAAIK,aAAa;YACf,OAAO;gBAACA;gBAAaD,MAAM;YAAO;QACpC;QACA,OAAO;YACLD,SAAS,CAAC,4BAA4B,EAAEL,OAAO;YAC/CS,QAAQ;YACRH,MAAM;QACR;IACF;IAEA,MAAM,EAACI,OAAOC,SAAS,EAAEC,MAAMC,YAAY,EAAC,GAAGC,eAAe;QAC5Db;QACAE;QACAY,KAAKX;IACP;IACA,IAAIO,WAAW;QACb,OAAO;YAACN,SAASM;YAAWF,QAAQ;YAAgBH,MAAM;QAAS;IACrE;IAEA,oEAAoE;IACpE,IAAIU,UAAUH;IACd,IAAIG,WAAWf,YAAY;QACzBe,UAAUpB,aAAaoB;QACvB,MAAMC,aAAapB,YAAYmB;QAC/B,IAAIC,eAAe,MAAM;YACvB,OAAO;gBAACZ,SAASY;gBAAYR,QAAQ;gBAAgBH,MAAM;YAAS;QACtE;IACF;IAEA,IA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,aAAazC,aAAamB;QAChC,MAAME,aAAapB,YAAYwC;QAC/B,IAAIpB,eAAe,MAAM;YACvB,OAAO;gBAACP,OAAOO;YAAU;QAC3B;QACA,OAAO;YAACL,MAAMyB;QAAU;IAC1B;IAEA,mFAAmF;IACnF,MAAMC,WAAWvB,IAAIwB,OAAO,CAAC,iBAAiB,IAAIA,OAAO,CAAC,yBAAyB;IAEnF,yFAAyF;IACzF,IAAID,SAASE,QAAQ,CAAC,MAAM;QAC1B,OAAO;YACL9B,OAAO,CAAC,CAAC,EAAE4B,SAAS,8EAA8E,CAAC;QACrG;IACF;IAEA,+DAA+D;IAC/D,IAAI,CAAC,mCAAmCG,IAAI,CAACH,WAAW;QACtD,OAAO;YACL5B,OAAO,CAAC,yBAAyB,EAAE4B,SAAS,4DAA4D,CAAC;QAC3G;IACF;IAEA,OAAO;QAAC1B,MAAM0B;IAAQ;AACxB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/resolveDeployTarget.ts"],"sourcesContent":["import {\n type Application,\n getApplication,\n getApplicationUrl,\n getWorkbenchUrl,\n listApplications,\n} from '@sanity/workbench-cli/deploy'\n\nimport {\n getUserApplication,\n getUserApplications,\n type UserApplication,\n type UserApplicationResolved,\n} from '../../services/userApplications.js'\nimport {APP_ID_NOT_FOUND_IN_ORGANIZATION} from '../../util/errorMessages.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\n/** The application fields a deploy-target verdict carries for reporting. */\nexport interface DeployTargetApp {\n id: string\n title: string | null\n type: 'coreApp' | 'studio'\n\n appHost?: string\n url?: string\n}\n\n/** A coreApp verdict also carries the organization, for the dashboard URL. */\ninterface DeployTargetCoreApp extends DeployTargetApp {\n organizationId: string\n}\n\n/**\n * The read-only outcome of resolving where a deploy would go.\n *\n * - `found` — the deploy targets this existing application\n * - `would-create` — nothing registered yet; a deploy would create it without prompting\n * - `needs-input` — config doesn't determine a target; a deploy would prompt\n * (`existing` lists the applications a prompt would offer)\n * - `invalid` — the configured target can never resolve (bad host, unknown appId)\n * - `blocked` — resolution requires config that's missing (projectId/organizationId)\n *\n * Transport errors (network, permissions) throw — they're not verdicts.\n *\n * The user-applications resolvers carry the full {@link UserApplication} (the\n * real deploy needs it); the workbench resolvers and the report only need\n * {@link DeployTargetApp}, so `App` defaults to that widened shape.\n */\ntype CommonDeployTargetResolution<App = DeployTargetApp> =\n | {application: App; type: 'found'}\n | {existing: App[]; type: 'needs-input'}\n | {message: string; reason: 'app-not-found' | 'invalid-host'; type: 'invalid'}\n | {message: string; type: 'blocked'}\n\nexport type StudioDeployTargetResolution<App = DeployTargetApp> =\n | CommonDeployTargetResolution<App>\n | {appHost: string; existing: App; type: 'slug-taken'}\n | {appHost: string; type: 'would-create'}\n\nexport type AppDeployTargetResolution<App = DeployTargetCoreApp> =\n | CommonDeployTargetResolution<App>\n | {appHost: string; existing: App; type: 'slug-taken'}\n | {appHost?: string; type: 'would-create'}\n\n/**\n * Owns the studio deploy-target rules: the --url flag over studioHost config,\n * appId over appHost precedence, external URL normalization and validation.\n * Both the real deploy and the dry run consume these verdicts.\n *\n * @internal\n */\nexport async function resolveStudioDeployTarget(options: {\n appId: string | undefined\n isExternal: boolean\n projectId: string | undefined\n studioHost: string | undefined\n urlFlag: string | undefined\n}): Promise<StudioDeployTargetResolution<UserApplication>> {\n const {appId, isExternal, projectId, studioHost, urlFlag} = options\n\n // appId wins over host config (and undeploy resolves it the same way): a\n // configured appId deploys even when studioHost is stale or invalid, so it's\n // resolved before any host validation.\n if (appId) {\n if (!projectId) {\n return {message: 'api.projectId is missing', type: 'blocked'}\n }\n const application = await getUserApplication({appId, isSdkApp: false, projectId})\n if (application) {\n return {application, type: 'found'}\n }\n return {\n message: `Cannot find app with app ID ${appId}`,\n reason: 'app-not-found',\n type: 'invalid',\n }\n }\n\n const {error: hostError, host: resolvedHost} = resolveAppHost({\n isExternal,\n studioHost,\n url: urlFlag,\n })\n if (hostError) {\n return {message: hostError, reason: 'invalid-host', type: 'invalid'}\n }\n\n // A host from config hasn't passed through the --url validation yet\n let appHost = resolvedHost\n if (appHost && isExternal) {\n appHost = normalizeUrl(appHost)\n const validation = validateUrl(appHost)\n if (validation !== true) {\n return {message: validation, reason: 'invalid-host', type: 'invalid'}\n }\n }\n\n if (appHost) {\n if (!projectId) {\n return {message: 'api.projectId is missing', type: 'blocked'}\n }\n const application = await getUserApplication({appHost, isSdkApp: false, projectId})\n if (application) {\n return {application, type: 'found'}\n }\n return {appHost, type: 'would-create'}\n }\n\n // Neither appId nor host configured — a deploy would prompt.\n // Without a project there is nothing to list; a deploy would still prompt.\n const existing = projectId ? await listStudioApplications(projectId, isExternal) : []\n return {existing, type: 'needs-input'}\n}\n\n/**\n * Owns the app deploy-target rules: appId lookup, falling back to listing the\n * organization's applications. Both the real deploy and the dry run consume\n * these verdicts.\n *\n * @internal\n */\nexport async function resolveAppDeployTarget(options: {\n appId: string | undefined\n create?: boolean\n organizationId: string | undefined\n}): Promise<AppDeployTargetResolution<UserApplicationResolved>> {\n const {appId, create, organizationId} = options\n\n if (appId) {\n const application = await getUserApplication({appId, isSdkApp: true})\n if (application) {\n return {application, type: 'found'}\n }\n return {\n message: `Cannot find app with app ID ${appId}`,\n reason: 'app-not-found',\n type: 'invalid',\n }\n }\n\n if (!organizationId) {\n return {message: 'app.organizationId is missing', type: 'blocked'}\n }\n\n if (create) {\n return {type: 'would-create'}\n }\n\n const existing = await getUserApplications({appType: 'coreApp', organizationId})\n if (existing?.length) {\n return {existing, type: 'needs-input'}\n }\n\n return {type: 'would-create'}\n}\n\n/**\n * The dry-run counterpart to a workbench app's create-on-deploy: without an\n * `appId`, an org already holding the slug resolves to that app, so the report\n * can name its id instead of a create that would fail.\n *\n * @internal\n */\nexport async function resolveWorkbenchApp({\n appId,\n hasAppView = true,\n hostSlug,\n organizationId,\n slug,\n}: {\n appId: string | undefined\n hasAppView?: boolean\n hostSlug?: string | null\n organizationId?: string\n slug?: string\n}): Promise<AppDeployTargetResolution> {\n const getUrl = (application: Application) =>\n hasAppView\n ? getApplicationUrl(application, hostSlug)\n : getWorkbenchUrl(application.organizationId, hostSlug)\n\n if (appId) return resolveAppById(appId, getUrl)\n\n if (organizationId && slug) {\n const existing = (await listApplications(organizationId)).find((app) => app.slug === slug)\n if (existing) {\n return {\n appHost: slug,\n existing: {...existing, url: getUrl(existing)},\n type: 'slug-taken',\n }\n }\n }\n\n return {appHost: slug, type: 'would-create'}\n}\n\n/**\n * {@link resolveWorkbenchApp} narrowed for a studio, whose slug is always configured.\n *\n * @internal\n */\nexport async function resolveWorkbenchStudio(options: {\n appId: string | undefined\n hostSlug?: string | null\n organizationId?: string\n slug: string\n}): Promise<StudioDeployTargetResolution> {\n const resolution = await resolveWorkbenchApp(options)\n return resolution.type === 'would-create'\n ? {appHost: options.slug, type: 'would-create'}\n : resolution\n}\n\nasync function resolveAppById(\n appId: string,\n getUrl: (application: Application) => string,\n): Promise<CommonDeployTargetResolution<DeployTargetCoreApp>> {\n const application = await getApplication(appId)\n return application\n ? {\n application: {...application, url: getUrl(application)},\n type: 'found',\n }\n : {message: APP_ID_NOT_FOUND_IN_ORGANIZATION, reason: 'app-not-found', type: 'invalid'}\n}\n\nasync function listStudioApplications(\n projectId: string,\n isExternal: boolean,\n): Promise<UserApplication[]> {\n const urlType = isExternal ? 'external' : 'internal'\n const applications = await getUserApplications({appType: 'studio', projectId})\n // External deploys should only see external studios and vice versa\n return applications?.filter((application) => application.urlType === urlType) ?? []\n}\n\nfunction resolveAppHost({\n isExternal,\n studioHost,\n url,\n}: {\n isExternal: boolean\n studioHost: string | undefined\n url: string | undefined\n}): {error?: string; host?: string} {\n if (!url) {\n return {host: studioHost}\n }\n\n if (isExternal) {\n const normalized = normalizeUrl(url)\n const validation = validateUrl(normalized)\n if (validation !== true) {\n return {error: validation}\n }\n return {host: normalized}\n }\n\n // For internal deploys, strip protocol prefix and .sanity.studio suffix if present\n const hostname = url.replace(/^https?:\\/\\//i, '').replace(/\\.sanity\\.studio\\/?$/i, '')\n\n // If the result still looks like a URL (contains dots), the user likely meant --external\n if (hostname.includes('.')) {\n return {\n error: `\"${hostname}\" does not look like a sanity.studio hostname. Did you mean to use --external?`,\n }\n }\n\n // Validate hostname characters (alphanumeric and hyphens only)\n if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(hostname)) {\n return {\n error: `Invalid studio hostname \"${hostname}\". Hostnames can only contain letters, numbers, and hyphens.`,\n }\n }\n\n return {host: hostname}\n}\n"],"names":["getApplication","getApplicationUrl","getWorkbenchUrl","listApplications","getUserApplication","getUserApplications","APP_ID_NOT_FOUND_IN_ORGANIZATION","normalizeUrl","validateUrl","resolveStudioDeployTarget","options","appId","isExternal","projectId","studioHost","urlFlag","message","type","application","isSdkApp","reason","error","hostError","host","resolvedHost","resolveAppHost","url","appHost","validation","existing","listStudioApplications","resolveAppDeployTarget","create","organizationId","appType","length","resolveWorkbenchApp","hasAppView","hostSlug","slug","getUrl","resolveAppById","find","app","resolveWorkbenchStudio","resolution","urlType","applications","filter","normalized","hostname","replace","includes","test"],"mappings":"AAAA,SAEEA,cAAc,EACdC,iBAAiB,EACjBC,eAAe,EACfC,gBAAgB,QACX,+BAA8B;AAErC,SACEC,kBAAkB,EAClBC,mBAAmB,QAGd,qCAAoC;AAC3C,SAAQC,gCAAgC,QAAO,8BAA6B;AAC5E,SAAQC,YAAY,EAAEC,WAAW,QAAO,gBAAe;AAiDvD;;;;;;CAMC,GACD,OAAO,eAAeC,0BAA0BC,OAM/C;IACC,MAAM,EAACC,KAAK,EAAEC,UAAU,EAAEC,SAAS,EAAEC,UAAU,EAAEC,OAAO,EAAC,GAAGL;IAE5D,yEAAyE;IACzE,6EAA6E;IAC7E,uCAAuC;IACvC,IAAIC,OAAO;QACT,IAAI,CAACE,WAAW;YACd,OAAO;gBAACG,SAAS;gBAA4BC,MAAM;YAAS;QAC9D;QACA,MAAMC,cAAc,MAAMd,mBAAmB;YAACO;YAAOQ,UAAU;YAAON;QAAS;QAC/E,IAAIK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cli-core';
|
|
3
|
+
import { select } from '@sanity/cli-core/ux';
|
|
4
|
+
import { promptForDataset } from '../../prompts/promptForDataset.js';
|
|
5
|
+
import { promptForProject } from '../../prompts/promptForProject.js';
|
|
6
|
+
import { getDeployedStack } from '../../services/blueprints.js';
|
|
7
|
+
import { listDatasets } from '../../services/datasets.js';
|
|
8
|
+
import { getCheckoutBlueprint } from '../../util/checkoutBlueprint.js';
|
|
9
|
+
export async function resolveCommandTarget({ dataset: datasetFlag, loadCliConfig, needsDataset, project: projectFlag, unattended }) {
|
|
10
|
+
if (projectFlag && (!needsDataset || datasetFlag)) {
|
|
11
|
+
return {
|
|
12
|
+
dataset: datasetFlag,
|
|
13
|
+
projectId: projectFlag
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
let checkout;
|
|
17
|
+
try {
|
|
18
|
+
checkout = getCheckoutBlueprint();
|
|
19
|
+
} catch (cause) {
|
|
20
|
+
throw targetError('Could not read the local Blueprint Stack link. Check .sanity/blueprint.config.json.', retryFlags(projectFlag, datasetFlag, needsDataset), cause);
|
|
21
|
+
}
|
|
22
|
+
const studio = checkout ? undefined : (await loadCliConfig()).api;
|
|
23
|
+
const localProject = checkout?.scopeType === 'project' ? checkout.scopeId : studio?.projectId;
|
|
24
|
+
let projectId = projectFlag || localProject;
|
|
25
|
+
const sameProject = !projectFlag || projectFlag === localProject;
|
|
26
|
+
let dataset = datasetFlag || (sameProject ? studio?.dataset : undefined);
|
|
27
|
+
const targetStack = sameProject || checkout?.scopeType === 'organization' ? checkout : undefined;
|
|
28
|
+
const stack = targetStack && (!projectId || needsDataset && !dataset) ? await readStackTargets(targetStack, retryFlags(projectId, dataset, needsDataset)) : undefined;
|
|
29
|
+
if (!projectId) {
|
|
30
|
+
const projects = [
|
|
31
|
+
...stack?.projects ?? []
|
|
32
|
+
];
|
|
33
|
+
const requestedDataset = dataset;
|
|
34
|
+
const matching = requestedDataset ? projects.filter((id)=>stack?.datasets.get(id)?.has(requestedDataset)) : projects;
|
|
35
|
+
const defaultProject = stack?.defaultProjectId ?? undefined;
|
|
36
|
+
const useDefaultProject = defaultProject && (!dataset || matching.length === 0 || matching.includes(defaultProject));
|
|
37
|
+
projectId = useDefaultProject ? defaultProject : await selectStackTarget(matching.length > 0 ? matching : projects, 'project', unattended);
|
|
38
|
+
if (!projectId) {
|
|
39
|
+
if (unattended) {
|
|
40
|
+
const reason = stack ? 'No deployed project found in the linked Stack.' : 'Project is required.';
|
|
41
|
+
throw targetError(reason, retryFlags(projectId, dataset, needsDataset));
|
|
42
|
+
}
|
|
43
|
+
projectId = await promptForProject({
|
|
44
|
+
organizationId: checkout?.scopeType === 'organization' ? checkout.scopeId : undefined
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (needsDataset && !dataset) {
|
|
49
|
+
dataset = await selectStackTarget([
|
|
50
|
+
...stack?.datasets.get(projectId) ?? []
|
|
51
|
+
], 'dataset', unattended);
|
|
52
|
+
if (!dataset && unattended) {
|
|
53
|
+
const reason = stack ? 'No deployed dataset found in the linked Stack for this project.' : 'Dataset is required.';
|
|
54
|
+
throw targetError(reason, '--dataset <name>');
|
|
55
|
+
}
|
|
56
|
+
if (!dataset) {
|
|
57
|
+
const datasets = await listDatasets(projectId);
|
|
58
|
+
if (datasets.length === 0) {
|
|
59
|
+
throw targetError('No datasets found in this project. Create a dataset or choose another project.', '--project <project-id> --dataset <name>');
|
|
60
|
+
}
|
|
61
|
+
dataset = await promptForDataset({
|
|
62
|
+
datasets
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
dataset,
|
|
68
|
+
projectId
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async function readStackTargets({ scopeId, scopeType, stackId }, flags) {
|
|
72
|
+
try {
|
|
73
|
+
const stack = await getDeployedStack({
|
|
74
|
+
scopeId,
|
|
75
|
+
scopeType,
|
|
76
|
+
stackId
|
|
77
|
+
});
|
|
78
|
+
if (!Array.isArray(stack.resources)) throw new TypeError('Stack resources are missing');
|
|
79
|
+
const projects = new Set();
|
|
80
|
+
const datasets = new Map();
|
|
81
|
+
for (const { externalId, type } of stack.resources){
|
|
82
|
+
if (!externalId) continue;
|
|
83
|
+
if (type === 'sanity.project') projects.add(externalId);
|
|
84
|
+
if (type !== 'sanity.project.dataset') continue;
|
|
85
|
+
const [projectId, dataset, remainder] = externalId.split(':');
|
|
86
|
+
if (!projectId || !dataset || remainder !== undefined) continue;
|
|
87
|
+
if (scopeType === 'project' && projectId !== scopeId) continue;
|
|
88
|
+
const names = datasets.get(projectId) ?? new Set();
|
|
89
|
+
names.add(dataset);
|
|
90
|
+
datasets.set(projectId, names);
|
|
91
|
+
projects.add(projectId);
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
datasets,
|
|
95
|
+
defaultProjectId: stack.defaultProjectId,
|
|
96
|
+
projects
|
|
97
|
+
};
|
|
98
|
+
} catch (cause) {
|
|
99
|
+
throw targetError(`Could not read Stack ${stackId}. Check your Stack access.`, flags, cause);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function selectStackTarget(values, kind, unattended) {
|
|
103
|
+
if (values.length < 2) return values[0];
|
|
104
|
+
if (unattended) {
|
|
105
|
+
const flag = kind === 'project' ? '--project <project-id>' : '--dataset <name>';
|
|
106
|
+
throw targetError(`Multiple deployed ${kind}s match the linked Stack.`, flag);
|
|
107
|
+
}
|
|
108
|
+
return select({
|
|
109
|
+
choices: values.toSorted().map((value)=>({
|
|
110
|
+
name: value,
|
|
111
|
+
value
|
|
112
|
+
})),
|
|
113
|
+
message: `Select a ${kind} from this Stack`
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function retryFlags(project, dataset, needsDataset) {
|
|
117
|
+
const flags = [];
|
|
118
|
+
if (!project) flags.push('--project <project-id>');
|
|
119
|
+
if (needsDataset && !dataset) flags.push('--dataset <name>');
|
|
120
|
+
return flags.join(' ');
|
|
121
|
+
}
|
|
122
|
+
function targetError(reason, flags, cause) {
|
|
123
|
+
return new CLIError(new Error(`${reason} Try again with \`${flags}\`.`, {
|
|
124
|
+
cause
|
|
125
|
+
}), {
|
|
126
|
+
exit: exitCodes.USAGE_ERROR
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=resolveCommandTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/targets/resolveCommandTarget.ts"],"sourcesContent":["import {CLIError} from '@oclif/core/errors'\nimport {exitCodes} from '@sanity/cli-core'\nimport {type CliConfig} from '@sanity/cli-core/config'\nimport {select} from '@sanity/cli-core/ux'\n\nimport {promptForDataset} from '../../prompts/promptForDataset.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {getDeployedStack} from '../../services/blueprints.js'\nimport {listDatasets} from '../../services/datasets.js'\nimport {type CheckoutStack, getCheckoutBlueprint} from '../../util/checkoutBlueprint.js'\n\ninterface TargetOptions {\n loadCliConfig: () => Promise<CliConfig>\n unattended: boolean\n\n dataset?: string\n needsDataset?: boolean\n project?: string\n}\n\ninterface CommandTarget {\n projectId: string\n\n dataset?: string\n}\n\n// Call only after the command has opted in with --with-blueprints.\n// Commands that need a dataset get a complete target or a usage error.\nexport function resolveCommandTarget(\n options: TargetOptions & {needsDataset: true},\n): Promise<CommandTarget & {dataset: string}>\nexport function resolveCommandTarget(options: TargetOptions): Promise<CommandTarget>\nexport async function resolveCommandTarget({\n dataset: datasetFlag,\n loadCliConfig,\n needsDataset,\n project: projectFlag,\n unattended,\n}: TargetOptions): Promise<CommandTarget> {\n if (projectFlag && (!needsDataset || datasetFlag)) {\n return {dataset: datasetFlag, projectId: projectFlag}\n }\n\n let checkout: CheckoutStack | undefined\n try {\n checkout = getCheckoutBlueprint()\n } catch (cause) {\n throw targetError(\n 'Could not read the local Blueprint Stack link. Check .sanity/blueprint.config.json.',\n retryFlags(projectFlag, datasetFlag, needsDataset),\n cause,\n )\n }\n\n const studio = checkout ? undefined : (await loadCliConfig()).api\n const localProject = checkout?.scopeType === 'project' ? checkout.scopeId : studio?.projectId\n let projectId = projectFlag || localProject\n const sameProject = !projectFlag || projectFlag === localProject\n let dataset = datasetFlag || (sameProject ? studio?.dataset : undefined)\n const targetStack = sameProject || checkout?.scopeType === 'organization' ? checkout : undefined\n\n const stack =\n targetStack && (!projectId || (needsDataset && !dataset))\n ? await readStackTargets(targetStack, retryFlags(projectId, dataset, needsDataset))\n : undefined\n\n if (!projectId) {\n const projects = [...(stack?.projects ?? [])]\n const requestedDataset = dataset\n const matching = requestedDataset\n ? projects.filter((id) => stack?.datasets.get(id)?.has(requestedDataset))\n : projects\n const defaultProject = stack?.defaultProjectId ?? undefined\n const useDefaultProject =\n defaultProject && (!dataset || matching.length === 0 || matching.includes(defaultProject))\n projectId = useDefaultProject\n ? defaultProject\n : await selectStackTarget(matching.length > 0 ? matching : projects, 'project', unattended)\n if (!projectId) {\n if (unattended) {\n const reason = stack\n ? 'No deployed project found in the linked Stack.'\n : 'Project is required.'\n throw targetError(reason, retryFlags(projectId, dataset, needsDataset))\n }\n projectId = await promptForProject({\n organizationId: checkout?.scopeType === 'organization' ? checkout.scopeId : undefined,\n })\n }\n }\n\n if (needsDataset && !dataset) {\n dataset = await selectStackTarget(\n [...(stack?.datasets.get(projectId) ?? [])],\n 'dataset',\n unattended,\n )\n if (!dataset && unattended) {\n const reason = stack\n ? 'No deployed dataset found in the linked Stack for this project.'\n : 'Dataset is required.'\n throw targetError(reason, '--dataset <name>')\n }\n if (!dataset) {\n const datasets = await listDatasets(projectId)\n if (datasets.length === 0) {\n throw targetError(\n 'No datasets found in this project. Create a dataset or choose another project.',\n '--project <project-id> --dataset <name>',\n )\n }\n dataset = await promptForDataset({datasets})\n }\n }\n\n return {dataset, projectId}\n}\n\nasync function readStackTargets({scopeId, scopeType, stackId}: CheckoutStack, flags: string) {\n try {\n const stack = await getDeployedStack({scopeId, scopeType, stackId})\n if (!Array.isArray(stack.resources)) throw new TypeError('Stack resources are missing')\n\n const projects = new Set<string>()\n const datasets = new Map<string, Set<string>>()\n for (const {externalId, type} of stack.resources) {\n if (!externalId) continue\n if (type === 'sanity.project') projects.add(externalId)\n if (type !== 'sanity.project.dataset') continue\n const [projectId, dataset, remainder] = externalId.split(':')\n if (!projectId || !dataset || remainder !== undefined) continue\n if (scopeType === 'project' && projectId !== scopeId) continue\n const names = datasets.get(projectId) ?? new Set<string>()\n names.add(dataset)\n datasets.set(projectId, names)\n projects.add(projectId)\n }\n return {datasets, defaultProjectId: stack.defaultProjectId, projects}\n } catch (cause) {\n throw targetError(`Could not read Stack ${stackId}. Check your Stack access.`, flags, cause)\n }\n}\n\nasync function selectStackTarget(\n values: string[],\n kind: 'dataset' | 'project',\n unattended: boolean,\n): Promise<string | undefined> {\n if (values.length < 2) return values[0]\n if (unattended) {\n const flag = kind === 'project' ? '--project <project-id>' : '--dataset <name>'\n throw targetError(`Multiple deployed ${kind}s match the linked Stack.`, flag)\n }\n return select({\n choices: values.toSorted().map((value) => ({name: value, value})),\n message: `Select a ${kind} from this Stack`,\n })\n}\n\nfunction retryFlags(project?: string, dataset?: string, needsDataset?: boolean): string {\n const flags = []\n if (!project) flags.push('--project <project-id>')\n if (needsDataset && !dataset) flags.push('--dataset <name>')\n return flags.join(' ')\n}\n\nfunction targetError(reason: string, flags: string, cause?: unknown): CLIError {\n return new CLIError(new Error(`${reason} Try again with \\`${flags}\\`.`, {cause}), {\n exit: exitCodes.USAGE_ERROR,\n })\n}\n"],"names":["CLIError","exitCodes","select","promptForDataset","promptForProject","getDeployedStack","listDatasets","getCheckoutBlueprint","resolveCommandTarget","dataset","datasetFlag","loadCliConfig","needsDataset","project","projectFlag","unattended","projectId","checkout","cause","targetError","retryFlags","studio","undefined","api","localProject","scopeType","scopeId","sameProject","targetStack","stack","readStackTargets","projects","requestedDataset","matching","filter","id","datasets","get","has","defaultProject","defaultProjectId","useDefaultProject","length","includes","selectStackTarget","reason","organizationId","stackId","flags","Array","isArray","resources","TypeError","Set","Map","externalId","type","add","remainder","split","names","set","values","kind","flag","choices","toSorted","map","value","name","message","push","join","Error","exit","USAGE_ERROR"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,qBAAoB;AAC3C,SAAQC,SAAS,QAAO,mBAAkB;AAE1C,SAAQC,MAAM,QAAO,sBAAqB;AAE1C,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,gBAAgB,QAAO,+BAA8B;AAC7D,SAAQC,YAAY,QAAO,6BAA4B;AACvD,SAA4BC,oBAAoB,QAAO,kCAAiC;AAuBxF,OAAO,eAAeC,qBAAqB,EACzCC,SAASC,WAAW,EACpBC,aAAa,EACbC,YAAY,EACZC,SAASC,WAAW,EACpBC,UAAU,EACI;IACd,IAAID,eAAgB,CAAA,CAACF,gBAAgBF,WAAU,GAAI;QACjD,OAAO;YAACD,SAASC;YAAaM,WAAWF;QAAW;IACtD;IAEA,IAAIG;IACJ,IAAI;QACFA,WAAWV;IACb,EAAE,OAAOW,OAAO;QACd,MAAMC,YACJ,uFACAC,WAAWN,aAAaJ,aAAaE,eACrCM;IAEJ;IAEA,MAAMG,SAASJ,WAAWK,YAAY,AAAC,CAAA,MAAMX,eAAc,EAAGY,GAAG;IACjE,MAAMC,eAAeP,UAAUQ,cAAc,YAAYR,SAASS,OAAO,GAAGL,QAAQL;IACpF,IAAIA,YAAYF,eAAeU;IAC/B,MAAMG,cAAc,CAACb,eAAeA,gBAAgBU;IACpD,IAAIf,UAAUC,eAAgBiB,CAAAA,cAAcN,QAAQZ,UAAUa,SAAQ;IACtE,MAAMM,cAAcD,eAAeV,UAAUQ,cAAc,iBAAiBR,WAAWK;IAEvF,MAAMO,QACJD,eAAgB,CAAA,CAACZ,aAAcJ,gBAAgB,CAACH,OAAO,IACnD,MAAMqB,iBAAiBF,aAAaR,WAAWJ,WAAWP,SAASG,iBACnEU;IAEN,I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BAACC,MAAMD;gBAAOA;YAAK,CAAA;QAC9DE,SAAS,CAAC,SAAS,EAAEP,KAAK,gBAAgB,CAAC;IAC7C;AACF;AAEA,SAAS3C,WAAWP,OAAgB,EAAEJ,OAAgB,EAAEG,YAAsB;IAC5E,MAAMoC,QAAQ,EAAE;IAChB,IAAI,CAACnC,SAASmC,MAAMuB,IAAI,CAAC;IACzB,IAAI3D,gBAAgB,CAACH,SAASuC,MAAMuB,IAAI,CAAC;IACzC,OAAOvB,MAAMwB,IAAI,CAAC;AACpB;AAEA,SAASrD,YAAY0B,MAAc,EAAEG,KAAa,EAAE9B,KAAe;IACjE,OAAO,IAAIlB,SAAS,IAAIyE,MAAM,GAAG5B,OAAO,kBAAkB,EAAEG,MAAM,GAAG,CAAC,EAAE;QAAC9B;IAAK,IAAI;QAChFwD,MAAMzE,UAAU0E,WAAW;IAC7B;AACF"}
|
|
@@ -89,7 +89,7 @@ const undeployDebug = subdebug('undeploy');
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
const { target } = resolution;
|
|
92
|
-
const summaryDetails = target.
|
|
92
|
+
const summaryDetails = target.organizationId ? fetchDeploySummaryDetails(target.organizationId) : undefined;
|
|
93
93
|
if (!flags.yes && options.isUnattended) {
|
|
94
94
|
throw new CLIError('Undeploy requires confirmation. Pass --yes to continue.', {
|
|
95
95
|
exit: exitCodes.USAGE_ERROR
|
|
@@ -119,8 +119,9 @@ const undeployDebug = subdebug('undeploy');
|
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
spin.succeed();
|
|
122
|
+
const details = await summaryDetails;
|
|
122
123
|
printUndeployed(target, output, {
|
|
123
|
-
...
|
|
124
|
+
...details,
|
|
124
125
|
durationMs: Date.now() - startedAt
|
|
125
126
|
});
|
|
126
127
|
return {
|
|
@@ -129,7 +130,12 @@ const undeployDebug = subdebug('undeploy');
|
|
|
129
130
|
payload: target.payload,
|
|
130
131
|
reason: null,
|
|
131
132
|
undeployed: true,
|
|
132
|
-
url: target.url
|
|
133
|
+
url: target.url,
|
|
134
|
+
...target.organizationId && {
|
|
135
|
+
organizationId: target.organizationId,
|
|
136
|
+
organizationName: details?.organizationName ?? null,
|
|
137
|
+
undeployedBy: details?.userName ?? null
|
|
138
|
+
}
|
|
133
139
|
};
|
|
134
140
|
}
|
|
135
141
|
/**
|
|
@@ -181,6 +187,16 @@ function printUndeployed(target, output, summary) {
|
|
|
181
187
|
}));
|
|
182
188
|
return;
|
|
183
189
|
}
|
|
190
|
+
if (target.organizationId) {
|
|
191
|
+
output.log(formatUndeploySummary({
|
|
192
|
+
...summary,
|
|
193
|
+
organizationId: target.organizationId,
|
|
194
|
+
title: target.title ?? target.id,
|
|
195
|
+
type: target.type,
|
|
196
|
+
url: getWorkbenchUrl(target.organizationId, summary.hostSlug)
|
|
197
|
+
}));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
184
200
|
if (target.type === 'coreApp') {
|
|
185
201
|
output.log(`\n${styleText('bold', '⏱️ Application undeploy scheduled.')} It might be a few minutes until ${target.title ? styleText('italic', `'${target.title}'`) : 'your application'} is unavailable.`);
|
|
186
202
|
output.log(`\n${styleText('bold', 'Remember to remove `deployment.appId` from your application configuration')} to avoid errors when redeploying.`);
|