@sanity/workbench-cli 2.19.1 → 2.21.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/_exports/build.d.ts +3 -2
- package/dist/_exports/build.js.map +1 -1
- package/dist/_exports/defineApp-COehpvlC.d.ts +376 -0
- package/dist/_exports/deploy.d.ts +22 -44
- package/dist/_exports/deploy.js +2 -0
- package/dist/_exports/deploy.js.map +1 -1
- package/dist/_exports/{summarizeInterfaces-AM-QbtIA.d.ts → deploySummary-DU7_Vcyq.d.ts} +30 -4
- package/dist/_exports/dev.d.ts +1 -1
- package/dist/_exports/index.d.ts +22 -4
- package/dist/_exports/index.js +2 -1
- package/dist/_exports/index.js.map +1 -1
- package/dist/_exports/preview.d.ts +1 -1
- package/dist/_exports/{registry-DZWnj09G.d.ts → registry-Da2PAcT1.d.ts} +17 -11
- package/dist/_exports/{resolveWorkbenchConfig-_iD6fVUH.d.ts → resolveWorkbenchApp-Bn0tsSDM.d.ts} +5 -20
- package/dist/_exports/resolveWorkbenchConfig-DkrkqN9H.d.ts +10 -0
- package/dist/_exports/undeploy.d.ts +6 -6
- package/dist/_exports/undeploy.js +1 -0
- package/dist/_exports/undeploy.js.map +1 -1
- package/dist/actions/build/artifact.js +20 -1
- package/dist/actions/build/artifact.js.map +1 -1
- package/dist/actions/build/configs/artifact.js +10 -50
- package/dist/actions/build/configs/artifact.js.map +1 -1
- package/dist/actions/build/dashboardConfig/artifact.js +25 -0
- package/dist/actions/build/dashboardConfig/artifact.js.map +1 -0
- package/dist/actions/build/hotConfigListeners.js +34 -0
- package/dist/actions/build/hotConfigListeners.js.map +1 -0
- package/dist/actions/build/vite/optimize-deps.js +2 -1
- package/dist/actions/build/vite/optimize-deps.js.map +1 -1
- package/dist/actions/build/vite/plugins/plugin-sanity-extension-artifacts.js +3 -1
- package/dist/actions/build/vite/plugins/plugin-sanity-extension-artifacts.js.map +1 -1
- package/dist/actions/deploy/deployConfig.js +9 -7
- package/dist/actions/deploy/deployConfig.js.map +1 -1
- package/dist/actions/deploy/deployPayload.js.map +1 -1
- package/dist/actions/deploy/deploySummary.js +24 -5
- package/dist/actions/deploy/deploySummary.js.map +1 -1
- package/dist/actions/deploy/deployWorkbenchApp.js +31 -13
- package/dist/actions/deploy/deployWorkbenchApp.js.map +1 -1
- package/dist/actions/deploy/uploadDashboardConfig.js +34 -0
- package/dist/actions/deploy/uploadDashboardConfig.js.map +1 -0
- package/dist/actions/dev/deriveConfigs.js +17 -13
- package/dist/actions/dev/deriveConfigs.js.map +1 -1
- package/dist/actions/dev/registry.js +34 -20
- package/dist/actions/dev/registry.js.map +1 -1
- package/dist/actions/dev/startDevServerRegistration.js +20 -11
- package/dist/actions/dev/startDevServerRegistration.js.map +1 -1
- package/dist/actions/dev/startWorkbenchDev.js +2 -2
- package/dist/actions/dev/startWorkbenchDev.js.map +1 -1
- package/dist/actions/preview/serveBuiltApplication.js +9 -7
- package/dist/actions/preview/serveBuiltApplication.js.map +1 -1
- package/dist/actions/preview/startWorkbenchPreview.js +52 -19
- package/dist/actions/preview/startWorkbenchPreview.js.map +1 -1
- package/dist/actions/undeploy/workbenchUndeployAdapter.js +50 -3
- package/dist/actions/undeploy/workbenchUndeployAdapter.js.map +1 -1
- package/dist/contract.js +20 -3
- package/dist/contract.js.map +1 -1
- package/dist/dashboardConfig.js +5 -0
- package/dist/dashboardConfig.js.map +1 -0
- package/dist/defineApp.js +25 -2
- package/dist/defineApp.js.map +1 -1
- package/dist/deriveInterfaces.js +24 -13
- package/dist/deriveInterfaces.js.map +1 -1
- package/dist/readAppIcon.js +3 -3
- package/dist/readAppIcon.js.map +1 -1
- package/dist/resolveWorkbenchApp.js +3 -2
- package/dist/resolveWorkbenchApp.js.map +1 -1
- package/dist/resolveWorkbenchConfig.js +11 -16
- package/dist/resolveWorkbenchConfig.js.map +1 -1
- package/dist/services/applications.js +12 -1
- package/dist/services/applications.js.map +1 -1
- package/dist/services/dashboard-configs.js +54 -0
- package/dist/services/dashboard-configs.js.map +1 -0
- package/package.json +8 -8
- package/dist/_exports/contract-WrU3aOYd.d.ts +0 -187
- package/dist/_exports/defineApp-9ppP3UQR.d.ts +0 -175
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/deployConfig.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deployConfig.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {createGzip} from 'node:zlib'\n\nimport {subdebug} from '@sanity/cli-core'\nimport {c as createTar} from 'tar'\n\nimport {type WorkbenchConfigValue} from '../../contract.js'\nimport {createConfig, resolveSingletonInstallationId} from '../../services/installations.js'\nimport {summarizeGroup} from './summarizeInterfaces.js'\n\nconst debug = subdebug('deploy')\n\n/**\n * The org's active installation for an app type, or `undefined` when none is\n * installed. Read-only, so `--dry-run` can report deployability.\n * @internal\n */\nexport async function resolveInstallationId(options: {\n appType: string\n organizationId: string\n}): Promise<string | undefined> {\n switch (options.appType) {\n case 'media-library': {\n return resolveSingletonInstallationId(options.organizationId, 'media-library')\n }\n default: {\n throw new Error(`Cannot create config for unknown app type: ${options.appType}`)\n }\n }\n}\n\n/**\n * A report heading and item list for a config; a media library's `fields` are\n * one of potentially many shapes.\n * @internal\n */\nexport function summarizeConfig(config: WorkbenchConfigValue): string {\n const {appType} = config\n\n switch (appType) {\n case 'dashboard': {\n return `Dashboard configuration: ${config.src}`\n }\n case 'media-library': {\n return summarizeGroup('Media library fields', config.fields)\n }\n default: {\n appType satisfies never\n throw new Error(`Cannot summarize unknown app type: ${appType as string}`)\n }\n }\n}\n\n/**\n * Upload the built module-federation remote to the installation as its config\n * snapshot. `installationId` is resolved by the caller so `--dry-run` never\n * reaches this mutating step.\n * @internal\n */\nexport async function deployConfig(options: {\n appType: string\n installationId: string\n sourceDir: string\n version: string\n}): Promise<void> {\n const {appType, installationId, sourceDir, version} = options\n const tarball = createTar({cwd: dirname(sourceDir)}, [basename(sourceDir)]).pipe(createGzip())\n await createConfig(installationId, {tarball, version})\n\n debug('Deployed config for app type: %s', appType)\n}\n"],"names":["basename","dirname","createGzip","subdebug","c","createTar","createConfig","resolveSingletonInstallationId","summarizeGroup","debug","resolveInstallationId","options","appType","organizationId","Error","summarizeConfig","config","src","fields","deployConfig","installationId","sourceDir","version","tarball","cwd","pipe"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,UAAU,QAAO,YAAW;AAEpC,SAAQC,QAAQ,QAAO,mBAAkB;AACzC,SAAQC,KAAKC,SAAS,QAAO,MAAK;AAGlC,SAAQC,YAAY,EAAEC,8BAA8B,QAAO,kCAAiC;AAC5F,SAAQC,cAAc,QAAO,2BAA0B;AAEvD,MAAMC,QAAQN,SAAS;AAEvB;;;;CAIC,GACD,OAAO,eAAeO,sBAAsBC,OAG3C;IACC,OAAQA,QAAQC,OAAO;QACrB,KAAK;YAAiB;gBACpB,OAAOL,+BAA+BI,QAAQE,cAAc,EAAE;YAChE;QACA;YAAS;gBACP,MAAM,IAAIC,MAAM,CAAC,2CAA2C,EAAEH,QAAQC,OAAO,EAAE;YACjF;IACF;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASG,gBAAgBC,MAA4B;IAC1D,MAAM,EAACJ,OAAO,EAAC,GAAGI;IAElB,OAAQJ;QACN,KAAK;YAAa;gBAChB,OAAO,CAAC,yBAAyB,EAAEI,OAAOC,GAAG,EAAE;YACjD;QACA,KAAK;YAAiB;gBACpB,OAAOT,eAAe,wBAAwBQ,OAAOE,MAAM;YAC7D;QACA;YAAS;gBACPN;gBACA,MAAM,IAAIE,MAAM,CAAC,mCAAmC,EAAEF,SAAmB;YAC3E;IACF;AACF;AAEA;;;;;CAKC,GACD,OAAO,eAAeO,aAAaR,OAKlC;IACC,MAAM,EAACC,OAAO,EAAEQ,cAAc,EAAEC,SAAS,EAAEC,OAAO,EAAC,GAAGX;IACtD,MAAMY,UAAUlB,UAAU;QAACmB,KAAKvB,QAAQoB;IAAU,GAAG;QAACrB,SAASqB;KAAW,EAAEI,IAAI,CAACvB;IACjF,MAAMI,aAAac,gBAAgB;QAACG;QAASD;IAAO;IAEpDb,MAAM,oCAAoCG;AAC5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/deployPayload.ts"],"sourcesContent":["import {type DeployableWorkbenchApp} from './getWorkbench.js'\nimport {type DeployedView, type DeployedWebWorker} from './summarizeInterfaces.js'\n\n/** What a workbench app contributes to a deploy payload. */\nexport interface WorkbenchDeployPayload {\n slug: string\n title: string\n\n /**
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deployPayload.ts"],"sourcesContent":["import {type DeployableWorkbenchApp} from './getWorkbench.js'\nimport {type DeployedView, type DeployedWebWorker} from './summarizeInterfaces.js'\n\n/** What a workbench app contributes to a deploy payload. */\nexport interface WorkbenchDeployPayload {\n slug: string\n title: string\n\n /** Config summary. */\n config?: string\n services?: DeployedWebWorker[]\n views?: DeployedView[]\n visibility?: string\n}\n\n/**\n * Gated once so a plain app can't pick up a stray key: without a workbench\n * there is nothing to contribute. `views` and `services` travel together.\n */\nexport function toWorkbenchPayload(\n workbench: DeployableWorkbenchApp | null,\n {\n config,\n interfaces,\n title,\n }: {\n config?: string\n interfaces: {services: DeployedWebWorker[]; views: DeployedView[]} | null\n title: string\n },\n): Partial<WorkbenchDeployPayload> {\n if (!workbench) return {}\n const {services, views} = interfaces ?? {services: [], views: []}\n return {\n ...(config ? {config} : {}),\n ...(services.length > 0 || views.length > 0 ? {services, views} : {}),\n slug: workbench.slug,\n title,\n ...(workbench.visibility ? {visibility: workbench.visibility} : {}),\n }\n}\n"],"names":["toWorkbenchPayload","workbench","config","interfaces","title","services","views","length","slug","visibility"],"mappings":"AAeA;;;CAGC,GACD,OAAO,SAASA,mBACdC,SAAwC,EACxC,EACEC,MAAM,EACNC,UAAU,EACVC,KAAK,EAKN;IAED,IAAI,CAACH,WAAW,OAAO,CAAC;IACxB,MAAM,EAACI,QAAQ,EAAEC,KAAK,EAAC,GAAGH,cAAc;QAACE,UAAU,EAAE;QAAEC,OAAO,EAAE;IAAA;IAChE,OAAO;QACL,GAAIJ,SAAS;YAACA;QAAM,IAAI,CAAC,CAAC;QAC1B,GAAIG,SAASE,MAAM,GAAG,KAAKD,MAAMC,MAAM,GAAG,IAAI;YAACF;YAAUC;QAAK,IAAI,CAAC,CAAC;QACpEE,MAAMP,UAAUO,IAAI;QACpBJ;QACA,GAAIH,UAAUQ,UAAU,GAAG;YAACA,YAAYR,UAAUQ,UAAU;QAAA,IAAI,CAAC,CAAC;IACpE;AACF"}
|
|
@@ -14,23 +14,42 @@ export async function fetchDeploySummaryDetails(organizationId) {
|
|
|
14
14
|
userName
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
+
const CREATED_AS = {
|
|
18
|
+
config: '',
|
|
19
|
+
coreApp: ' as a new application',
|
|
20
|
+
studio: ' as a new studio'
|
|
21
|
+
};
|
|
17
22
|
export function formatDeploySummary(options) {
|
|
18
|
-
const {
|
|
23
|
+
const { created, durationMs, title, url, userName } = options;
|
|
19
24
|
const summary = formatSummary({
|
|
20
25
|
durationMs,
|
|
21
26
|
heading: `${title} deployed`,
|
|
22
|
-
isApp,
|
|
27
|
+
isApp: options.type === 'coreApp',
|
|
23
28
|
organization: options.organizationName ?? options.organizationId,
|
|
24
|
-
|
|
29
|
+
// A config has no app or studio of its own to name.
|
|
30
|
+
title: options.type === 'config' ? undefined : title,
|
|
25
31
|
url,
|
|
26
32
|
version: userName ? `just now by ${userName}` : 'just now'
|
|
27
33
|
});
|
|
28
|
-
const result = created ? `Created ${title}
|
|
34
|
+
const result = created ? `Created ${title}${CREATED_AS[options.type]}.` : `Updated ${title}.`;
|
|
29
35
|
const success = styleText('green', ` ${logSymbols.success} ${result}`);
|
|
30
|
-
const appIdHint = showAppIdHint ? `\n ${styleText('dim', 'Add')} deployment.appId: "${applicationId}" ${styleText('dim', 'to sanity.cli.ts so the next deploy updates it')}\n` : '';
|
|
36
|
+
const appIdHint = options.type !== 'config' && options.showAppIdHint ? `\n ${styleText('dim', 'Add')} deployment.appId: "${options.applicationId}" ${styleText('dim', 'to sanity.cli.ts so the next deploy updates it')}\n` : '';
|
|
31
37
|
return `${summary}
|
|
32
38
|
${success}
|
|
33
39
|
${appIdHint}`;
|
|
34
40
|
}
|
|
41
|
+
export function formatUndeploySummary(options) {
|
|
42
|
+
const summary = formatSummary({
|
|
43
|
+
durationMs: options.durationMs,
|
|
44
|
+
heading: `${options.title} undeployed`,
|
|
45
|
+
isApp: false,
|
|
46
|
+
organization: options.organizationName ?? options.organizationId,
|
|
47
|
+
url: options.url
|
|
48
|
+
});
|
|
49
|
+
const success = styleText('green', ` ${logSymbols.success} Deleted ${options.title}.`);
|
|
50
|
+
return `${summary}
|
|
51
|
+
${success}
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
35
54
|
|
|
36
55
|
//# sourceMappingURL=deploySummary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/deploySummary.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {logSymbols} from '@sanity/cli-core/ux'\n\nimport {getOrganization} from '../../services/organizations.js'\nimport {getCurrentUser} from '../../services/users.js'\nimport {formatSummary, SUMMARY_LOOKUP_TIMEOUT_MS} from '../summary.js'\n\nexport async function fetchDeploySummaryDetails(organizationId: string) {\n const signal = AbortSignal.timeout(SUMMARY_LOOKUP_TIMEOUT_MS)\n const [organizationName, userName] = await Promise.all([\n getOrganization(organizationId, signal)\n .then((org) => org.name)\n .catch(() => null),\n getCurrentUser(signal)\n .then((user) => user.name)\n .catch(() => null),\n ])\n\n return {organizationName, userName}\n}\n\nexport function formatDeploySummary(options:
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deploySummary.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {logSymbols} from '@sanity/cli-core/ux'\n\nimport {getOrganization} from '../../services/organizations.js'\nimport {getCurrentUser} from '../../services/users.js'\nimport {formatSummary, SUMMARY_LOOKUP_TIMEOUT_MS} from '../summary.js'\n\nexport async function fetchDeploySummaryDetails(organizationId: string) {\n const signal = AbortSignal.timeout(SUMMARY_LOOKUP_TIMEOUT_MS)\n const [organizationName, userName] = await Promise.all([\n getOrganization(organizationId, signal)\n .then((org) => org.name)\n .catch(() => null),\n getCurrentUser(signal)\n .then((user) => user.name)\n .catch(() => null),\n ])\n\n return {organizationName, userName}\n}\n\nconst CREATED_AS = {config: '', coreApp: ' as a new application', studio: ' as a new studio'}\n\nexport function formatDeploySummary(\n options: (\n | {applicationId: string; showAppIdHint: boolean; type: 'coreApp' | 'studio'}\n | {type: 'config'}\n ) & {\n created: boolean\n durationMs: number\n organizationId: string\n organizationName?: string | null\n title: string\n url: string\n userName?: string | null\n },\n): string {\n const {created, durationMs, title, url, userName} = options\n\n const summary = formatSummary({\n durationMs,\n heading: `${title} deployed`,\n isApp: options.type === 'coreApp',\n organization: options.organizationName ?? options.organizationId,\n // A config has no app or studio of its own to name.\n title: options.type === 'config' ? undefined : title,\n url,\n version: userName ? `just now by ${userName}` : 'just now',\n })\n const result = created ? `Created ${title}${CREATED_AS[options.type]}.` : `Updated ${title}.`\n const success = styleText('green', ` ${logSymbols.success} ${result}`)\n const appIdHint =\n options.type !== 'config' && options.showAppIdHint\n ? `\\n ${styleText('dim', 'Add')} deployment.appId: \"${options.applicationId}\" ${styleText('dim', 'to sanity.cli.ts so the next deploy updates it')}\\n`\n : ''\n\n return `${summary}\n${success}\n${appIdHint}`\n}\n\nexport function formatUndeploySummary(options: {\n durationMs: number\n organizationId: string\n organizationName?: string | null\n title: string\n url: string\n}): string {\n const summary = formatSummary({\n durationMs: options.durationMs,\n heading: `${options.title} undeployed`,\n isApp: false,\n organization: options.organizationName ?? options.organizationId,\n url: options.url,\n })\n const success = styleText('green', ` ${logSymbols.success} Deleted ${options.title}.`)\n\n return `${summary}\n${success}\n`\n}\n"],"names":["styleText","logSymbols","getOrganization","getCurrentUser","formatSummary","SUMMARY_LOOKUP_TIMEOUT_MS","fetchDeploySummaryDetails","organizationId","signal","AbortSignal","timeout","organizationName","userName","Promise","all","then","org","name","catch","user","CREATED_AS","config","coreApp","studio","formatDeploySummary","options","created","durationMs","title","url","summary","heading","isApp","type","organization","undefined","version","result","success","appIdHint","showAppIdHint","applicationId","formatUndeploySummary"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,UAAU,QAAO,sBAAqB;AAE9C,SAAQC,eAAe,QAAO,kCAAiC;AAC/D,SAAQC,cAAc,QAAO,0BAAyB;AACtD,SAAQC,aAAa,EAAEC,yBAAyB,QAAO,gBAAe;AAEtE,OAAO,eAAeC,0BAA0BC,cAAsB;IACpE,MAAMC,SAASC,YAAYC,OAAO,CAACL;IACnC,MAAM,CAACM,kBAAkBC,SAAS,GAAG,MAAMC,QAAQC,GAAG,CAAC;QACrDZ,gBAAgBK,gBAAgBC,QAC7BO,IAAI,CAAC,CAACC,MAAQA,IAAIC,IAAI,EACtBC,KAAK,CAAC,IAAM;QACff,eAAeK,QACZO,IAAI,CAAC,CAACI,OAASA,KAAKF,IAAI,EACxBC,KAAK,CAAC,IAAM;KAChB;IAED,OAAO;QAACP;QAAkBC;IAAQ;AACpC;AAEA,MAAMQ,aAAa;IAACC,QAAQ;IAAIC,SAAS;IAAyBC,QAAQ;AAAkB;AAE5F,OAAO,SAASC,oBACdC,OAWC;IAED,MAAM,EAACC,OAAO,EAAEC,UAAU,EAAEC,KAAK,EAAEC,GAAG,EAAEjB,QAAQ,EAAC,GAAGa;IAEpD,MAAMK,UAAU1B,cAAc;QAC5BuB;QACAI,SAAS,GAAGH,MAAM,SAAS,CAAC;QAC5BI,OAAOP,QAAQQ,IAAI,KAAK;QACxBC,cAAcT,QAAQd,gBAAgB,IAAIc,QAAQlB,cAAc;QAChE,oDAAoD;QACpDqB,OAAOH,QAAQQ,IAAI,KAAK,WAAWE,YAAYP;QAC/CC;QACAO,SAASxB,WAAW,CAAC,YAAY,EAAEA,UAAU,GAAG;IAClD;IACA,MAAMyB,SAASX,UAAU,CAAC,QAAQ,EAAEE,QAAQR,UAAU,CAACK,QAAQQ,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAEL,MAAM,CAAC,CAAC;IAC7F,MAAMU,UAAUtC,UAAU,SAAS,CAAC,EAAE,EAAEC,WAAWqC,OAAO,CAAC,CAAC,EAAED,QAAQ;IACtE,MAAME,YACJd,QAAQQ,IAAI,KAAK,YAAYR,QAAQe,aAAa,GAC9C,CAAC,IAAI,EAAExC,UAAU,OAAO,OAAO,oBAAoB,EAAEyB,QAAQgB,aAAa,CAAC,EAAE,EAAEzC,UAAU,OAAO,kDAAkD,EAAE,CAAC,GACrJ;IAEN,OAAO,GAAG8B,QAAQ;AACpB,EAAEQ,QAAQ;AACV,EAAEC,WAAW;AACb;AAEA,OAAO,SAASG,sBAAsBjB,OAMrC;IACC,MAAMK,UAAU1B,cAAc;QAC5BuB,YAAYF,QAAQE,UAAU;QAC9BI,SAAS,GAAGN,QAAQG,KAAK,CAAC,WAAW,CAAC;QACtCI,OAAO;QACPE,cAAcT,QAAQd,gBAAgB,IAAIc,QAAQlB,cAAc;QAChEsB,KAAKJ,QAAQI,GAAG;IAClB;IACA,MAAMS,UAAUtC,UAAU,SAAS,CAAC,EAAE,EAAEC,WAAWqC,OAAO,CAAC,SAAS,EAAEb,QAAQG,KAAK,CAAC,CAAC,CAAC;IAEtF,OAAO,GAAGE,QAAQ;AACpB,EAAEQ,QAAQ;AACV,CAAC;AACD"}
|
|
@@ -4,7 +4,8 @@ import { getErrorMessage } from '@sanity/cli-core/errors';
|
|
|
4
4
|
import { spinner } from '@sanity/cli-core/ux';
|
|
5
5
|
import { c as createTar } from 'tar';
|
|
6
6
|
import { deriveInterfaces } from '../../deriveInterfaces.js';
|
|
7
|
-
import {
|
|
7
|
+
import { readAppIcon } from '../../readAppIcon.js';
|
|
8
|
+
import { createApplication, createDeployment, deleteApplication, removeApplicationIcon, setApplicationIcon, setInterfaceIcon, updateApplication } from '../../services/applications.js';
|
|
8
9
|
function toBrettInterface(iface) {
|
|
9
10
|
const { id: _id, src: _src, ...declaration } = iface;
|
|
10
11
|
if ('type' in declaration) return declaration;
|
|
@@ -19,7 +20,7 @@ function toBrettInterface(iface) {
|
|
|
19
20
|
}
|
|
20
21
|
case 'panel':
|
|
21
22
|
{
|
|
22
|
-
const { surface, ...view } = declaration;
|
|
23
|
+
const { icon: _icon, surface, ...view } = declaration;
|
|
23
24
|
return {
|
|
24
25
|
...view,
|
|
25
26
|
type: surface
|
|
@@ -35,7 +36,7 @@ function toBrettInterface(iface) {
|
|
|
35
36
|
}
|
|
36
37
|
case 'window':
|
|
37
38
|
{
|
|
38
|
-
const { surface, ...view } = declaration;
|
|
39
|
+
const { icon: _icon, surface, ...view } = declaration;
|
|
39
40
|
return {
|
|
40
41
|
...view,
|
|
41
42
|
type: 'app'
|
|
@@ -89,7 +90,7 @@ function toBrettInterface(iface) {
|
|
|
89
90
|
* then sync its mutable metadata (`title`, and `slug`/`visibility` when set)
|
|
90
91
|
* and its icon from config. The deploy endpoint ignores these, so a redeploy
|
|
91
92
|
* patches them here alongside the new deployment. No `icon` removes the
|
|
92
|
-
* application's icon.
|
|
93
|
+
* application's icon. Each interface's `icon` goes on the interface Brett created for it.
|
|
93
94
|
*
|
|
94
95
|
* `onDeployed` fires the instant the deployment is live, before the metadata
|
|
95
96
|
* sync — so a caller can disarm a create-time rollback that must not delete an
|
|
@@ -99,22 +100,27 @@ function toBrettInterface(iface) {
|
|
|
99
100
|
* application's registered origin.
|
|
100
101
|
* @internal
|
|
101
102
|
*/ export async function deployWorkbenchApp(options) {
|
|
102
|
-
const { access, app, applicationId, icon, isApp, isAutoUpdating, isExternal = false, label = 'Deploying...', mfManifest, onDeployed, slug, sourceDir, title, version, visibility, workspaces } = options;
|
|
103
|
+
const { access, app, applicationId, icon, isApp, isAutoUpdating, isExternal = false, label = 'Deploying...', mfManifest, onDeployed, slug, sourceDir, title, version, visibility, workDir, workspaces } = options;
|
|
103
104
|
const tarball = isExternal ? undefined : createTar({
|
|
104
105
|
cwd: dirname(sourceDir)
|
|
105
106
|
}, [
|
|
106
107
|
basename(sourceDir)
|
|
107
108
|
]).pipe(createGzip());
|
|
109
|
+
// Read before deploying, so a bad icon path fails while nothing is live.
|
|
110
|
+
const interfaces = await Promise.all(deriveInterfaces(app, {
|
|
111
|
+
appTitle: title,
|
|
112
|
+
isApp
|
|
113
|
+
}).map(async (iface)=>({
|
|
114
|
+
brett: toBrettInterface(iface),
|
|
115
|
+
icon: 'icon' in iface && iface.icon ? await readAppIcon(workDir, iface.icon) : undefined
|
|
116
|
+
})));
|
|
108
117
|
const spin = spinner(label).start();
|
|
109
118
|
try {
|
|
110
|
-
await createDeployment({
|
|
119
|
+
const deployment = await createDeployment({
|
|
111
120
|
access,
|
|
112
121
|
applicationId,
|
|
113
122
|
// Brett assigns the id and resolves modules by `moduleId`, so neither travels.
|
|
114
|
-
interfaces:
|
|
115
|
-
appTitle: title,
|
|
116
|
-
isApp
|
|
117
|
-
}).map((iface)=>toBrettInterface(iface)),
|
|
123
|
+
interfaces: interfaces.map(({ brett })=>brett),
|
|
118
124
|
isAutoUpdating,
|
|
119
125
|
mfManifest,
|
|
120
126
|
tarball,
|
|
@@ -139,11 +145,23 @@ function toBrettInterface(iface) {
|
|
|
139
145
|
try {
|
|
140
146
|
await setApplicationIcon(applicationId, icon);
|
|
141
147
|
} catch (error) {
|
|
142
|
-
throw toIconRejection(error);
|
|
148
|
+
throw toIconRejection(error, 'The app icon was rejected', "The deployment is live with the application's previous icon. Change `app.icon`");
|
|
143
149
|
}
|
|
144
150
|
} else {
|
|
145
151
|
await removeApplicationIcon(applicationId);
|
|
146
152
|
}
|
|
153
|
+
for (const { brett: { name, type }, icon: interfaceIcon } of interfaces){
|
|
154
|
+
if (!interfaceIcon) continue;
|
|
155
|
+
const iface = deployment.interfaces.find((i)=>i.type === type && i.name === name);
|
|
156
|
+
if (!iface) {
|
|
157
|
+
throw new Error(`The deployment is live, but has no ${type} interface named "${name}" to set its icon on.`);
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
await setInterfaceIcon(applicationId, iface.id, interfaceIcon);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
throw toIconRejection(error, `The icon of view "${name}" was rejected`, "The deployment is live without it. Change the view's `icon`");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
147
165
|
spin.succeed();
|
|
148
166
|
} catch (error) {
|
|
149
167
|
spin.clear();
|
|
@@ -162,10 +180,10 @@ function toBrettInterface(iface) {
|
|
|
162
180
|
cause: error
|
|
163
181
|
});
|
|
164
182
|
}
|
|
165
|
-
/** A 4xx on
|
|
183
|
+
/** A 4xx on an icon upload is the image being rejected; name the server's reason. */ function toIconRejection(error, rejected, fix) {
|
|
166
184
|
const statusCode = error?.statusCode;
|
|
167
185
|
if (statusCode === undefined || statusCode < 400 || statusCode >= 500) return error;
|
|
168
|
-
return new Error(
|
|
186
|
+
return new Error(`${rejected}: ${getErrorMessage(error)}. ${fix} in sanity.cli.ts and deploy again.`, {
|
|
169
187
|
cause: error
|
|
170
188
|
});
|
|
171
189
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/deployWorkbenchApp.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {createGzip} from 'node:zlib'\n\nimport {type AppVisibility, type CliConfig} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {type ImageFile} from '@sanity/cli-core/images'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {c as createTar} from 'tar'\n\nimport {type DerivedInterface, deriveInterfaces} from '../../deriveInterfaces.js'\nimport {\n type Application,\n type BrettAccess,\n type BrettInterface,\n type BrettWorkspace,\n createApplication,\n createDeployment,\n deleteApplication,\n removeApplicationIcon,\n setApplicationIcon,\n updateApplication,\n} from '../../services/applications.js'\n\n/**\n * `rollback` undoes the creation, so a later failure leaves no record stranded at the slug.\n * @internal\n */\nexport interface CreatedApplication {\n application: Application\n rollback: () => Promise<void>\n}\n\nfunction toBrettInterface(iface: DerivedInterface): BrettInterface {\n const {id: _id, src: _src, ...declaration} = iface\n if ('type' in declaration) return declaration\n\n switch (declaration.surface) {\n case 'asset_source': {\n const {surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'panel': {\n const {surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'tile': {\n const {surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'window': {\n const {surface, ...view} = declaration\n return {...view, type: 'app'}\n }\n }\n}\n\n/**\n * Create a coreApp record (no deployment), so the CLI can build with its id\n * before shipping the first deployment. First deploy only.\n * @internal\n */\nexport async function createCoreApp(options: {\n isSingleton?: boolean\n name?: string\n organizationId: string\n slug: string\n title: string\n visibility?: AppVisibility\n}): Promise<CreatedApplication> {\n const spin = spinner('Creating application...').start()\n try {\n const application = await createApplication({...options, type: 'coreApp'})\n spin.succeed()\n return {application, rollback: () => deleteApplication(application.id)}\n } catch (error) {\n spin.fail()\n throw error\n }\n}\n\n/**\n * Create a studio record (no deployment).\n * @internal\n */\nexport async function createStudio(options: {\n externalUrl?: string\n name?: string\n organizationId: string\n projectId: string | undefined\n slug: string\n title: string\n visibility?: AppVisibility\n}): Promise<CreatedApplication> {\n const spin = spinner('Creating studio...').start()\n try {\n const application = await createApplication({...options, type: 'studio'})\n spin.succeed()\n return {application, rollback: () => deleteApplication(application.id)}\n } catch (error) {\n spin.fail()\n throw error\n }\n}\n\n/**\n * Ship a deployment to an already-created (or `deployment.appId`) application,\n * then sync its mutable metadata (`title`, and `slug`/`visibility` when set)\n * and its icon from config. The deploy endpoint ignores these, so a redeploy\n * patches them here alongside the new deployment. No `icon` removes the\n * application's icon.\n *\n * `onDeployed` fires the instant the deployment is live, before the metadata\n * sync — so a caller can disarm a create-time rollback that must not delete an\n * application once it has an active deployment.\n *\n * `isExternal` skips the tarball: the customer serves the build from the\n * application's registered origin.\n * @internal\n */\nexport async function deployWorkbenchApp(options: {\n access?: readonly BrettAccess[]\n app: CliConfig['app']\n applicationId: string\n icon?: ImageFile\n isApp: boolean\n isAutoUpdating: boolean\n isExternal?: boolean\n label?: string\n mfManifest: Record<string, unknown>\n onDeployed?: () => void\n /**\n * The address from config. Only `createApplication` used to send it, so an\n * app with a `deployment.appId` kept whatever slug it was created at.\n */\n slug?: string\n sourceDir: string\n title: string\n version: string\n visibility?: AppVisibility\n workspaces?: readonly BrettWorkspace[]\n}): Promise<void> {\n const {\n access,\n app,\n applicationId,\n icon,\n isApp,\n isAutoUpdating,\n isExternal = false,\n label = 'Deploying...',\n mfManifest,\n onDeployed,\n slug,\n sourceDir,\n title,\n version,\n visibility,\n workspaces,\n } = options\n const tarball = isExternal\n ? undefined\n : createTar({cwd: dirname(sourceDir)}, [basename(sourceDir)]).pipe(createGzip())\n\n const spin = spinner(label).start()\n try {\n await createDeployment({\n access,\n applicationId,\n // Brett assigns the id and resolves modules by `moduleId`, so neither travels.\n interfaces: deriveInterfaces(app, {appTitle: title, isApp}).map((iface) =>\n toBrettInterface(iface),\n ),\n isAutoUpdating,\n mfManifest,\n tarball,\n version,\n workspaces,\n })\n onDeployed?.()\n try {\n await updateApplication(applicationId, {\n title,\n ...(slug ? {slug} : {}),\n ...(visibility ? {visibility} : {}),\n })\n } catch (error) {\n throw toSlugRejection(error, slug)\n }\n if (icon) {\n try {\n await setApplicationIcon(applicationId, icon)\n } catch (error) {\n throw toIconRejection(error)\n }\n } else {\n await removeApplicationIcon(applicationId)\n }\n spin.succeed()\n } catch (error) {\n spin.clear()\n throw error\n }\n}\n\n/**\n * The slug is the one synced field the server validates — it must be free\n * within the organization, and a singleton app only accepts its reserved\n * identifiers — so a 4xx on the metadata patch is a rejected rename. Name the\n * slug and the server's reason; anything else propagates untouched.\n */\nfunction toSlugRejection(error: unknown, slug: string | undefined): unknown {\n const statusCode = (error as {statusCode?: number})?.statusCode\n if (!slug || statusCode === undefined || statusCode < 400 || statusCode >= 500) return error\n return new Error(\n `Slug \"${slug}\" was rejected: ${getErrorMessage(error)}. The deployment is live at the application's previous slug — change \\`app.slug\\` in sanity.cli.ts and deploy again.`,\n {cause: error},\n )\n}\n\n/** A 4xx on the icon upload is the image being rejected; name the server's reason. */\nfunction toIconRejection(error: unknown): unknown {\n const statusCode = (error as {statusCode?: number})?.statusCode\n if (statusCode === undefined || statusCode < 400 || statusCode >= 500) return error\n return new Error(\n `The app icon was rejected: ${getErrorMessage(error)}. The deployment is live with the application's previous icon. Change \\`app.icon\\` in sanity.cli.ts and deploy again.`,\n {cause: error},\n )\n}\n"],"names":["basename","dirname","createGzip","getErrorMessage","spinner","c","createTar","deriveInterfaces","createApplication","createDeployment","deleteApplication","removeApplicationIcon","setApplicationIcon","updateApplication","toBrettInterface","iface","id","_id","src","_src","declaration","surface","view","type","createCoreApp","options","spin","start","application","succeed","rollback","error","fail","createStudio","deployWorkbenchApp","access","app","applicationId","icon","isApp","isAutoUpdating","isExternal","label","mfManifest","onDeployed","slug","sourceDir","title","version","visibility","workspaces","tarball","undefined","cwd","pipe","interfaces","appTitle","map","toSlugRejection","toIconRejection","clear","statusCode","Error","cause"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,UAAU,QAAO,YAAW;AAGpC,SAAQC,eAAe,QAAO,0BAAyB;AAEvD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,KAAKC,SAAS,QAAO,MAAK;AAElC,SAA+BC,gBAAgB,QAAO,4BAA2B;AACjF,SAKEC,iBAAiB,EACjBC,gBAAgB,EAChBC,iBAAiB,EACjBC,qBAAqB,EACrBC,kBAAkB,EAClBC,iBAAiB,QACZ,iCAAgC;AAWvC,SAASC,iBAAiBC,KAAuB;IAC/C,MAAM,EAACC,IAAIC,GA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B;IACR;AACF;AAEA;;;;;CAKC,GACD,SAAS2B,gBAAgB3B,KAAc,EAAEc,IAAwB;IAC/D,MAAMgB,aAAc9B,OAAiC8B;IACrD,IAAI,CAAChB,QAAQgB,eAAeT,aAAaS,aAAa,OAAOA,cAAc,KAAK,OAAO9B;IACvF,OAAO,IAAI+B,MACT,CAAC,MAAM,EAAEjB,KAAK,gBAAgB,EAAE1C,gBAAgB4B,OAAO,oHAAoH,CAAC,EAC5K;QAACgC,OAAOhC;IAAK;AAEjB;AAEA,oFAAoF,GACpF,SAAS4B,gBAAgB5B,KAAc;IACrC,MAAM8B,aAAc9B,OAAiC8B;IACrD,IAAIA,eAAeT,aAAaS,aAAa,OAAOA,cAAc,KAAK,OAAO9B;IAC9E,OAAO,IAAI+B,MACT,CAAC,2BAA2B,EAAE3D,gBAAgB4B,OAAO,qHAAqH,CAAC,EAC3K;QAACgC,OAAOhC;IAAK;AAEjB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deployWorkbenchApp.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {createGzip} from 'node:zlib'\n\nimport {type AppVisibility, type CliConfig} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {type ImageFile} from '@sanity/cli-core/images'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {c as createTar} from 'tar'\n\nimport {type DerivedInterface, deriveInterfaces} from '../../deriveInterfaces.js'\nimport {readAppIcon} from '../../readAppIcon.js'\nimport {\n type Application,\n type BrettAccess,\n type BrettInterface,\n type BrettWorkspace,\n createApplication,\n createDeployment,\n deleteApplication,\n removeApplicationIcon,\n setApplicationIcon,\n setInterfaceIcon,\n updateApplication,\n} from '../../services/applications.js'\n\n/**\n * `rollback` undoes the creation, so a later failure leaves no record stranded at the slug.\n * @internal\n */\nexport interface CreatedApplication {\n application: Application\n rollback: () => Promise<void>\n}\n\nfunction toBrettInterface(iface: DerivedInterface): BrettInterface {\n const {id: _id, src: _src, ...declaration} = iface\n if ('type' in declaration) return declaration\n\n switch (declaration.surface) {\n case 'asset_source': {\n const {surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'panel': {\n const {icon: _icon, surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'tile': {\n const {surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'window': {\n const {icon: _icon, surface, ...view} = declaration\n return {...view, type: 'app'}\n }\n }\n}\n\n/**\n * Create a coreApp record (no deployment), so the CLI can build with its id\n * before shipping the first deployment. First deploy only.\n * @internal\n */\nexport async function createCoreApp(options: {\n isSingleton?: boolean\n name?: string\n organizationId: string\n slug: string\n title: string\n visibility?: AppVisibility\n}): Promise<CreatedApplication> {\n const spin = spinner('Creating application...').start()\n try {\n const application = await createApplication({...options, type: 'coreApp'})\n spin.succeed()\n return {application, rollback: () => deleteApplication(application.id)}\n } catch (error) {\n spin.fail()\n throw error\n }\n}\n\n/**\n * Create a studio record (no deployment).\n * @internal\n */\nexport async function createStudio(options: {\n externalUrl?: string\n name?: string\n organizationId: string\n projectId: string | undefined\n slug: string\n title: string\n visibility?: AppVisibility\n}): Promise<CreatedApplication> {\n const spin = spinner('Creating studio...').start()\n try {\n const application = await createApplication({...options, type: 'studio'})\n spin.succeed()\n return {application, rollback: () => deleteApplication(application.id)}\n } catch (error) {\n spin.fail()\n throw error\n }\n}\n\n/**\n * Ship a deployment to an already-created (or `deployment.appId`) application,\n * then sync its mutable metadata (`title`, and `slug`/`visibility` when set)\n * and its icon from config. The deploy endpoint ignores these, so a redeploy\n * patches them here alongside the new deployment. No `icon` removes the\n * application's icon. Each interface's `icon` goes on the interface Brett created for it.\n *\n * `onDeployed` fires the instant the deployment is live, before the metadata\n * sync — so a caller can disarm a create-time rollback that must not delete an\n * application once it has an active deployment.\n *\n * `isExternal` skips the tarball: the customer serves the build from the\n * application's registered origin.\n * @internal\n */\nexport async function deployWorkbenchApp(options: {\n access?: readonly BrettAccess[]\n app: CliConfig['app']\n applicationId: string\n icon?: ImageFile\n isApp: boolean\n isAutoUpdating: boolean\n isExternal?: boolean\n label?: string\n mfManifest: Record<string, unknown>\n onDeployed?: () => void\n /**\n * The address from config. Only `createApplication` used to send it, so an\n * app with a `deployment.appId` kept whatever slug it was created at.\n */\n slug?: string\n sourceDir: string\n title: string\n version: string\n visibility?: AppVisibility\n workDir: string\n workspaces?: readonly BrettWorkspace[]\n}): Promise<void> {\n const {\n access,\n app,\n applicationId,\n icon,\n isApp,\n isAutoUpdating,\n isExternal = false,\n label = 'Deploying...',\n mfManifest,\n onDeployed,\n slug,\n sourceDir,\n title,\n version,\n visibility,\n workDir,\n workspaces,\n } = options\n const tarball = isExternal\n ? undefined\n : createTar({cwd: dirname(sourceDir)}, [basename(sourceDir)]).pipe(createGzip())\n\n // Read before deploying, so a bad icon path fails while nothing is live.\n const interfaces = await Promise.all(\n deriveInterfaces(app, {appTitle: title, isApp}).map(async (iface) => ({\n brett: toBrettInterface(iface),\n icon: 'icon' in iface && iface.icon ? await readAppIcon(workDir, iface.icon) : undefined,\n })),\n )\n\n const spin = spinner(label).start()\n try {\n const deployment = await createDeployment({\n access,\n applicationId,\n // Brett assigns the id and resolves modules by `moduleId`, so neither travels.\n interfaces: interfaces.map(({brett}) => brett),\n isAutoUpdating,\n mfManifest,\n tarball,\n version,\n workspaces,\n })\n onDeployed?.()\n try {\n await updateApplication(applicationId, {\n title,\n ...(slug ? {slug} : {}),\n ...(visibility ? {visibility} : {}),\n })\n } catch (error) {\n throw toSlugRejection(error, slug)\n }\n if (icon) {\n try {\n await setApplicationIcon(applicationId, icon)\n } catch (error) {\n throw toIconRejection(\n error,\n 'The app icon was rejected',\n \"The deployment is live with the application's previous icon. Change `app.icon`\",\n )\n }\n } else {\n await removeApplicationIcon(applicationId)\n }\n for (const {\n brett: {name, type},\n icon: interfaceIcon,\n } of interfaces) {\n if (!interfaceIcon) continue\n\n const iface = deployment.interfaces.find((i) => i.type === type && i.name === name)\n if (!iface) {\n throw new Error(\n `The deployment is live, but has no ${type} interface named \"${name}\" to set its icon on.`,\n )\n }\n try {\n await setInterfaceIcon(applicationId, iface.id, interfaceIcon)\n } catch (error) {\n throw toIconRejection(\n error,\n `The icon of view \"${name}\" was rejected`,\n \"The deployment is live without it. Change the view's `icon`\",\n )\n }\n }\n spin.succeed()\n } catch (error) {\n spin.clear()\n throw error\n }\n}\n\n/**\n * The slug is the one synced field the server validates — it must be free\n * within the organization, and a singleton app only accepts its reserved\n * identifiers — so a 4xx on the metadata patch is a rejected rename. Name the\n * slug and the server's reason; anything else propagates untouched.\n */\nfunction toSlugRejection(error: unknown, slug: string | undefined): unknown {\n const statusCode = (error as {statusCode?: number})?.statusCode\n if (!slug || statusCode === undefined || statusCode < 400 || statusCode >= 500) return error\n return new Error(\n `Slug \"${slug}\" was rejected: ${getErrorMessage(error)}. The deployment is live at the application's previous slug — change \\`app.slug\\` in sanity.cli.ts and deploy again.`,\n {cause: error},\n )\n}\n\n/** A 4xx on an icon upload is the image being rejected; name the server's reason. */\nfunction toIconRejection(error: unknown, rejected: string, fix: string): unknown {\n const statusCode = (error as {statusCode?: number})?.statusCode\n if (statusCode === undefined || statusCode < 400 || statusCode >= 500) return error\n return new Error(\n `${rejected}: ${getErrorMessage(error)}. ${fix} in sanity.cli.ts and deploy again.`,\n {cause: error},\n )\n}\n"],"names":["basename","dirname","createGzip","getErrorMessage","spinner","c","createTar","deriveInterfaces","readAppIcon","createApplication","createDeployment","deleteApplication","removeApplicationIcon","setApplicationIcon","setInterfaceIcon","updateApplication","toBrettInterface","iface","id","_id","src","_src","declaration","surface","view","type","icon","_icon","createCoreApp","options","spin","start","application","succeed","rollback","error","fail","createStudio","deployWorkbenchApp","access","app","applicationId","isApp","isAutoUpdating","isExternal","label","mfManifest","onDeployed","slug","sourceDir","title","version","visibility","workDir","workspaces","tarball","undefined","cwd","pipe","interfaces","Promise","all","appTitle","map","brett","deployment","toSlugRejection","toIconRejection","name","interfaceIcon","find","i","Error","clear","statusCode","cause","rejected","fix"],"mappings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;QACAtC,KAAKG,OAAO;IACd,EAAE,OAAOE,OAAO;QACdL,KAAK2C,KAAK;QACV,MAAMtC;IACR;AACF;AAEA;;;;;CAKC,GACD,SAAS+B,gBAAgB/B,KAAc,EAAEa,IAAwB;IAC/D,MAAM0B,aAAcvC,OAAiCuC;IACrD,IAAI,CAAC1B,QAAQ0B,eAAelB,aAAakB,aAAa,OAAOA,cAAc,KAAK,OAAOvC;IACvF,OAAO,IAAIqC,MACT,CAAC,MAAM,EAAExB,KAAK,gBAAgB,EAAE7C,gBAAgBgC,OAAO,oHAAoH,CAAC,EAC5K;QAACwC,OAAOxC;IAAK;AAEjB;AAEA,mFAAmF,GACnF,SAASgC,gBAAgBhC,KAAc,EAAEyC,QAAgB,EAAEC,GAAW;IACpE,MAAMH,aAAcvC,OAAiCuC;IACrD,IAAIA,eAAelB,aAAakB,aAAa,OAAOA,cAAc,KAAK,OAAOvC;IAC9E,OAAO,IAAIqC,MACT,GAAGI,SAAS,EAAE,EAAEzE,gBAAgBgC,OAAO,EAAE,EAAE0C,IAAI,mCAAmC,CAAC,EACnF;QAACF,OAAOxC;IAAK;AAEjB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { basename, dirname } from 'node:path';
|
|
2
|
+
import { createGzip } from 'node:zlib';
|
|
3
|
+
import { subdebug } from '@sanity/cli-core';
|
|
4
|
+
import { c as createTar } from 'tar';
|
|
5
|
+
import { configContractVersion } from '../../contract.js';
|
|
6
|
+
import { createDashboard, createDashboardConfig, deleteDashboard } from '../../services/dashboard-configs.js';
|
|
7
|
+
const debug = subdebug('deploy');
|
|
8
|
+
export async function uploadDashboardConfig(options) {
|
|
9
|
+
const { dashboard, organizationId, sourceDir } = options;
|
|
10
|
+
const version = configContractVersion('dashboard');
|
|
11
|
+
const tarball = createTar({
|
|
12
|
+
cwd: dirname(sourceDir)
|
|
13
|
+
}, [
|
|
14
|
+
basename(sourceDir)
|
|
15
|
+
]).pipe(createGzip());
|
|
16
|
+
if (dashboard) {
|
|
17
|
+
return createDashboardConfig(dashboard.id, {
|
|
18
|
+
tarball,
|
|
19
|
+
version
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const created = await createDashboard(organizationId);
|
|
23
|
+
try {
|
|
24
|
+
return await createDashboardConfig(created.id, {
|
|
25
|
+
tarball,
|
|
26
|
+
version
|
|
27
|
+
});
|
|
28
|
+
} catch (err) {
|
|
29
|
+
await deleteDashboard(created.id).catch((cleanupErr)=>debug('Failed to remove Dashboard %s after a failed config upload: %O', created.id, cleanupErr));
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=uploadDashboardConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/uploadDashboardConfig.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {createGzip} from 'node:zlib'\n\nimport {subdebug} from '@sanity/cli-core'\nimport {c as createTar} from 'tar'\n\nimport {configContractVersion} from '../../contract.js'\nimport {\n createDashboard,\n createDashboardConfig,\n type Dashboard,\n deleteDashboard,\n} from '../../services/dashboard-configs.js'\n\nconst debug = subdebug('deploy')\n\nexport async function uploadDashboardConfig(options: {\n dashboard: Dashboard | undefined\n organizationId: string\n sourceDir: string\n}): Promise<void> {\n const {dashboard, organizationId, sourceDir} = options\n const version = configContractVersion('dashboard')\n const tarball = createTar({cwd: dirname(sourceDir)}, [basename(sourceDir)]).pipe(createGzip())\n\n if (dashboard) {\n return createDashboardConfig(dashboard.id, {tarball, version})\n }\n\n const created = await createDashboard(organizationId)\n\n try {\n return await createDashboardConfig(created.id, {tarball, version})\n } catch (err) {\n await deleteDashboard(created.id).catch((cleanupErr) =>\n debug(\n 'Failed to remove Dashboard %s after a failed config upload: %O',\n created.id,\n cleanupErr,\n ),\n )\n throw err\n }\n}\n"],"names":["basename","dirname","createGzip","subdebug","c","createTar","configContractVersion","createDashboard","createDashboardConfig","deleteDashboard","debug","uploadDashboardConfig","options","dashboard","organizationId","sourceDir","version","tarball","cwd","pipe","id","created","err","catch","cleanupErr"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,UAAU,QAAO,YAAW;AAEpC,SAAQC,QAAQ,QAAO,mBAAkB;AACzC,SAAQC,KAAKC,SAAS,QAAO,MAAK;AAElC,SAAQC,qBAAqB,QAAO,oBAAmB;AACvD,SACEC,eAAe,EACfC,qBAAqB,EAErBC,eAAe,QACV,sCAAqC;AAE5C,MAAMC,QAAQP,SAAS;AAEvB,OAAO,eAAeQ,sBAAsBC,OAI3C;IACC,MAAM,EAACC,SAAS,EAAEC,cAAc,EAAEC,SAAS,EAAC,GAAGH;IAC/C,MAAMI,UAAUV,sBAAsB;IACtC,MAAMW,UAAUZ,UAAU;QAACa,KAAKjB,QAAQc;IAAU,GAAG;QAACf,SAASe;KAAW,EAAEI,IAAI,CAACjB;IAEjF,IAAIW,WAAW;QACb,OAAOL,sBAAsBK,UAAUO,EAAE,EAAE;YAACH;YAASD;QAAO;IAC9D;IAEA,MAAMK,UAAU,MAAMd,gBAAgBO;IAEtC,IAAI;QACF,OAAO,MAAMN,sBAAsBa,QAAQD,EAAE,EAAE;YAACH;YAASD;QAAO;IAClE,EAAE,OAAOM,KAAK;QACZ,MAAMb,gBAAgBY,QAAQD,EAAE,EAAEG,KAAK,CAAC,CAACC,aACvCd,MACE,kEACAW,QAAQD,EAAE,EACVI;QAGJ,MAAMF;IACR;AACF"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { configContractVersion, ConfigSchema } from '../../contract.js';
|
|
2
2
|
import { resolveWorkbenchConfig } from '../../resolveWorkbenchConfig.js';
|
|
3
3
|
/**
|
|
4
4
|
* The named source files a config's generated module is built from, dispatched
|
|
5
5
|
* per app type — the projection the exposes-set id keys on, so the generic HMR
|
|
6
|
-
* tracker owns none of the per-type shape.
|
|
7
|
-
* handle, so a new config family has to register its shape here.
|
|
6
|
+
* tracker owns none of the per-type shape.
|
|
8
7
|
*/ export function deriveConfigEntries(config) {
|
|
9
|
-
|
|
8
|
+
const { appType } = config;
|
|
9
|
+
switch(appType){
|
|
10
|
+
case 'dashboard':
|
|
11
|
+
{
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
name: 'dashboard',
|
|
15
|
+
src: config.src
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
}
|
|
10
19
|
case 'media-library':
|
|
11
20
|
{
|
|
12
21
|
return config.fields.map((field)=>({
|
|
@@ -16,7 +25,8 @@ import { resolveWorkbenchConfig } from '../../resolveWorkbenchConfig.js';
|
|
|
16
25
|
}
|
|
17
26
|
default:
|
|
18
27
|
{
|
|
19
|
-
|
|
28
|
+
appType;
|
|
29
|
+
throw new Error(`Cannot derive entries for unknown app type: ${appType}`);
|
|
20
30
|
}
|
|
21
31
|
}
|
|
22
32
|
}
|
|
@@ -35,16 +45,10 @@ import { resolveWorkbenchConfig } from '../../resolveWorkbenchConfig.js';
|
|
|
35
45
|
const config = resolveWorkbenchConfig(cliConfig);
|
|
36
46
|
if (!config) return [];
|
|
37
47
|
const entry = {
|
|
38
|
-
|
|
39
|
-
fields: config.fields.map((field)=>({
|
|
40
|
-
name: field.name,
|
|
41
|
-
public: field.public,
|
|
42
|
-
src: field.src,
|
|
43
|
-
title: field.title
|
|
44
|
-
})),
|
|
48
|
+
...ConfigSchema.parse(config),
|
|
45
49
|
// A config keys on its target `appType`, not a fabricated slug.
|
|
46
50
|
moduleName: config.appType,
|
|
47
|
-
version:
|
|
51
|
+
version: configContractVersion(config.appType)
|
|
48
52
|
};
|
|
49
53
|
return [
|
|
50
54
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/dev/deriveConfigs.ts"],"sourcesContent":["import {type CliConfig} from '@sanity/cli-core'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/dev/deriveConfigs.ts"],"sourcesContent":["import {type CliConfig} from '@sanity/cli-core'\n\nimport {configContractVersion, ConfigSchema, type WorkbenchConfigValue} from '../../contract.js'\nimport {resolveWorkbenchConfig} from '../../resolveWorkbenchConfig.js'\nimport {type DevServerManifest} from './registry.js'\n\n/** One forwarded interface record on the dev-server registry entry. */\nexport type DevServerInterface = NonNullable<DevServerManifest['interfaces']>[number]\n\n/** One forwarded config on the dev-server registry entry. */\nexport type DevServerConfig = NonNullable<DevServerManifest['configs']>[number]\n\n/**\n * The named source files a config's generated module is built from, dispatched\n * per app type — the projection the exposes-set id keys on, so the generic HMR\n * tracker owns none of the per-type shape.\n */\nexport function deriveConfigEntries(config: WorkbenchConfigValue): {name: string; src: string}[] {\n const {appType} = config\n\n switch (appType) {\n case 'dashboard': {\n return [{name: 'dashboard', src: config.src}]\n }\n case 'media-library': {\n return config.fields.map((field) => ({name: field.name, src: field.src}))\n }\n default: {\n appType satisfies never\n throw new Error(`Cannot derive entries for unknown app type: ${appType as string}`)\n }\n }\n}\n\n/**\n * The fields' schema *values* can't serialize — the workbench loads them from\n * the federation module. `src` stays on so the exposes-set id keys on it and a\n * repoint rebuilds. `appType` routes the config to the singleton (no app id to\n * key on) and names the federation `moduleName`, so the alias no longer borrows\n * the app slug. `id` is a content hash of the entry — it fills the\n * installation-config id slot deployed apps get from the applications API,\n * and the workbench keys change detection on it. `version` is a string, like\n * the one Brett returns on a deployed `activeConfig`.\n */\nexport async function deriveConfigs(\n cliConfig: CliConfig | null | undefined,\n): Promise<DevServerConfig[]> {\n // Keyed on the config brand (its target `appType`), not on having fields — an\n // empty config is still a config; dev just has nothing local to load for it.\n const config = resolveWorkbenchConfig(cliConfig)\n if (!config) return []\n\n const entry = {\n ...ConfigSchema.parse(config),\n // A config keys on its target `appType`, not a fabricated slug.\n moduleName: config.appType,\n version: configContractVersion(config.appType),\n }\n\n return [{...entry, id: await contentHash(JSON.stringify(entry))}]\n}\n\n/**\n * SHA-256 of a string, as hex, via the Web Crypto API — available in both Node\n * and the browser. `node:crypto` can't be used: the Vite dev server's dep scan\n * pulls this module into the browser graph.\n */\nasync function contentHash(input: string): Promise<string> {\n // eslint-disable-next-line n-js/no-unsupported-features/node-builtins -- the Web Crypto global is available on our Node target and in the browser\n const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(input))\n return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('')\n}\n"],"names":["configContractVersion","ConfigSchema","resolveWorkbenchConfig","deriveConfigEntries","config","appType","name","src","fields","map","field","Error","deriveConfigs","cliConfig","entry","parse","moduleName","version","id","contentHash","JSON","stringify","input","digest","globalThis","crypto","subtle","TextEncoder","encode","Array","from","Uint8Array","byte","toString","padStart","join"],"mappings":"AAEA,SAAQA,qBAAqB,EAAEC,YAAY,QAAkC,oBAAmB;AAChG,SAAQC,sBAAsB,QAAO,kCAAiC;AAStE;;;;CAIC,GACD,OAAO,SAASC,oBAAoBC,MAA4B;IAC9D,MAAM,EAACC,OAAO,EAAC,GAAGD;IAElB,OAAQC;QACN,KAAK;YAAa;gBAChB,OAAO;oBAAC;wBAACC,MAAM;wBAAaC,KAAKH,OAAOG,GAAG;oBAAA;iBAAE;YAC/C;QACA,KAAK;YAAiB;gBACpB,OAAOH,OAAOI,MAAM,CAACC,GAAG,CAAC,CAACC,QAAW,CAAA;wBAACJ,MAAMI,MAAMJ,IAAI;wBAAEC,KAAKG,MAAMH,GAAG;oBAAA,CAAA;YACxE;QACA;YAAS;gBACPF;gBACA,MAAM,IAAIM,MAAM,CAAC,4CAA4C,EAAEN,SAAmB;YACpF;IACF;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,eAAeO,cACpBC,SAAuC;IAEvC,8EAA8E;IAC9E,6EAA6E;IAC7E,MAAMT,SAASF,uBAAuBW;IACtC,IAAI,CAACT,QAAQ,OAAO,EAAE;IAEtB,MAAMU,QAAQ;QACZ,GAAGb,aAAac,KAAK,CAACX,OAAO;QAC7B,gEAAgE;QAChEY,YAAYZ,OAAOC,OAAO;QAC1BY,SAASjB,sBAAsBI,OAAOC,OAAO;IAC/C;IAEA,OAAO;QAAC;YAAC,GAAGS,KAAK;YAAEI,IAAI,MAAMC,YAAYC,KAAKC,SAAS,CAACP;QAAO;KAAE;AACnE;AAEA;;;;CAIC,GACD,eAAeK,YAAYG,KAAa;IACtC,kJAAkJ;IAClJ,MAAMC,SAAS,MAAMC,WAAWC,MAAM,CAACC,MAAM,CAACH,MAAM,CAAC,WAAW,IAAII,cAAcC,MAAM,CAACN;IACzF,OAAOO,MAAMC,IAAI,CAAC,IAAIC,WAAWR,SAAS,CAACS,OAASA,KAAKC,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG,MAAMC,IAAI,CAAC;AAC/F"}
|
|
@@ -3,7 +3,7 @@ import { join } from 'node:path';
|
|
|
3
3
|
import { coreAppManifestSchema, getSanityDataDir, studioManifestSchema, subdebug } from '@sanity/cli-core';
|
|
4
4
|
import { z } from 'zod/mini';
|
|
5
5
|
import { applicationReference } from '../../applicationReference.js';
|
|
6
|
-
import { TileInterfaceMetadataSchema, ViewPlacementMetadataSchema } from '../../contract.js';
|
|
6
|
+
import { ConfigSchema, TileInterfaceMetadataSchema, ViewPlacementMetadataSchema } from '../../contract.js';
|
|
7
7
|
import { canonicalizeWatchDir } from './canonicalizeWatchDir.js';
|
|
8
8
|
import { getProcessStartTime, isOurProcess } from './processLiveness.js';
|
|
9
9
|
/**
|
|
@@ -74,6 +74,17 @@ const interfaceBaseFields = {
|
|
|
74
74
|
type: z.literal('worker')
|
|
75
75
|
})
|
|
76
76
|
]);
|
|
77
|
+
const devServerConfigSchema = z.intersection(ConfigSchema, z.object({
|
|
78
|
+
// Content hash of the config — the workbench's change-detection key
|
|
79
|
+
// (see deriveConfigs).
|
|
80
|
+
id: z.string(),
|
|
81
|
+
// The app's `defineApplication` slug — the module-federation alias the
|
|
82
|
+
// workbench loads this config's live values from.
|
|
83
|
+
moduleName: z.optional(z.string()),
|
|
84
|
+
// The version the workbench federates this config's module under —
|
|
85
|
+
// a string, like the one Brett returns on a deployed `activeConfig`.
|
|
86
|
+
version: z.string()
|
|
87
|
+
}));
|
|
77
88
|
// Exported so test fixtures can validate against the same schema the registry
|
|
78
89
|
// parses with — see `aDevServerManifest`. Used internally by `getRegisteredServers`.
|
|
79
90
|
export const devServerManifestSchema = z.object({
|
|
@@ -82,25 +93,7 @@ export const devServerManifestSchema = z.object({
|
|
|
82
93
|
* Field schema *values* load from the federation module; each field's `src`
|
|
83
94
|
* rides along so a repoint bumps the exposes-set id and forces a rebuild.
|
|
84
95
|
* Lenient — the workbench is the authority.
|
|
85
|
-
*/ configs: z.optional(z.array(
|
|
86
|
-
// Identifies the owning app when it has no app id (singletons).
|
|
87
|
-
appType: z.optional(z.string()),
|
|
88
|
-
fields: z.array(z.object({
|
|
89
|
-
name: z.string(),
|
|
90
|
-
public: z.optional(z.boolean()),
|
|
91
|
-
src: z.string(),
|
|
92
|
-
title: z.string()
|
|
93
|
-
})),
|
|
94
|
-
// Content hash of the config — the workbench's change-detection key
|
|
95
|
-
// (see deriveConfigs).
|
|
96
|
-
id: z.string(),
|
|
97
|
-
// The app's `defineApplication` slug — the module-federation alias the
|
|
98
|
-
// workbench loads this config's live values from.
|
|
99
|
-
moduleName: z.optional(z.string()),
|
|
100
|
-
// The version the workbench federates this config's module under —
|
|
101
|
-
// a string, like the one Brett returns on a deployed `activeConfig`.
|
|
102
|
-
version: z.string()
|
|
103
|
-
}))),
|
|
96
|
+
*/ configs: z.optional(z.array(devServerConfigSchema)),
|
|
104
97
|
host: z.string(),
|
|
105
98
|
https: z.optional(z.boolean()),
|
|
106
99
|
/**
|
|
@@ -268,6 +261,27 @@ function runExitCleanups() {
|
|
|
268
261
|
}
|
|
269
262
|
};
|
|
270
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Why a server can't join its organization's Dashboard: a registered server
|
|
266
|
+
* already uses its bus id, or stands in for the same application.
|
|
267
|
+
*/ export function findServerConflict({ applicationId, id, organizationId, slug }) {
|
|
268
|
+
const server = getRegisteredServers().find((server)=>server.organizationId === organizationId && (server.id === id || applicationId && server.applicationId === applicationId));
|
|
269
|
+
if (!id || !server) {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
// A preview registers under its build id, so name both sides by slug.
|
|
273
|
+
const name = serverDisplayName(slug, id);
|
|
274
|
+
const serverName = serverDisplayName(server.slug, server.id);
|
|
275
|
+
const served = serverName === name ? `${name} is already served` : `${name} is the same application as ${serverName}, served`;
|
|
276
|
+
return `${served} by the dev server in ${server.workDir} on port ${server.port}, so the Dashboard can't tell them apart`;
|
|
277
|
+
}
|
|
278
|
+
function serverDisplayName(slug, id) {
|
|
279
|
+
// Configs register as `config:<appType>` and have no slug.
|
|
280
|
+
if (!slug && id?.startsWith('config:')) {
|
|
281
|
+
return `The ${id.slice('config:'.length)} configuration`;
|
|
282
|
+
}
|
|
283
|
+
return `"${slug ?? id}"`;
|
|
284
|
+
}
|
|
271
285
|
/**
|
|
272
286
|
* Read all manifest files from the registry, prune stale entries (dead PIDs),
|
|
273
287
|
* and return the live ones.
|