@sanity/cli 7.5.0 → 7.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/actions/build/buildApp.js +7 -183
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStudio.js +6 -213
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/build/shouldAutoUpdate.js +100 -22
- package/dist/actions/build/shouldAutoUpdate.js.map +1 -1
- package/dist/actions/deploy/{createStudioUserApplication.js → createUserApplication.js} +56 -5
- package/dist/actions/deploy/createUserApplication.js.map +1 -0
- package/dist/actions/deploy/deployApp.js +253 -183
- package/dist/actions/deploy/deployApp.js.map +1 -1
- package/dist/actions/deploy/deployChecks.js +284 -0
- package/dist/actions/deploy/deployChecks.js.map +1 -0
- package/dist/actions/deploy/deployRunner.js +78 -0
- package/dist/actions/deploy/deployRunner.js.map +1 -0
- package/dist/actions/deploy/deployStudio.js +200 -197
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/deploy/deployStudioSchemasAndManifests.js +2 -3
- package/dist/actions/deploy/deployStudioSchemasAndManifests.js.map +1 -1
- package/dist/actions/deploy/deploymentPlan.js +117 -0
- package/dist/actions/deploy/deploymentPlan.js.map +1 -0
- package/dist/actions/deploy/findUserApplication.js +209 -0
- package/dist/actions/deploy/findUserApplication.js.map +1 -0
- package/dist/actions/deploy/resolveDeployTarget.js +185 -0
- package/dist/actions/deploy/resolveDeployTarget.js.map +1 -0
- package/dist/actions/deploy/urlUtils.js +4 -0
- package/dist/actions/deploy/urlUtils.js.map +1 -1
- package/dist/actions/dev/devAction.js +1 -1
- package/dist/actions/dev/devAction.js.map +1 -1
- package/dist/actions/dev/servers/getDevServerConfig.js +18 -6
- package/dist/actions/dev/servers/getDevServerConfig.js.map +1 -1
- package/dist/actions/dev/servers/startAppDevServer.js +1 -1
- package/dist/actions/dev/servers/startAppDevServer.js.map +1 -1
- package/dist/actions/dev/servers/startStudioDevServer.js +2 -1
- package/dist/actions/dev/servers/startStudioDevServer.js.map +1 -1
- package/dist/actions/manifest/extractCoreAppManifest.js +15 -1
- package/dist/actions/manifest/extractCoreAppManifest.js.map +1 -1
- package/dist/commands/deploy.js +31 -12
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.js +2 -1
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/init.js +2 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/exports/index.d.ts +9 -0
- package/dist/exports/index.js +1 -8
- package/dist/exports/index.js.map +1 -1
- package/dist/server/devServer.js +27 -3
- package/dist/server/devServer.js.map +1 -1
- package/dist/services/userApplications.js.map +1 -1
- package/dist/util/appId.js +13 -5
- package/dist/util/appId.js.map +1 -1
- package/dist/util/compareDependencyVersions.js.map +1 -1
- package/dist/util/determineIsApp.js +1 -1
- package/dist/util/determineIsApp.js.map +1 -1
- package/dist/util/errorMessages.js +2 -0
- package/dist/util/errorMessages.js.map +1 -1
- package/oclif.manifest.json +223 -203
- package/package.json +8 -8
- package/dist/actions/build/handlePrereleaseVersions.js +0 -44
- package/dist/actions/build/handlePrereleaseVersions.js.map +0 -1
- package/dist/actions/deploy/createStudioUserApplication.js.map +0 -1
- package/dist/actions/deploy/createUserApplicationForApp.js +0 -56
- package/dist/actions/deploy/createUserApplicationForApp.js.map +0 -1
- package/dist/actions/deploy/findUserApplicationForApp.js +0 -111
- package/dist/actions/deploy/findUserApplicationForApp.js.map +0 -1
- package/dist/actions/deploy/findUserApplicationForStudio.js +0 -172
- package/dist/actions/deploy/findUserApplicationForStudio.js.map +0 -1
- package/dist/actions/deploy/viewDeployment.js +0 -32
- package/dist/actions/deploy/viewDeployment.js.map +0 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { readdir, stat } from 'node:fs/promises';
|
|
2
|
+
import { join, relative, sep } from 'node:path';
|
|
3
|
+
import { styleText } from 'node:util';
|
|
4
|
+
import { logSymbols } from '@sanity/cli-core/ux';
|
|
5
|
+
import { pluralize } from '../../util/pluralize.js';
|
|
6
|
+
/**
|
|
7
|
+
* Lists the files a deploy would pack from `sourceDir`, as paths relative to
|
|
8
|
+
* `fromDir`. A missing directory yields an empty list rather than throwing.
|
|
9
|
+
*/ export async function listDeploymentFiles(sourceDir, fromDir) {
|
|
10
|
+
const walk = async (dir)=>{
|
|
11
|
+
let entries;
|
|
12
|
+
try {
|
|
13
|
+
entries = await readdir(dir, {
|
|
14
|
+
withFileTypes: true
|
|
15
|
+
});
|
|
16
|
+
} catch {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const nested = await Promise.all(entries.map((entry)=>{
|
|
20
|
+
const full = join(dir, entry.name);
|
|
21
|
+
return entry.isDirectory() ? walk(full) : Promise.resolve([
|
|
22
|
+
full
|
|
23
|
+
]);
|
|
24
|
+
}));
|
|
25
|
+
return nested.flat();
|
|
26
|
+
};
|
|
27
|
+
const absolute = await walk(sourceDir);
|
|
28
|
+
const files = await Promise.all(absolute.map(async (file)=>({
|
|
29
|
+
// Deploy paths are POSIX-style regardless of the host OS (Windows gives `\`).
|
|
30
|
+
path: relative(fromDir, file).split(sep).join('/'),
|
|
31
|
+
size: (await stat(file)).size
|
|
32
|
+
})));
|
|
33
|
+
return files.toSorted((a, b)=>a.path.localeCompare(b.path));
|
|
34
|
+
}
|
|
35
|
+
export function isDeployable(plan) {
|
|
36
|
+
return plan.checks.every((check)=>check.status !== 'fail');
|
|
37
|
+
}
|
|
38
|
+
function totalBytes(files) {
|
|
39
|
+
return files.reduce((sum, file)=>sum + file.size, 0);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A problem-focused, machine-readable projection of the plan: blocking problems
|
|
43
|
+
* mapped to their fix, warnings as messages. Derived from the same checks the
|
|
44
|
+
* human report renders (its pass/skip lines are informational and omitted here).
|
|
45
|
+
*/ export function deploymentPlanToJson(plan) {
|
|
46
|
+
const errors = {};
|
|
47
|
+
const warnings = [];
|
|
48
|
+
for (const check of plan.checks){
|
|
49
|
+
if (check.status === 'fail') errors[check.message] = check.solution ?? null;
|
|
50
|
+
else if (check.status === 'warn') warnings.push(check.message);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
applicationType: plan.type,
|
|
54
|
+
applicationVersion: plan.version,
|
|
55
|
+
errors,
|
|
56
|
+
files: plan.files,
|
|
57
|
+
isDeployable: isDeployable(plan),
|
|
58
|
+
target: plan.target,
|
|
59
|
+
totalBytes: totalBytes(plan.files),
|
|
60
|
+
warnings
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export function renderDeploymentPlan(plan, output) {
|
|
64
|
+
const label = plan.type === 'coreApp' ? 'application' : 'studio';
|
|
65
|
+
const problems = plan.checks.filter((check)=>check.status === 'fail');
|
|
66
|
+
const warnings = plan.checks.filter((check)=>check.status === 'warn');
|
|
67
|
+
output.log('\nDry run — no changes made.\n');
|
|
68
|
+
// Only pass/skip here; problems and warnings render below with their fixes.
|
|
69
|
+
for (const check of plan.checks){
|
|
70
|
+
if (check.status === 'pass' || check.status === 'skip') {
|
|
71
|
+
output.log(` ${statusIcon(check.status)} ${check.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
output.log(isDeployable(plan) ? styleText('green', `\nThis ${label} can be deployed.`) : styleText('red', `\nThis ${label} can't be deployed.`));
|
|
75
|
+
renderIssues(output, 'Problems to fix:', problems);
|
|
76
|
+
renderIssues(output, 'Warnings:', warnings);
|
|
77
|
+
// A blocked deploy uploads nothing, so only list files for a deployable plan.
|
|
78
|
+
if (isDeployable(plan) && plan.files.length > 0) {
|
|
79
|
+
output.log(`\nFiles to deploy (${plan.files.length} ${pluralize('file', plan.files.length)}, ${formatMB(totalBytes(plan.files))}):`);
|
|
80
|
+
for (const file of plan.files){
|
|
81
|
+
output.log(` ${file.path} (${formatMB(file.size)})`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function renderIssues(output, title, checks) {
|
|
86
|
+
if (checks.length === 0) return;
|
|
87
|
+
output.log(`\n${title}`);
|
|
88
|
+
for (const check of checks){
|
|
89
|
+
const fix = check.solution ? `: ${check.solution}` : '';
|
|
90
|
+
output.log(` ${statusIcon(check.status)} ${check.message}${fix}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function formatMB(bytes) {
|
|
94
|
+
return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
|
|
95
|
+
}
|
|
96
|
+
function statusIcon(status) {
|
|
97
|
+
switch(status){
|
|
98
|
+
case 'fail':
|
|
99
|
+
{
|
|
100
|
+
return logSymbols.error;
|
|
101
|
+
}
|
|
102
|
+
case 'skip':
|
|
103
|
+
{
|
|
104
|
+
return logSymbols.info;
|
|
105
|
+
}
|
|
106
|
+
case 'warn':
|
|
107
|
+
{
|
|
108
|
+
return logSymbols.warning;
|
|
109
|
+
}
|
|
110
|
+
default:
|
|
111
|
+
{
|
|
112
|
+
return logSymbols.success;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
//# sourceMappingURL=deploymentPlan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deploymentPlan.ts"],"sourcesContent":["import {readdir, stat} from 'node:fs/promises'\nimport {join, relative, sep} from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {type Output} from '@sanity/cli-core'\nimport {logSymbols} from '@sanity/cli-core/ux'\n\nimport {pluralize} from '../../util/pluralize.js'\nimport {type DeployCheck, type DeployTarget} from './deployChecks.js'\n\nexport interface DeploymentFile {\n /** Path relative to the project root, POSIX-style. */\n path: string\n size: number\n}\n\n/** What a `--dry-run` deploy would do: the real deploy sequence with every mutation gated off. */\nexport interface DeploymentPlan {\n checks: DeployCheck[]\n files: DeploymentFile[]\n /** The resolved deploy target; `null` when the checks can't determine one. */\n target: DeployTarget | null\n type: 'coreApp' | 'studio'\n /** Installed framework version the deploy would use; `null` when not found. */\n version: string | null\n}\n\n/**\n * Lists the files a deploy would pack from `sourceDir`, as paths relative to\n * `fromDir`. A missing directory yields an empty list rather than throwing.\n */\nexport async function listDeploymentFiles(\n sourceDir: string,\n fromDir: string,\n): Promise<DeploymentFile[]> {\n const walk = async (dir: string): Promise<string[]> => {\n let entries\n try {\n entries = await readdir(dir, {withFileTypes: true})\n } catch {\n return []\n }\n const nested = await Promise.all(\n entries.map((entry) => {\n const full = join(dir, entry.name)\n return entry.isDirectory() ? walk(full) : Promise.resolve([full])\n }),\n )\n return nested.flat()\n }\n\n const absolute = await walk(sourceDir)\n const files = await Promise.all(\n absolute.map(async (file) => ({\n // Deploy paths are POSIX-style regardless of the host OS (Windows gives `\\`).\n path: relative(fromDir, file).split(sep).join('/'),\n size: (await stat(file)).size,\n })),\n )\n return files.toSorted((a, b) => a.path.localeCompare(b.path))\n}\n\nexport function isDeployable(plan: DeploymentPlan): boolean {\n return plan.checks.every((check) => check.status !== 'fail')\n}\n\nfunction totalBytes(files: DeploymentFile[]): number {\n return files.reduce((sum, file) => sum + file.size, 0)\n}\n\n/**\n * A problem-focused, machine-readable projection of the plan: blocking problems\n * mapped to their fix, warnings as messages. Derived from the same checks the\n * human report renders (its pass/skip lines are informational and omitted here).\n */\nexport function deploymentPlanToJson(plan: DeploymentPlan): {\n applicationType: DeploymentPlan['type']\n applicationVersion: string | null\n errors: Record<string, string | null>\n files: DeploymentFile[]\n isDeployable: boolean\n target: DeployTarget | null\n totalBytes: number\n warnings: string[]\n} {\n const errors: Record<string, string | null> = {}\n const warnings: string[] = []\n for (const check of plan.checks) {\n if (check.status === 'fail') errors[check.message] = check.solution ?? null\n else if (check.status === 'warn') warnings.push(check.message)\n }\n\n return {\n applicationType: plan.type,\n applicationVersion: plan.version,\n errors,\n files: plan.files,\n isDeployable: isDeployable(plan),\n target: plan.target,\n totalBytes: totalBytes(plan.files),\n warnings,\n }\n}\n\nexport function renderDeploymentPlan(plan: DeploymentPlan, output: Output): void {\n const label = plan.type === 'coreApp' ? 'application' : 'studio'\n const problems = plan.checks.filter((check) => check.status === 'fail')\n const warnings = plan.checks.filter((check) => check.status === 'warn')\n\n output.log('\\nDry run — no changes made.\\n')\n\n // Only pass/skip here; problems and warnings render below with their fixes.\n for (const check of plan.checks) {\n if (check.status === 'pass' || check.status === 'skip') {\n output.log(` ${statusIcon(check.status)} ${check.message}`)\n }\n }\n\n output.log(\n isDeployable(plan)\n ? styleText('green', `\\nThis ${label} can be deployed.`)\n : styleText('red', `\\nThis ${label} can't be deployed.`),\n )\n\n renderIssues(output, 'Problems to fix:', problems)\n renderIssues(output, 'Warnings:', warnings)\n\n // A blocked deploy uploads nothing, so only list files for a deployable plan.\n if (isDeployable(plan) && plan.files.length > 0) {\n output.log(\n `\\nFiles to deploy (${plan.files.length} ${pluralize('file', plan.files.length)}, ${formatMB(totalBytes(plan.files))}):`,\n )\n for (const file of plan.files) {\n output.log(` ${file.path} (${formatMB(file.size)})`)\n }\n }\n}\n\nfunction renderIssues(output: Output, title: string, checks: DeployCheck[]): void {\n if (checks.length === 0) return\n\n output.log(`\\n${title}`)\n for (const check of checks) {\n const fix = check.solution ? `: ${check.solution}` : ''\n output.log(` ${statusIcon(check.status)} ${check.message}${fix}`)\n }\n}\n\nfunction formatMB(bytes: number): string {\n return `${(bytes / 1024 / 1024).toFixed(2)} MB`\n}\n\nfunction statusIcon(status: DeployCheck['status']): string {\n switch (status) {\n case 'fail': {\n return logSymbols.error\n }\n case 'skip': {\n return logSymbols.info\n }\n case 'warn': {\n return logSymbols.warning\n }\n default: {\n return logSymbols.success\n }\n }\n}\n"],"names":["readdir","stat","join","relative","sep","styleText","logSymbols","pluralize","listDeploymentFiles","sourceDir","fromDir","walk","dir","entries","withFileTypes","nested","Promise","all","map","entry","full","name","isDirectory","resolve","flat","absolute","files","file","path","split","size","toSorted","a","b","localeCompare","isDeployable","plan","checks","every","check","status","totalBytes","reduce","sum","deploymentPlanToJson","errors","warnings","message","solution","push","applicationType","type","applicationVersion","version","target","renderDeploymentPlan","output","label","problems","filter","log","statusIcon","renderIssues","length","formatMB","title","fix","bytes","toFixed","error","info","warning","success"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,IAAI,QAAO,mBAAkB;AAC9C,SAAQC,IAAI,EAAEC,QAAQ,EAAEC,GAAG,QAAO,YAAW;AAC7C,SAAQC,SAAS,QAAO,YAAW;AAGnC,SAAQC,UAAU,QAAO,sBAAqB;AAE9C,SAAQC,SAAS,QAAO,0BAAyB;AAoBjD;;;CAGC,GACD,OAAO,eAAeC,oBACpBC,SAAiB,EACjBC,OAAe;IAEf,MAAMC,OAAO,OAAOC;QAClB,IAAIC;QACJ,IAAI;YACFA,UAAU,MAAMb,QAAQY,KAAK;gBAACE,eAAe;YAAI;QACnD,EAAE,OAAM;YACN,OAAO,EAAE;QACX;QACA,MAAMC,SAAS,MAAMC,QAAQC,GAAG,CAC9BJ,QAAQK,GAAG,CAAC,CAACC;YACX,MAAMC,OAAOlB,KAAKU,KAAKO,MAAME,IAAI;YACjC,OAAOF,MAAMG,WAAW,KAAKX,KAAKS,QAAQJ,QAAQO,OAAO,CAAC;gBAACH;aAAK;QAClE;QAEF,OAAOL,OAAOS,IAAI;IACpB;IAEA,MAAMC,WAAW,MAAMd,KAAKF;IAC5B,MAAMiB,QAAQ,MAAMV,QAAQC,GAAG,CAC7BQ,SAASP,GAAG,CAAC,OAAOS,OAAU,CAAA;YAC5B,8EAA8E;YAC9EC,MAAMzB,SAASO,SAASiB,MAAME,KAAK,CAACzB,KAAKF,IAAI,CAAC;YAC9C4B,MAAM,AAAC,CAAA,MAAM7B,KAAK0B,KAAI,EAAGG,IAAI;QAC/B,CAAA;IAEF,OAAOJ,MAAMK,QAAQ,CAAC,CAACC,GAAGC,IAAMD,EAAEJ,IAAI,CAACM,aAAa,CAACD,EAAEL,IAAI;AAC7D;AAEA,OAAO,SAASO,aAAaC,IAAoB;IAC/C,OAAOA,KAAKC,MAAM,CAACC,KAAK,CAAC,CAACC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WAAWrB,MAA6B;IAC/C,OAAQA;QACN,KAAK;YAAQ;gBACX,OAAOlC,WAAW+D,KAAK;YACzB;QACA,KAAK;YAAQ;gBACX,OAAO/D,WAAWgE,IAAI;YACxB;QACA,KAAK;YAAQ;gBACX,OAAOhE,WAAWiE,OAAO;YAC3B;QACA;YAAS;gBACP,OAAOjE,WAAWkE,OAAO;YAC3B;IACF;AACF"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds (or creates) the user application a deploy targets — the interactive
|
|
3
|
+
* adapter that turns the resolveDeployTarget verdicts into prompts, creation,
|
|
4
|
+
* and exits. Dry runs consume the same verdicts read-only (see deployChecks).
|
|
5
|
+
*/ import { select, Separator, spinner } from '@sanity/cli-core/ux';
|
|
6
|
+
import { createUserApplication } from '../../services/userApplications.js';
|
|
7
|
+
import { getAppId } from '../../util/appId.js';
|
|
8
|
+
import { getErrorMessage } from '../../util/getErrorMessage.js';
|
|
9
|
+
import { createFailFastReporter, describeAppTarget, describeAppTargetError, describeStudioTarget } from './deployChecks.js';
|
|
10
|
+
import { deployDebug } from './deployDebug.js';
|
|
11
|
+
import { resolveAppDeployTarget, resolveStudioDeployTarget } from './resolveDeployTarget.js';
|
|
12
|
+
export async function findUserApplication(options) {
|
|
13
|
+
const { cliConfig, organizationId, output, title, unattended = false } = options;
|
|
14
|
+
const spin = spinner('Checking application info...').start();
|
|
15
|
+
let resolution;
|
|
16
|
+
try {
|
|
17
|
+
resolution = await resolveAppDeployTarget({
|
|
18
|
+
appId: getAppId(cliConfig),
|
|
19
|
+
organizationId
|
|
20
|
+
});
|
|
21
|
+
deployDebug('Resolved app deploy target', resolution);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
spin.clear();
|
|
24
|
+
deployDebug('Error finding user application for app', error);
|
|
25
|
+
output.error(describeAppTargetError(error, organizationId), {
|
|
26
|
+
exit: 1
|
|
27
|
+
});
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (resolution.type === 'found') {
|
|
31
|
+
spin.succeed();
|
|
32
|
+
return resolution.application;
|
|
33
|
+
}
|
|
34
|
+
// null tells the caller to create. Unattended runs can only create with a
|
|
35
|
+
// --title; picking among existing apps (needs-input) always needs a prompt.
|
|
36
|
+
if (resolution.type === 'would-create' && (!unattended || title)) {
|
|
37
|
+
spin.info('No application ID configured');
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (resolution.type === 'needs-input' && !unattended) {
|
|
41
|
+
spin.info('No application ID configured');
|
|
42
|
+
return promptForExistingApp(resolution.existing);
|
|
43
|
+
}
|
|
44
|
+
spin.clear();
|
|
45
|
+
// 'blocked' diagnoses as a skip (its root cause fails an earlier check), so it
|
|
46
|
+
// needs an explicit exit here to not fall through to application creation
|
|
47
|
+
if (resolution.type === 'blocked') {
|
|
48
|
+
output.error(resolution.message, {
|
|
49
|
+
exit: 1
|
|
50
|
+
});
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
createFailFastReporter(output).report(describeAppTarget(resolution));
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
export async function findUserApplicationForStudio(options) {
|
|
57
|
+
const { appId, isExternal, output, projectId, studioHost, title, unattended = false, urlFlag } = options;
|
|
58
|
+
const urlType = isExternal ? 'external' : 'internal';
|
|
59
|
+
const spin = spinner('Checking project info').start();
|
|
60
|
+
let resolution;
|
|
61
|
+
try {
|
|
62
|
+
resolution = await resolveStudioDeployTarget({
|
|
63
|
+
appId,
|
|
64
|
+
isExternal,
|
|
65
|
+
projectId,
|
|
66
|
+
studioHost,
|
|
67
|
+
urlFlag
|
|
68
|
+
});
|
|
69
|
+
deployDebug('Resolved studio deploy target', resolution);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
spin.fail();
|
|
72
|
+
deployDebug('Error finding user application', error);
|
|
73
|
+
output.error(`Failed to resolve deploy target: ${getErrorMessage(error)}`, {
|
|
74
|
+
exit: 1
|
|
75
|
+
});
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
if (resolution.type === 'found') {
|
|
79
|
+
spin.succeed();
|
|
80
|
+
return resolution.application;
|
|
81
|
+
}
|
|
82
|
+
// The configured host isn't registered yet — a deploy registers it without prompting
|
|
83
|
+
if (resolution.type === 'would-create') {
|
|
84
|
+
spin.succeed();
|
|
85
|
+
return createFromConfiguredHost({
|
|
86
|
+
appHost: resolution.appHost,
|
|
87
|
+
output,
|
|
88
|
+
projectId,
|
|
89
|
+
title,
|
|
90
|
+
urlType
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (resolution.type === 'needs-input' && !unattended) {
|
|
94
|
+
spin.succeed();
|
|
95
|
+
// Nothing to select from — the caller prompts for a brand new host
|
|
96
|
+
if (resolution.existing.length === 0) return null;
|
|
97
|
+
return promptForExistingStudio({
|
|
98
|
+
existing: resolution.existing,
|
|
99
|
+
urlType
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
spin.fail();
|
|
103
|
+
// 'blocked' diagnoses as a skip (its root cause fails an earlier check), so it
|
|
104
|
+
// needs an explicit exit here
|
|
105
|
+
if (resolution.type === 'blocked') {
|
|
106
|
+
output.error(resolution.message, {
|
|
107
|
+
exit: 1
|
|
108
|
+
});
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
createFailFastReporter(output).report(describeStudioTarget(resolution, {
|
|
112
|
+
isExternal
|
|
113
|
+
}));
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The host is configured (studioHost or --url) but not registered yet:
|
|
118
|
+
* a deploy registers it without prompting.
|
|
119
|
+
*/ async function createFromConfiguredHost({ appHost, output, projectId, title, urlType }) {
|
|
120
|
+
if (urlType === 'external') {
|
|
121
|
+
output.log('Your project has not been registered with an external studio URL.');
|
|
122
|
+
output.log(`Registering ${appHost}`);
|
|
123
|
+
} else {
|
|
124
|
+
output.log('Your project has not been assigned a studio hostname.');
|
|
125
|
+
output.log(`Creating https://${appHost}.sanity.studio`);
|
|
126
|
+
}
|
|
127
|
+
output.log('');
|
|
128
|
+
const spin = spinner(urlType === 'external' ? 'Registering external studio' : 'Creating studio hostname').start();
|
|
129
|
+
try {
|
|
130
|
+
const response = await createUserApplication({
|
|
131
|
+
appType: 'studio',
|
|
132
|
+
body: {
|
|
133
|
+
appHost,
|
|
134
|
+
title,
|
|
135
|
+
type: 'studio',
|
|
136
|
+
urlType
|
|
137
|
+
},
|
|
138
|
+
projectId
|
|
139
|
+
});
|
|
140
|
+
spin.succeed();
|
|
141
|
+
return response;
|
|
142
|
+
} catch (e) {
|
|
143
|
+
spin.fail();
|
|
144
|
+
// if the name is taken, it should return a 409 so we relay to the user
|
|
145
|
+
if ([
|
|
146
|
+
402,
|
|
147
|
+
409
|
|
148
|
+
].includes(e?.statusCode)) {
|
|
149
|
+
output.error(e?.response?.body?.message || 'Bad request', {
|
|
150
|
+
exit: 1
|
|
151
|
+
});
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
// otherwise, it's a fatal error
|
|
155
|
+
deployDebug('Error creating user application from config', e);
|
|
156
|
+
output.error(`Error creating user application from config: ${e instanceof Error ? e.message : e}`, {
|
|
157
|
+
exit: 1
|
|
158
|
+
});
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async function promptForExistingApp(existing) {
|
|
163
|
+
const choices = existing.map((app)=>({
|
|
164
|
+
name: app.title ?? app.appHost,
|
|
165
|
+
value: app.appHost
|
|
166
|
+
}));
|
|
167
|
+
const selected = await select({
|
|
168
|
+
choices: [
|
|
169
|
+
{
|
|
170
|
+
name: 'New application deployment',
|
|
171
|
+
value: 'NEW_APP'
|
|
172
|
+
},
|
|
173
|
+
new Separator(' ════ Existing applications: ════ '),
|
|
174
|
+
...choices
|
|
175
|
+
],
|
|
176
|
+
loop: false,
|
|
177
|
+
message: 'Would you like to create a new application deployment, or deploy to an existing one?',
|
|
178
|
+
pageSize: 10
|
|
179
|
+
});
|
|
180
|
+
if (selected === 'NEW_APP') {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
return existing.find((app)=>app.appHost === selected);
|
|
184
|
+
}
|
|
185
|
+
async function promptForExistingStudio({ existing, urlType }) {
|
|
186
|
+
const newLabel = urlType === 'external' ? 'Register new external studio URL' : 'Create new studio hostname';
|
|
187
|
+
const selectMessage = urlType === 'external' ? 'Select existing external studio, or register a new one' : 'Select existing studio hostname, or create a new one';
|
|
188
|
+
const choices = existing.map((app)=>({
|
|
189
|
+
name: app.title ?? app.appHost,
|
|
190
|
+
value: app.appHost
|
|
191
|
+
}));
|
|
192
|
+
const selected = await select({
|
|
193
|
+
choices: [
|
|
194
|
+
{
|
|
195
|
+
name: newLabel,
|
|
196
|
+
value: 'NEW_STUDIO'
|
|
197
|
+
},
|
|
198
|
+
new Separator(),
|
|
199
|
+
...choices
|
|
200
|
+
],
|
|
201
|
+
message: selectMessage
|
|
202
|
+
});
|
|
203
|
+
if (selected === 'NEW_STUDIO') {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
return existing.find((app)=>app.appHost === selected);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
//# sourceMappingURL=findUserApplication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/findUserApplication.ts"],"sourcesContent":["/**\n * Finds (or creates) the user application a deploy targets — the interactive\n * adapter that turns the resolveDeployTarget verdicts into prompts, creation,\n * and exits. Dry runs consume the same verdicts read-only (see deployChecks).\n */\n\nimport {type CliConfig, type Output} from '@sanity/cli-core'\nimport {select, Separator, spinner} from '@sanity/cli-core/ux'\n\nimport {\n createUserApplication,\n type UserApplication,\n type UserApplicationResolved,\n} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {getErrorMessage} from '../../util/getErrorMessage.js'\nimport {\n createFailFastReporter,\n describeAppTarget,\n describeAppTargetError,\n describeStudioTarget,\n} from './deployChecks.js'\nimport {deployDebug} from './deployDebug.js'\nimport {resolveAppDeployTarget, resolveStudioDeployTarget} from './resolveDeployTarget.js'\n\ninterface FindUserApplicationOptions {\n cliConfig: CliConfig\n organizationId: string\n output: Output\n\n title?: string\n unattended?: boolean\n}\n\nexport async function findUserApplication(\n options: FindUserApplicationOptions,\n): Promise<UserApplicationResolved | null> {\n const {cliConfig, organizationId, output, title, unattended = false} = options\n const spin = spinner('Checking application info...').start()\n\n let resolution\n try {\n resolution = await resolveAppDeployTarget({appId: getAppId(cliConfig), organizationId})\n deployDebug('Resolved app deploy target', resolution)\n } catch (error) {\n spin.clear()\n deployDebug('Error finding user application for app', error)\n output.error(describeAppTargetError(error, organizationId), {exit: 1})\n return null\n }\n\n if (resolution.type === 'found') {\n spin.succeed()\n return resolution.application\n }\n\n // null tells the caller to create. Unattended runs can only create with a\n // --title; picking among existing apps (needs-input) always needs a prompt.\n if (resolution.type === 'would-create' && (!unattended || title)) {\n spin.info('No application ID configured')\n return null\n }\n if (resolution.type === 'needs-input' && !unattended) {\n spin.info('No application ID configured')\n return promptForExistingApp(resolution.existing)\n }\n\n spin.clear()\n // 'blocked' diagnoses as a skip (its root cause fails an earlier check), so it\n // needs an explicit exit here to not fall through to application creation\n if (resolution.type === 'blocked') {\n output.error(resolution.message, {exit: 1})\n return null\n }\n createFailFastReporter(output).report(describeAppTarget(resolution))\n return null\n}\n\ninterface FindUserApplicationForStudioOptions {\n isExternal: boolean\n output: Output\n projectId: string\n\n appId?: string\n studioHost?: string\n title?: string\n unattended?: boolean\n urlFlag?: string\n}\n\nexport async function findUserApplicationForStudio(\n options: FindUserApplicationForStudioOptions,\n): Promise<UserApplication | null> {\n const {\n appId,\n isExternal,\n output,\n projectId,\n studioHost,\n title,\n unattended = false,\n urlFlag,\n } = options\n const urlType = isExternal ? 'external' : 'internal'\n const spin = spinner('Checking project info').start()\n\n let resolution\n try {\n resolution = await resolveStudioDeployTarget({\n appId,\n isExternal,\n projectId,\n studioHost,\n urlFlag,\n })\n deployDebug('Resolved studio deploy target', resolution)\n } catch (error) {\n spin.fail()\n deployDebug('Error finding user application', error)\n output.error(`Failed to resolve deploy target: ${getErrorMessage(error)}`, {exit: 1})\n return null\n }\n\n if (resolution.type === 'found') {\n spin.succeed()\n return resolution.application\n }\n\n // The configured host isn't registered yet — a deploy registers it without prompting\n if (resolution.type === 'would-create') {\n spin.succeed()\n return createFromConfiguredHost({\n appHost: resolution.appHost,\n output,\n projectId,\n title,\n urlType,\n })\n }\n\n if (resolution.type === 'needs-input' && !unattended) {\n spin.succeed()\n // Nothing to select from — the caller prompts for a brand new host\n if (resolution.existing.length === 0) return null\n return promptForExistingStudio({existing: resolution.existing, urlType})\n }\n\n spin.fail()\n // 'blocked' diagnoses as a skip (its root cause fails an earlier check), so it\n // needs an explicit exit here\n if (resolution.type === 'blocked') {\n output.error(resolution.message, {exit: 1})\n return null\n }\n createFailFastReporter(output).report(describeStudioTarget(resolution, {isExternal}))\n return null\n}\n\n/**\n * The host is configured (studioHost or --url) but not registered yet:\n * a deploy registers it without prompting.\n */\nasync function createFromConfiguredHost({\n appHost,\n output,\n projectId,\n title,\n urlType,\n}: {\n appHost: string\n output: Output\n projectId: string\n title?: string\n urlType: 'external' | 'internal'\n}): Promise<UserApplication | null> {\n if (urlType === 'external') {\n output.log('Your project has not been registered with an external studio URL.')\n output.log(`Registering ${appHost}`)\n } else {\n output.log('Your project has not been assigned a studio hostname.')\n output.log(`Creating https://${appHost}.sanity.studio`)\n }\n output.log('')\n\n const spin = spinner(\n urlType === 'external' ? 'Registering external studio' : 'Creating studio hostname',\n ).start()\n\n try {\n const response = await createUserApplication({\n appType: 'studio',\n body: {appHost, title, type: 'studio', urlType},\n projectId,\n })\n spin.succeed()\n return response\n } catch (e) {\n spin.fail()\n // if the name is taken, it should return a 409 so we relay to the user\n if ([402, 409].includes(e?.statusCode)) {\n output.error(e?.response?.body?.message || 'Bad request', {exit: 1})\n return null\n }\n // otherwise, it's a fatal error\n deployDebug('Error creating user application from config', e)\n output.error(\n `Error creating user application from config: ${e instanceof Error ? e.message : e}`,\n {exit: 1},\n )\n return null\n }\n}\n\nasync function promptForExistingApp(\n existing: UserApplicationResolved[],\n): Promise<UserApplicationResolved | null> {\n const choices = existing.map((app) => ({name: app.title ?? app.appHost, value: app.appHost}))\n\n const selected = await select({\n choices: [\n {name: 'New application deployment', value: 'NEW_APP'},\n new Separator(' ════ Existing applications: ════ '),\n ...choices,\n ],\n loop: false,\n message: 'Would you like to create a new application deployment, or deploy to an existing one?',\n pageSize: 10,\n })\n\n if (selected === 'NEW_APP') {\n return null\n }\n\n return existing.find((app) => app.appHost === selected)!\n}\n\nasync function promptForExistingStudio({\n existing,\n urlType,\n}: {\n existing: UserApplication[]\n urlType: 'external' | 'internal'\n}): Promise<UserApplication | null> {\n const newLabel =\n urlType === 'external' ? 'Register new external studio URL' : 'Create new studio hostname'\n const selectMessage =\n urlType === 'external'\n ? 'Select existing external studio, or register a new one'\n : 'Select existing studio hostname, or create a new one'\n\n const choices = existing.map((app) => ({name: app.title ?? app.appHost, value: app.appHost}))\n\n const selected = await select({\n choices: [{name: newLabel, value: 'NEW_STUDIO'}, new Separator(), ...choices],\n message: selectMessage,\n })\n\n if (selected === 'NEW_STUDIO') {\n return null\n }\n\n return existing.find((app) => app.appHost === selected)!\n}\n"],"names":["select","Separator","spinner","createUserApplication","getAppId","getErrorMessage","createFailFastReporter","describeAppTarget","describeAppTargetError","describeStudioTarget","deployDebug","resolveAppDeployTarget","resolveStudioDeployTarget","findUserApplication","options","cliConfig","organizationId","output","title","unattended","spin","start","resolution","appId","error","clear","exit","type","succeed","application","info","promptForExistingApp","existing","message","report","findUserApplicationForStudio","isExternal","projectId","studioHost","urlFlag","urlType","fail","createFromConfiguredHost","appHost","length","promptForExistingStudio","log","response","appType","body","e","includes","statusCode","Error","choices","map","app","name","value","selected","loop","pageSize","find","newLabel","selectMessage"],"mappings":"AAAA;;;;CAIC,GAGD,SAAQA,MAAM,EAAEC,SAAS,EAAEC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C,MAAS,CAAA;YAACC,MAAMD,IAAItC,KAAK,IAAIsC,IAAIb,OAAO;YAAEe,OAAOF,IAAIb,OAAO;QAAA,CAAA;IAE1F,MAAMgB,WAAW,MAAM3D,OAAO;QAC5BsD,SAAS;YACP;gBAACG,MAAM;gBAA8BC,OAAO;YAAS;YACrD,IAAIzD,UAAU;eACXqD;SACJ;QACDM,MAAM;QACN3B,SAAS;QACT4B,UAAU;IACZ;IAEA,IAAIF,aAAa,WAAW;QAC1B,OAAO;IACT;IAEA,OAAO3B,SAAS8B,IAAI,CAAC,CAACN,MAAQA,IAAIb,OAAO,KAAKgB;AAChD;AAEA,eAAed,wBAAwB,EACrCb,QAAQ,EACRQ,OAAO,EAIR;IACC,MAAMuB,WACJvB,YAAY,aAAa,qCAAqC;IAChE,MAAMwB,gBACJxB,YAAY,aACR,2DACA;IAEN,MAAMc,UAAUtB,SAASuB,GAAG,CAAC,CAACC,MAAS,CAAA;YAACC,MAAMD,IAAItC,KAAK,IAAIsC,IAAIb,OAAO;YAAEe,OAAOF,IAAIb,OAAO;QAAA,CAAA;IAE1F,MAAMgB,WAAW,MAAM3D,OAAO;QAC5BsD,SAAS;YAAC;gBAACG,MAAMM;gBAAUL,OAAO;YAAY;YAAG,IAAIzD;eAAgBqD;SAAQ;QAC7ErB,SAAS+B;IACX;IAEA,IAAIL,aAAa,cAAc;QAC7B,OAAO;IACT;IAEA,OAAO3B,SAAS8B,IAAI,CAAC,CAACN,MAAQA,IAAIb,OAAO,KAAKgB;AAChD"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { getUserApplication, getUserApplications } from '../../services/userApplications.js';
|
|
2
|
+
import { normalizeUrl, validateUrl } from './urlUtils.js';
|
|
3
|
+
/**
|
|
4
|
+
* Owns the studio deploy-target rules: the --url flag over studioHost config,
|
|
5
|
+
* appId over appHost precedence, external URL normalization and validation.
|
|
6
|
+
* Both the real deploy and the dry run consume these verdicts.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/ export async function resolveStudioDeployTarget(options) {
|
|
10
|
+
const { appId, isExternal, projectId, studioHost, urlFlag } = options;
|
|
11
|
+
// appId wins over host config (and undeploy resolves it the same way): a
|
|
12
|
+
// configured appId deploys even when studioHost is stale or invalid, so it's
|
|
13
|
+
// resolved before any host validation.
|
|
14
|
+
if (appId) {
|
|
15
|
+
if (!projectId) {
|
|
16
|
+
return {
|
|
17
|
+
message: 'api.projectId is missing',
|
|
18
|
+
type: 'blocked'
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const application = await getUserApplication({
|
|
22
|
+
appId,
|
|
23
|
+
isSdkApp: false,
|
|
24
|
+
projectId
|
|
25
|
+
});
|
|
26
|
+
if (application) {
|
|
27
|
+
return {
|
|
28
|
+
application,
|
|
29
|
+
type: 'found'
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
message: `Cannot find app with app ID ${appId}`,
|
|
34
|
+
reason: 'app-not-found',
|
|
35
|
+
type: 'invalid'
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const { error: hostError, host: resolvedHost } = resolveAppHost({
|
|
39
|
+
isExternal,
|
|
40
|
+
studioHost,
|
|
41
|
+
url: urlFlag
|
|
42
|
+
});
|
|
43
|
+
if (hostError) {
|
|
44
|
+
return {
|
|
45
|
+
message: hostError,
|
|
46
|
+
reason: 'invalid-host',
|
|
47
|
+
type: 'invalid'
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// A host from config hasn't passed through the --url validation yet
|
|
51
|
+
let appHost = resolvedHost;
|
|
52
|
+
if (appHost && isExternal) {
|
|
53
|
+
appHost = normalizeUrl(appHost);
|
|
54
|
+
const validation = validateUrl(appHost);
|
|
55
|
+
if (validation !== true) {
|
|
56
|
+
return {
|
|
57
|
+
message: validation,
|
|
58
|
+
reason: 'invalid-host',
|
|
59
|
+
type: 'invalid'
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (appHost) {
|
|
64
|
+
if (!projectId) {
|
|
65
|
+
return {
|
|
66
|
+
message: 'api.projectId is missing',
|
|
67
|
+
type: 'blocked'
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const application = await getUserApplication({
|
|
71
|
+
appHost,
|
|
72
|
+
isSdkApp: false,
|
|
73
|
+
projectId
|
|
74
|
+
});
|
|
75
|
+
if (application) {
|
|
76
|
+
return {
|
|
77
|
+
application,
|
|
78
|
+
type: 'found'
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
appHost,
|
|
83
|
+
type: 'would-create'
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// Neither appId nor host configured — a deploy would prompt.
|
|
87
|
+
// Without a project there is nothing to list; a deploy would still prompt.
|
|
88
|
+
const existing = projectId ? await listStudioApplications(projectId, isExternal) : [];
|
|
89
|
+
return {
|
|
90
|
+
existing,
|
|
91
|
+
type: 'needs-input'
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Owns the app deploy-target rules: appId lookup, falling back to listing the
|
|
96
|
+
* organization's applications. Both the real deploy and the dry run consume
|
|
97
|
+
* these verdicts.
|
|
98
|
+
*
|
|
99
|
+
* @internal
|
|
100
|
+
*/ export async function resolveAppDeployTarget(options) {
|
|
101
|
+
const { appId, organizationId } = options;
|
|
102
|
+
if (appId) {
|
|
103
|
+
const application = await getUserApplication({
|
|
104
|
+
appId,
|
|
105
|
+
isSdkApp: true
|
|
106
|
+
});
|
|
107
|
+
if (application) {
|
|
108
|
+
return {
|
|
109
|
+
application,
|
|
110
|
+
type: 'found'
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
message: `Cannot find app with app ID ${appId}`,
|
|
115
|
+
reason: 'app-not-found',
|
|
116
|
+
type: 'invalid'
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (!organizationId) {
|
|
120
|
+
return {
|
|
121
|
+
message: 'app.organizationId is missing',
|
|
122
|
+
type: 'blocked'
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const existing = await getUserApplications({
|
|
126
|
+
appType: 'coreApp',
|
|
127
|
+
organizationId
|
|
128
|
+
});
|
|
129
|
+
if (existing?.length) {
|
|
130
|
+
return {
|
|
131
|
+
existing,
|
|
132
|
+
type: 'needs-input'
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
type: 'would-create'
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async function listStudioApplications(projectId, isExternal) {
|
|
140
|
+
const urlType = isExternal ? 'external' : 'internal';
|
|
141
|
+
const applications = await getUserApplications({
|
|
142
|
+
appType: 'studio',
|
|
143
|
+
projectId
|
|
144
|
+
});
|
|
145
|
+
// External deploys should only see external studios and vice versa
|
|
146
|
+
return applications?.filter((application)=>application.urlType === urlType) ?? [];
|
|
147
|
+
}
|
|
148
|
+
function resolveAppHost({ isExternal, studioHost, url }) {
|
|
149
|
+
if (!url) {
|
|
150
|
+
return {
|
|
151
|
+
host: studioHost
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
if (isExternal) {
|
|
155
|
+
const normalized = normalizeUrl(url);
|
|
156
|
+
const validation = validateUrl(normalized);
|
|
157
|
+
if (validation !== true) {
|
|
158
|
+
return {
|
|
159
|
+
error: validation
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
host: normalized
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
// For internal deploys, strip protocol prefix and .sanity.studio suffix if present
|
|
167
|
+
const hostname = url.replace(/^https?:\/\//i, '').replace(/\.sanity\.studio\/?$/i, '');
|
|
168
|
+
// If the result still looks like a URL (contains dots), the user likely meant --external
|
|
169
|
+
if (hostname.includes('.')) {
|
|
170
|
+
return {
|
|
171
|
+
error: `"${hostname}" does not look like a sanity.studio hostname. Did you mean to use --external?`
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
// Validate hostname characters (alphanumeric and hyphens only)
|
|
175
|
+
if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(hostname)) {
|
|
176
|
+
return {
|
|
177
|
+
error: `Invalid studio hostname "${hostname}". Hostnames can only contain letters, numbers, and hyphens.`
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
host: hostname
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=resolveDeployTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/resolveDeployTarget.ts"],"sourcesContent":["import {\n getUserApplication,\n getUserApplications,\n type UserApplication,\n type UserApplicationResolved,\n} from '../../services/userApplications.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\n/**\n * The read-only outcome of resolving where a deploy would go.\n *\n * - `found` — the deploy targets this existing user 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 */\ntype CommonDeployTargetResolution<App extends UserApplication = UserApplication> =\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 =\n | CommonDeployTargetResolution\n | {appHost: string; type: 'would-create'}\n\nexport type AppDeployTargetResolution =\n | CommonDeployTargetResolution<UserApplicationResolved>\n | {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> {\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 organizationId: string | undefined\n}): Promise<AppDeployTargetResolution> {\n const {appId, 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 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\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":["getUserApplication","getUserApplications","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","organizationId","appType","length","urlType","applications","filter","normalized","hostname","replace","includes","test"],"mappings":"AAAA,SACEA,kBAAkB,EAClBC,mBAAmB,QAG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B;QACA,OAAO;YAACL,MAAMe;QAAU;IAC1B;IAEA,mFAAmF;IACnF,MAAMC,WAAWb,IAAIc,OAAO,CAAC,iBAAiB,IAAIA,OAAO,CAAC,yBAAyB;IAEnF,yFAAyF;IACzF,IAAID,SAASE,QAAQ,CAAC,MAAM;QAC1B,OAAO;YACLpB,OAAO,CAAC,CAAC,EAAEkB,SAAS,8EAA8E,CAAC;QACrG;IACF;IAEA,+DAA+D;IAC/D,IAAI,CAAC,mCAAmCG,IAAI,CAACH,WAAW;QACtD,OAAO;YACLlB,OAAO,CAAC,yBAAyB,EAAEkB,SAAS,4DAA4D,CAAC;QAC3G;IACF;IAEA,OAAO;QAAChB,MAAMgB;IAAQ;AACxB"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { getSanityUrl } from '@sanity/cli-core';
|
|
2
|
+
export function getCoreAppUrl(organizationId, appId) {
|
|
3
|
+
return getSanityUrl(`/@${organizationId}/application/${appId}`);
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
6
|
* Validates that the given string is a valid http or https URL.
|
|
3
7
|
* Returns `true` if valid, or an error message string if invalid.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/urlUtils.ts"],"sourcesContent":["/**\n * Validates that the given string is a valid http or https URL.\n * Returns `true` if valid, or an error message string if invalid.\n */\nexport function validateUrl(url: string): string | true {\n try {\n const parsed = new URL(url)\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n return 'URL must use http or https protocol'\n }\n return true\n } catch {\n return 'Invalid URL. Please enter a valid http or https URL'\n }\n}\n\n/**\n * Normalizes a URL by removing trailing slashes.\n */\nexport function normalizeUrl(url: string): string {\n return url.replace(/\\/+$/, '')\n}\n"],"names":["validateUrl","url","parsed","URL","protocol","normalizeUrl","replace"],"mappings":"AAAA;;;CAGC,GACD,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/urlUtils.ts"],"sourcesContent":["import {getSanityUrl} from '@sanity/cli-core'\n\nexport function getCoreAppUrl(organizationId: string, appId: string): string {\n return getSanityUrl(`/@${organizationId}/application/${appId}`)\n}\n\n/**\n * Validates that the given string is a valid http or https URL.\n * Returns `true` if valid, or an error message string if invalid.\n */\nexport function validateUrl(url: string): string | true {\n try {\n const parsed = new URL(url)\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n return 'URL must use http or https protocol'\n }\n return true\n } catch {\n return 'Invalid URL. Please enter a valid http or https URL'\n }\n}\n\n/**\n * Normalizes a URL by removing trailing slashes.\n */\nexport function normalizeUrl(url: string): string {\n return url.replace(/\\/+$/, '')\n}\n"],"names":["getSanityUrl","getCoreAppUrl","organizationId","appId","validateUrl","url","parsed","URL","protocol","normalizeUrl","replace"],"mappings":"AAAA,SAAQA,YAAY,QAAO,mBAAkB;AAE7C,OAAO,SAASC,cAAcC,cAAsB,EAAEC,KAAa;IACjE,OAAOH,aAAa,CAAC,EAAE,EAAEE,eAAe,aAAa,EAAEC,OAAO;AAChE;AAEA;;;CAGC,GACD,OAAO,SAASC,YAAYC,GAAW;IACrC,IAAI;QACF,MAAMC,SAAS,IAAIC,IAAIF;QACvB,IAAIC,OAAOE,QAAQ,KAAK,WAAWF,OAAOE,QAAQ,KAAK,UAAU;YAC/D,OAAO;QACT;QACA,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA;;CAEC,GACD,OAAO,SAASC,aAAaJ,GAAW;IACtC,OAAOA,IAAIK,OAAO,CAAC,QAAQ;AAC7B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SANITY_CACHE_DIR } from '@sanity/cli-build/_internal/build';
|
|
2
|
-
import { isWorkbenchApp } from '@sanity/cli
|
|
2
|
+
import { isWorkbenchApp } from '@sanity/workbench-cli';
|
|
3
3
|
import { checkForDeprecatedAppId, getAppId } from '../../util/appId.js';
|
|
4
4
|
import { getSharedServerConfig } from '../../util/getSharedServerConfig.js';
|
|
5
5
|
import { resolveReactStrictMode } from '../../util/resolveReactStrictMode.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/dev/devAction.ts"],"sourcesContent":["import {SANITY_CACHE_DIR} from '@sanity/cli-build/_internal/build'\nimport {type CliConfig
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/dev/devAction.ts"],"sourcesContent":["import {SANITY_CACHE_DIR} from '@sanity/cli-build/_internal/build'\nimport {type CliConfig} from '@sanity/cli-core'\nimport {isWorkbenchApp} from '@sanity/workbench-cli'\n\nimport {checkForDeprecatedAppId, getAppId} from '../../util/appId.js'\nimport {getSharedServerConfig} from '../../util/getSharedServerConfig.js'\nimport {resolveReactStrictMode} from '../../util/resolveReactStrictMode.js'\nimport {extractCoreAppManifest} from '../manifest/extractCoreAppManifest.js'\nimport {extractStudioManifest} from '../manifest/extractStudioManifest.js'\nimport {startAppDevServer} from './servers/startAppDevServer.js'\nimport {startStudioDevServer} from './servers/startStudioDevServer.js'\nimport {type DevActionOptions} from './types.js'\n\nconst noop = async () => {}\n\n/**\n * Entry point for `sanity dev`. A plain studio/app starts a single dev server, as\n * before workbench existed. A workbench app (via `unstable_defineApp`) delegates to\n * `@sanity/workbench-cli`, injecting the CLI-domain pieces (app server, manifest\n * extraction, app id) and loading the package lazily so plain projects never do.\n */\nexport async function devAction(options: DevActionOptions): Promise<{close: () => Promise<void>}> {\n const {cliConfig, flags, isApp, output, workDir} = options\n\n const {httpHost, httpPort} = getSharedServerConfig({\n cliConfig,\n flags: {host: flags.host, port: flags.port},\n workDir,\n })\n\n // The app/studio server, parameterized per call; `announceUrl` is false when\n // the workbench announces the URL on its behalf.\n const startAppServer = (params: {announceUrl: boolean; cliConfig: CliConfig; httpPort: number}) =>\n (isApp ? startAppDevServer : startStudioDevServer)({\n ...options,\n announceUrl: params.announceUrl,\n cliConfig: params.cliConfig,\n httpPort: params.httpPort,\n })\n\n if (isWorkbenchApp(cliConfig?.app)) {\n // Lazy so a non-workbench `sanity dev` never loads the package. `doImport`\n // is path-based and doesn't apply to a bare specifier.\n // eslint-disable-next-line no-restricted-syntax\n const {startWorkbenchDev} = await import('@sanity/workbench-cli/dev')\n return startWorkbenchDev({\n appId: getAppId(cliConfig),\n cacheDir: `${SANITY_CACHE_DIR}/vite`,\n checkForDeprecatedAppId: () => checkForDeprecatedAppId({cliConfig, output}),\n cliConfig,\n extractManifest: isApp\n ? ({workDir: wd}) => extractCoreAppManifest({workDir: wd})\n : (params) => extractStudioManifest(params),\n httpHost,\n httpPort,\n isApp,\n output,\n // Runtime template needs a concrete boolean; collapse an unset config to off.\n reactStrictMode: resolveReactStrictMode(cliConfig) ?? false,\n startAppServer,\n workDir,\n })\n }\n\n // Plain non-workbench studio/app: one dev server announcing its own URL.\n const result = await startAppServer({announceUrl: true, cliConfig, httpPort})\n return {close: result.started ? result.close : noop}\n}\n"],"names":["SANITY_CACHE_DIR","isWorkbenchApp","checkForDeprecatedAppId","getAppId","getSharedServerConfig","resolveReactStrictMode","extractCoreAppManifest","extractStudioManifest","startAppDevServer","startStudioDevServer","noop","devAction","options","cliConfig","flags","isApp","output","workDir","httpHost","httpPort","host","port","startAppServer","params","announceUrl","app","startWorkbenchDev","appId","cacheDir","extractManifest","wd","reactStrictMode","result","close","started"],"mappings":"AAAA,SAAQA,gBAAgB,QAAO,oCAAmC;AAElE,SAAQC,cAAc,QAAO,wBAAuB;AAEpD,SAAQC,uBAAuB,EAAEC,QAAQ,QAAO,sBAAqB;AACrE,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,sBAAsB,QAAO,uCAAsC;AAC3E,SAAQC,sBAAsB,QAAO,wCAAuC;AAC5E,SAAQC,qBAAqB,QAAO,uCAAsC;AAC1E,SAAQC,iBAAiB,QAAO,iCAAgC;AAChE,SAAQC,oBAAoB,QAAO,oCAAmC;AAGtE,MAAMC,OAAO,WAAa;AAE1B;;;;;CAKC,GACD,OAAO,eAAeC,UAAUC,OAAyB;IACvD,MAAM,EAACC,SAA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