@sanity/workbench-cli 2.20.0 → 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 +18 -41
- package/dist/_exports/deploy.js +2 -0
- package/dist/_exports/deploy.js.map +1 -1
- package/dist/_exports/{summarizeInterfaces-BKIMEFzw.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-BI8kZVpy.d.ts → registry-Da2PAcT1.d.ts} +11 -7
- package/dist/_exports/{resolveWorkbenchConfig-Eex64aAA.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/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 +9 -5
- 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/startWorkbenchPreview.js +39 -11
- 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 +14 -0
- 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 +2 -2
- package/dist/deriveInterfaces.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 +1 -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-BeAds4Yi.d.ts +0 -191
- package/dist/_exports/defineApp-DSXAAr3V.d.ts +0 -177
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/dev/startWorkbenchDev.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {type CliConfig, type Output} from '@sanity/cli-core'\n\nimport {isWorkbenchApp} from '../../defineApp.js'\nimport {createServerLifecycle, toDisplayHost} from '../../util/serverOrchestration.js'\nimport {formatSummary} from '../summary.js'\nimport {type AppServerResult, startAppServerSupervisor} from './appServerSupervisor.js'\nimport {bindDevShortcuts} from './bindDevShortcuts.js'\nimport {fetchDevSummaryDetails, waitForDevSummaryDetails} from './devSummary.js'\nimport {type DevServerManifest} from './registry.js'\nimport {startDevServerRegistration} from './startDevServerRegistration.js'\nimport {\n startWorkbenchDevServer,\n startWorkbenchRemoteCoordinator,\n} from './startWorkbenchDevServer.js'\n\nexport interface StartWorkbenchDevOptions {\n /** Directory for the workbench Vite server's dependency cache. */\n cacheDir: string\n /** CLI-domain `app.id`/`deployment.appId` deprecation check, run before registering. */\n checkForDeprecatedAppId: () => void\n cliConfig: CliConfig\n /** Extract the project manifest to inline into the registry (studio-vs-app handled by the CLI). */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n /** Where the app server serves the app's icon. */\n iconUrl?: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n httpHost: string | undefined\n httpPort: number\n isApp: boolean\n output: Output\n reactStrictMode: boolean\n /** Start the app/studio dev server — the CLI owns the server, this orchestrates it. */\n startAppServer: (params: {\n cliConfig: CliConfig\n httpPort: number\n isRestarting?: boolean\n quiet?: boolean\n }) => Promise<AppServerResult>\n workDir: string\n}\n\n/**\n * Orchestrate the dev servers a workbench project needs: a singleton workbench\n * Vite server plus the app/studio dev server it renders, wired to the dev-server\n * registry so view/web worker edits re-sync live.\n *\n * A running workbench claims the configured port, so the app server binds the\n * next one. If the workbench can't start (package or port unavailable), the app\n * server falls back to the configured port and announces its own URL, exactly as\n * a plain `sanity dev` would.\n */\nexport async function startWorkbenchDev(\n options: StartWorkbenchDevOptions,\n): Promise<{close: () => Promise<void>}> {\n const {\n cacheDir,\n checkForDeprecatedAppId,\n cliConfig,\n extractManifest,\n httpHost,\n httpPort,\n isApp,\n output,\n reactStrictMode,\n startAppServer,\n workDir,\n } = options\n\n // The remote can't render itself, so it runs as a plain app server (not the\n // shell) that still bridges the registry.\n if (process.env.SANITY_INTERNAL_IS_WORKBENCH_REMOTE === 'true') {\n const remote = await startAppServer({cliConfig, httpPort})\n if (!remote.started) return {close: async () => {}}\n\n const coordinator = startWorkbenchRemoteCoordinator({server: remote.server})\n\n return {\n close: async () => {\n await coordinator.close()\n await remote.close()\n },\n }\n }\n\n // Unwound in reverse on any failure or on close(): the watcher stops before\n // the app server, and the supervisor waits out an in-flight rebuild.\n const {close, closers, installSignalHandlers} = createServerLifecycle()\n const startedAt = Date.now()\n const app = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined\n const organizationId = cliConfig.app?.organizationId\n const details = fetchDevSummaryDetails({\n idOrSlug: app && (cliConfig.deployment?.appId ?? app.slug),\n organizationId,\n })\n\n const workbench = await startWorkbenchDevServer({\n cacheDir,\n cliConfig,\n httpHost,\n httpPort,\n output,\n reactStrictMode,\n workDir,\n })\n closers.push(workbench.close)\n\n // A running workbench owns the configured port; the app server takes the next.\n // Without one it claims the configured port and announces its own URL.\n const appPort = workbench.workbenchAvailable ? workbench.workbenchPort + 1 : httpPort\n\n const supervised = await startAppServerSupervisor({\n cliConfig,\n start: (config, {isRestarting} = {}) =>\n startAppServer({\n cliConfig: config,\n httpPort: appPort,\n isRestarting,\n quiet: workbench.workbenchAvailable,\n }),\n workDir,\n }).catch(async (err) => {\n await close()\n throw err\n })\n\n if (!supervised.started) {\n // The app server already reported why (e.g. missing organization id). Hand\n // back a close that releases the workbench lock; nothing else came up.\n return {close}\n }\n const {supervisor} = supervised\n closers.push(supervisor.close)\n\n let dashboardAppPath: string | undefined\n try {\n // The deprecated-id check and manifest extractor are CLI-domain, injected here.\n checkForDeprecatedAppId()\n const registration = await startDevServerRegistration({\n cliConfig,\n extractManifest,\n isApp,\n onInterfaceSetChange: () => supervisor.rebuild(),\n output,\n server: supervisor.server,\n workDir,\n })\n closers.push(registration.close)\n dashboardAppPath = registration.path\n } catch (err) {\n // Registration runs after both servers are up; a failure here would leak the\n // workbench lock and dev servers without this teardown.\n await close()\n throw err\n }\n\n const durationMs = Date.now() - startedAt\n const {deployment, organizationName} = workbench.workbenchAvailable\n ? await waitForDevSummaryDetails(details)\n : {}\n\n installSignalHandlers()\n\n if (workbench.workbenchAvailable) {\n const url = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}${dashboardAppPath ?? ''}`\n let version = ''\n\n if (deployment) {\n const date = new Date(deployment.createdAt).toLocaleDateString('en-US', {\n day: 'numeric',\n month: 'short',\n year: 'numeric',\n })\n const by = deployment.deployedBy ? ` by ${deployment.deployedBy}` : ''\n version = `local preview ${styleText('dim', `· deployed ${date}${by}`)}`\n } else if (deployment === null) {\n version = `local preview ${styleText('dim', '· not deployed')}`\n }\n\n output.log(\n formatSummary({\n durationMs,\n heading: 'Sanity Dashboard ready',\n isApp,\n organization: organizationName ?? organizationId,\n title: app?.title,\n url,\n version,\n }),\n )\n\n const quit = () => void close().then(() => process.exit(0))\n closers.push(bindDevShortcuts({output, quit, url}))\n }\n\n return {close}\n}\n"],"names":["styleText","isWorkbenchApp","createServerLifecycle","toDisplayHost","formatSummary","startAppServerSupervisor","bindDevShortcuts","fetchDevSummaryDetails","waitForDevSummaryDetails","startDevServerRegistration","startWorkbenchDevServer","startWorkbenchRemoteCoordinator","startWorkbenchDev","options","cacheDir","checkForDeprecatedAppId","cliConfig","extractManifest","httpHost","httpPort","isApp","output","reactStrictMode","startAppServer","workDir","process","env","SANITY_INTERNAL_IS_WORKBENCH_REMOTE","remote","started","close","coordinator","server","closers","installSignalHandlers","startedAt","Date","now","app","undefined","organizationId","details","idOrSlug","deployment","appId","slug","workbench","push","appPort","workbenchAvailable","workbenchPort","supervised","start","config","isRestarting","quiet","catch","err","supervisor","dashboardAppPath","registration","onInterfaceSetChange","rebuild","path","durationMs","organizationName","url","version","date","createdAt","toLocaleDateString","day","month","year","by","deployedBy","log","heading","organization","title","quit","then","exit"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAInC,SAAQC,cAAc,QAAO,qBAAoB;AACjD,SAAQC,qBAAqB,EAAEC,aAAa,QAAO,oCAAmC;AACtF,SAAQC,aAAa,QAAO,gBAAe;AAC3C,SAA8BC,wBAAwB,QAAO,2BAA0B;AACvF,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,sBAAsB,EAAEC,wBAAwB,QAAO,kBAAiB;AAEhF,SAAQC,0BAA0B,QAAO,kCAAiC;AAC1E,SACEC,uBAAuB,EACvBC,+BAA+B,QAC1B,+BAA8B;AA+BrC;;;;;;;;;CASC,GACD,OAAO,eAAeC,kBACpBC,OAAiC;IAEjC,MAAM,EACJC,QAAQ,EACRC,uBAAuB,EACvBC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,eAAe,EACfC,cAAc,EACdC,OAAO,EACR,GAAGX;IAEJ,4EAA4E;IAC5E,0CAA0C;IAC1C,IAAIY,QAAQC,GAAG,CAACC,mCAAmC,KAAK,QAAQ;QAC9D,MAAMC,SAAS,MAAML,eAAe;YAACP;YAAWG;QAAQ;QACxD,IAAI,CAACS,OAAOC,OAAO,EAAE,OAAO;YAACC,OAAO,WAAa;QAAC;QAElD,MAAMC,cAAcpB,gCAAgC;YAACqB,QAAQJ,OAAOI,MAAM;QAAA;QAE1E,OAAO;YACLF,OAAO;gBACL,MAAMC,YAAYD,KAAK;gBACvB,MAAMF,OAAOE,KAAK;YACpB;QACF;IACF;IAEA,4EAA4E;IAC5E,qEAAqE;IACrE,MAAM,EAACA,KAAK,EAAEG,OAAO,EAAEC,qBAAqB,EAAC,GAAGhC;IAChD,MAAMiC,YAAYC,KAAKC,GAAG;IAC1B,MAAMC,MAAMrC,eAAee,UAAUsB,GAAG,IAAItB,UAAUsB,GAAG,GAAGC;IAC5D,MAAMC,iB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,EAACQ,UAAU,EAAEsB,gBAAgB,EAAC,GAAGnB,UAAUG,kBAAkB,GAC/D,MAAMzC,yBAAyBiC,WAC/B,CAAC;IAELP;IAEA,IAAIY,UAAUG,kBAAkB,EAAE;QAChC,MAAMiB,MAAM,CAAC,OAAO,EAAE/D,cAAc2C,UAAU5B,QAAQ,EAAE,CAAC,EAAE4B,UAAUI,aAAa,GAAGS,oBAAoB,IAAI;QAC7G,IAAIQ,UAAU;QAEd,IAAIxB,YAAY;YACd,MAAMyB,OAAO,IAAIhC,KAAKO,WAAW0B,SAAS,EAAEC,kBAAkB,CAAC,SAAS;gBACtEC,KAAK;gBACLC,OAAO;gBACPC,MAAM;YACR;YACA,MAAMC,KAAK/B,WAAWgC,UAAU,GAAG,CAAC,IAAI,EAAEhC,WAAWgC,UAAU,EAAE,GAAG;YACpER,UAAU,CAAC,cAAc,EAAEnE,UAAU,OAAO,CAAC,WAAW,EAAEoE,OAAOM,IAAI,GAAG;QAC1E,OAAO,IAAI/B,eAAe,MAAM;YAC9BwB,UAAU,CAAC,cAAc,EAAEnE,UAAU,OAAO,mBAAmB;QACjE;QAEAqB,OAAOuD,GAAG,CACRxE,cAAc;YACZ4D;YACAa,SAAS;YACTzD;YACA0D,cAAcb,oBAAoBzB;YAClCuC,OAAOzC,KAAKyC;YACZb;YACAC;QACF;QAGF,MAAMa,OAAO,IAAM,KAAKlD,QAAQmD,IAAI,CAAC,IAAMxD,QAAQyD,IAAI,CAAC;QACxDjD,QAAQc,IAAI,CAACzC,iBAAiB;YAACe;YAAQ2D;YAAMd;QAAG;IAClD;IAEA,OAAO;QAACpC;IAAK;AACf"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/dev/startWorkbenchDev.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {type CliConfig, type Output} from '@sanity/cli-core'\n\nimport {isWorkbenchApp, resolveAppTitle} from '../../defineApp.js'\nimport {createServerLifecycle, toDisplayHost} from '../../util/serverOrchestration.js'\nimport {formatSummary} from '../summary.js'\nimport {type AppServerResult, startAppServerSupervisor} from './appServerSupervisor.js'\nimport {bindDevShortcuts} from './bindDevShortcuts.js'\nimport {fetchDevSummaryDetails, waitForDevSummaryDetails} from './devSummary.js'\nimport {type DevServerManifest} from './registry.js'\nimport {startDevServerRegistration} from './startDevServerRegistration.js'\nimport {\n startWorkbenchDevServer,\n startWorkbenchRemoteCoordinator,\n} from './startWorkbenchDevServer.js'\n\nexport interface StartWorkbenchDevOptions {\n /** Directory for the workbench Vite server's dependency cache. */\n cacheDir: string\n /** CLI-domain `app.id`/`deployment.appId` deprecation check, run before registering. */\n checkForDeprecatedAppId: () => void\n cliConfig: CliConfig\n /** Extract the project manifest to inline into the registry (studio-vs-app handled by the CLI). */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n /** Where the app server serves the app's icon. */\n iconUrl?: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n httpHost: string | undefined\n httpPort: number\n isApp: boolean\n output: Output\n reactStrictMode: boolean\n /** Start the app/studio dev server — the CLI owns the server, this orchestrates it. */\n startAppServer: (params: {\n cliConfig: CliConfig\n httpPort: number\n isRestarting?: boolean\n quiet?: boolean\n }) => Promise<AppServerResult>\n workDir: string\n}\n\n/**\n * Orchestrate the dev servers a workbench project needs: a singleton workbench\n * Vite server plus the app/studio dev server it renders, wired to the dev-server\n * registry so view/web worker edits re-sync live.\n *\n * A running workbench claims the configured port, so the app server binds the\n * next one. If the workbench can't start (package or port unavailable), the app\n * server falls back to the configured port and announces its own URL, exactly as\n * a plain `sanity dev` would.\n */\nexport async function startWorkbenchDev(\n options: StartWorkbenchDevOptions,\n): Promise<{close: () => Promise<void>}> {\n const {\n cacheDir,\n checkForDeprecatedAppId,\n cliConfig,\n extractManifest,\n httpHost,\n httpPort,\n isApp,\n output,\n reactStrictMode,\n startAppServer,\n workDir,\n } = options\n\n // The remote can't render itself, so it runs as a plain app server (not the\n // shell) that still bridges the registry.\n if (process.env.SANITY_INTERNAL_IS_WORKBENCH_REMOTE === 'true') {\n const remote = await startAppServer({cliConfig, httpPort})\n if (!remote.started) return {close: async () => {}}\n\n const coordinator = startWorkbenchRemoteCoordinator({server: remote.server})\n\n return {\n close: async () => {\n await coordinator.close()\n await remote.close()\n },\n }\n }\n\n // Unwound in reverse on any failure or on close(): the watcher stops before\n // the app server, and the supervisor waits out an in-flight rebuild.\n const {close, closers, installSignalHandlers} = createServerLifecycle()\n const startedAt = Date.now()\n const app = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined\n const organizationId = cliConfig.app?.organizationId\n const details = fetchDevSummaryDetails({\n idOrSlug: app && (cliConfig.deployment?.appId ?? app.slug),\n organizationId,\n })\n\n const workbench = await startWorkbenchDevServer({\n cacheDir,\n cliConfig,\n httpHost,\n httpPort,\n output,\n reactStrictMode,\n workDir,\n })\n closers.push(workbench.close)\n\n // A running workbench owns the configured port; the app server takes the next.\n // Without one it claims the configured port and announces its own URL.\n const appPort = workbench.workbenchAvailable ? workbench.workbenchPort + 1 : httpPort\n\n const supervised = await startAppServerSupervisor({\n cliConfig,\n start: (config, {isRestarting} = {}) =>\n startAppServer({\n cliConfig: config,\n httpPort: appPort,\n isRestarting,\n quiet: workbench.workbenchAvailable,\n }),\n workDir,\n }).catch(async (err) => {\n await close()\n throw err\n })\n\n if (!supervised.started) {\n // The app server already reported why (e.g. missing organization id). Hand\n // back a close that releases the workbench lock; nothing else came up.\n return {close}\n }\n const {supervisor} = supervised\n closers.push(supervisor.close)\n\n let dashboardAppPath: string | undefined\n try {\n // The deprecated-id check and manifest extractor are CLI-domain, injected here.\n checkForDeprecatedAppId()\n const registration = await startDevServerRegistration({\n cliConfig,\n extractManifest,\n isApp,\n onInterfaceSetChange: () => supervisor.rebuild(),\n output,\n server: supervisor.server,\n workDir,\n })\n closers.push(registration.close)\n dashboardAppPath = registration.path\n } catch (err) {\n // Registration runs after both servers are up; a failure here would leak the\n // workbench lock and dev servers without this teardown.\n await close()\n throw err\n }\n\n const durationMs = Date.now() - startedAt\n const {deployment, organizationName} = workbench.workbenchAvailable\n ? await waitForDevSummaryDetails(details)\n : {}\n\n installSignalHandlers()\n\n if (workbench.workbenchAvailable) {\n const url = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}${dashboardAppPath ?? ''}`\n let version = ''\n\n if (deployment) {\n const date = new Date(deployment.createdAt).toLocaleDateString('en-US', {\n day: 'numeric',\n month: 'short',\n year: 'numeric',\n })\n const by = deployment.deployedBy ? ` by ${deployment.deployedBy}` : ''\n version = `local preview ${styleText('dim', `· deployed ${date}${by}`)}`\n } else if (deployment === null) {\n version = `local preview ${styleText('dim', '· not deployed')}`\n }\n\n output.log(\n formatSummary({\n durationMs,\n heading: 'Sanity Dashboard ready',\n isApp,\n organization: organizationName ?? organizationId,\n title: app && resolveAppTitle(app),\n url,\n version,\n }),\n )\n\n const quit = () => void close().then(() => process.exit(0))\n closers.push(bindDevShortcuts({output, quit, url}))\n }\n\n return {close}\n}\n"],"names":["styleText","isWorkbenchApp","resolveAppTitle","createServerLifecycle","toDisplayHost","formatSummary","startAppServerSupervisor","bindDevShortcuts","fetchDevSummaryDetails","waitForDevSummaryDetails","startDevServerRegistration","startWorkbenchDevServer","startWorkbenchRemoteCoordinator","startWorkbenchDev","options","cacheDir","checkForDeprecatedAppId","cliConfig","extractManifest","httpHost","httpPort","isApp","output","reactStrictMode","startAppServer","workDir","process","env","SANITY_INTERNAL_IS_WORKBENCH_REMOTE","remote","started","close","coordinator","server","closers","installSignalHandlers","startedAt","Date","now","app","undefined","organizationId","details","idOrSlug","deployment","appId","slug","workbench","push","appPort","workbenchAvailable","workbenchPort","supervised","start","config","isRestarting","quiet","catch","err","supervisor","dashboardAppPath","registration","onInterfaceSetChange","rebuild","path","durationMs","organizationName","url","version","date","createdAt","toLocaleDateString","day","month","year","by","deployedBy","log","heading","organization","title","quit","then","exit"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAInC,SAAQC,cAAc,EAAEC,eAAe,QAAO,qB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IY,UAAUG,kBAAkB,EAAE;QAChC,MAAMiB,MAAM,CAAC,OAAO,EAAE/D,cAAc2C,UAAU5B,QAAQ,EAAE,CAAC,EAAE4B,UAAUI,aAAa,GAAGS,oBAAoB,IAAI;QAC7G,IAAIQ,UAAU;QAEd,IAAIxB,YAAY;YACd,MAAMyB,OAAO,IAAIhC,KAAKO,WAAW0B,SAAS,EAAEC,kBAAkB,CAAC,SAAS;gBACtEC,KAAK;gBACLC,OAAO;gBACPC,MAAM;YACR;YACA,MAAMC,KAAK/B,WAAWgC,UAAU,GAAG,CAAC,IAAI,EAAEhC,WAAWgC,UAAU,EAAE,GAAG;YACpER,UAAU,CAAC,cAAc,EAAEpE,UAAU,OAAO,CAAC,WAAW,EAAEqE,OAAOM,IAAI,GAAG;QAC1E,OAAO,IAAI/B,eAAe,MAAM;YAC9BwB,UAAU,CAAC,cAAc,EAAEpE,UAAU,OAAO,mBAAmB;QACjE;QAEAsB,OAAOuD,GAAG,CACRxE,cAAc;YACZ4D;YACAa,SAAS;YACTzD;YACA0D,cAAcb,oBAAoBzB;YAClCuC,OAAOzC,OAAOrC,gBAAgBqC;YAC9B4B;YACAC;QACF;QAGF,MAAMa,OAAO,IAAM,KAAKlD,QAAQmD,IAAI,CAAC,IAAMxD,QAAQyD,IAAI,CAAC;QACxDjD,QAAQc,IAAI,CAACzC,iBAAiB;YAACe;YAAQ2D;YAAMd;QAAG;IAClD;IAEA,OAAO;QAACpC;IAAK;AACf"}
|
|
@@ -7,9 +7,10 @@ import { isWorkbenchApp } from '../../defineApp.js';
|
|
|
7
7
|
import { deriveInterfaces } from '../../deriveInterfaces.js';
|
|
8
8
|
import { readAppIcon, toUrlPath } from '../../readAppIcon.js';
|
|
9
9
|
import { resolveWorkbenchApp } from '../../resolveWorkbenchApp.js';
|
|
10
|
+
import { resolveWorkbenchConfig } from '../../resolveWorkbenchConfig.js';
|
|
10
11
|
import { createServerLifecycle, toDisplayHost } from '../../util/serverOrchestration.js';
|
|
11
12
|
import { deriveConfigs } from '../dev/deriveConfigs.js';
|
|
12
|
-
import { dashboardPath, localAppIdentity, registerDevServer } from '../dev/registry.js';
|
|
13
|
+
import { dashboardPath, findServerConflict, localAppIdentity, registerDevServer } from '../dev/registry.js';
|
|
13
14
|
import { startWorkbenchDevServer } from '../dev/startWorkbenchDevServer.js';
|
|
14
15
|
import { serveBuiltApplication } from './serveBuiltApplication.js';
|
|
15
16
|
/**
|
|
@@ -24,7 +25,20 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
|
|
|
24
25
|
* own URL.
|
|
25
26
|
*/ export async function startWorkbenchPreview(options) {
|
|
26
27
|
const { cacheDir, checkForDeprecatedAppId, cliConfig, extractManifest, httpHost, httpPort, isApp, outDir, output, reactStrictMode, workDir } = options;
|
|
27
|
-
//
|
|
28
|
+
// Resolved before any server starts, so a bad icon path, a project that isn't set
|
|
29
|
+
// up for the Dashboard, or one it already serves fails with nothing to tear down.
|
|
30
|
+
const { id, workbenchApp } = await resolvePreviewTarget(cliConfig, outDir);
|
|
31
|
+
const applicationId = workbenchApp ? cliConfig.deployment?.appId : undefined;
|
|
32
|
+
const organizationId = cliConfig.app?.organizationId;
|
|
33
|
+
const conflict = findServerConflict({
|
|
34
|
+
applicationId,
|
|
35
|
+
id,
|
|
36
|
+
organizationId,
|
|
37
|
+
slug: workbenchApp?.slug
|
|
38
|
+
});
|
|
39
|
+
if (conflict) {
|
|
40
|
+
throw new Error(`${conflict}. Stop that server first.`);
|
|
41
|
+
}
|
|
28
42
|
const app = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined;
|
|
29
43
|
const appIcon = isApp ? app?.icon : undefined;
|
|
30
44
|
const iconUrlPath = (iconPath)=>`/${toUrlPath(workDir, path.resolve(workDir, iconPath))}`;
|
|
@@ -65,19 +79,13 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
|
|
|
65
79
|
// out of workbench-cli.
|
|
66
80
|
checkForDeprecatedAppId();
|
|
67
81
|
const configPath = (await findProjectRoot(workDir)).path;
|
|
68
|
-
const workbench = resolveWorkbenchApp(cliConfig);
|
|
69
|
-
if (!workbench) {
|
|
70
|
-
throw new Error('`sanity start` was invoked in an application that is not set up for the Dashboard');
|
|
71
|
-
}
|
|
72
|
-
const inlinedId = await readInlinedAppId(outDir);
|
|
73
82
|
const configs = await deriveConfigs(cliConfig);
|
|
74
|
-
const id = inlinedId ?? await buildAppId(workbench);
|
|
75
83
|
const interfaces = deriveInterfaces(cliConfig.app, {
|
|
76
84
|
iconUrl: (iconPath)=>`http://${remote.host}:${remote.port}${iconUrlPath(iconPath)}`,
|
|
77
85
|
isApp
|
|
78
86
|
});
|
|
79
87
|
const registration = registerDevServer({
|
|
80
|
-
applicationId
|
|
88
|
+
applicationId,
|
|
81
89
|
configs,
|
|
82
90
|
host: remote.host,
|
|
83
91
|
id,
|
|
@@ -89,9 +97,10 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
|
|
|
89
97
|
workDir
|
|
90
98
|
}),
|
|
91
99
|
manifestUpdatedAt: new Date().toISOString(),
|
|
100
|
+
organizationId,
|
|
92
101
|
port: remote.port,
|
|
93
102
|
projectId: cliConfig?.api?.projectId,
|
|
94
|
-
...localAppIdentity(
|
|
103
|
+
...workbenchApp && localAppIdentity(workbenchApp),
|
|
95
104
|
type: isApp ? 'coreApp' : 'studio',
|
|
96
105
|
workDir
|
|
97
106
|
});
|
|
@@ -99,7 +108,7 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
|
|
|
99
108
|
dashboardAppPath = dashboardPath({
|
|
100
109
|
id,
|
|
101
110
|
interfaces,
|
|
102
|
-
slug:
|
|
111
|
+
slug: workbenchApp?.slug,
|
|
103
112
|
type: isApp ? 'coreApp' : 'studio'
|
|
104
113
|
});
|
|
105
114
|
} catch (err) {
|
|
@@ -124,6 +133,25 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
|
|
|
124
133
|
close
|
|
125
134
|
};
|
|
126
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* What the preview registers: a config under its own id namespace (as in dev),
|
|
138
|
+
* or the workbench app under the id its build inlined.
|
|
139
|
+
*/ async function resolvePreviewTarget(cliConfig, outDir) {
|
|
140
|
+
const config = resolveWorkbenchConfig(cliConfig);
|
|
141
|
+
if (config) {
|
|
142
|
+
return {
|
|
143
|
+
id: `config:${config.appType}`
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const workbenchApp = resolveWorkbenchApp(cliConfig);
|
|
147
|
+
if (!workbenchApp) {
|
|
148
|
+
throw new Error('`sanity start` was invoked in an application that is not set up for the Dashboard');
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
id: await readInlinedAppId(outDir) ?? await buildAppId(workbenchApp),
|
|
152
|
+
workbenchApp
|
|
153
|
+
};
|
|
154
|
+
}
|
|
127
155
|
/** The id the build inlined into its bundle, or undefined when absent. */ async function readInlinedAppId(outDir) {
|
|
128
156
|
try {
|
|
129
157
|
return (await readFile(path.join(outDir, SANITY_APP_ID_FILE), 'utf8')).trim() || undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/preview/startWorkbenchPreview.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {type CliConfig, findProjectRoot, type Output} from '@sanity/cli-core'\n\nimport {buildAppId, SANITY_APP_ID_FILE} from '../../appId.js'\nimport {isWorkbenchApp} from '../../defineApp.js'\nimport {deriveInterfaces} from '../../deriveInterfaces.js'\nimport {readAppIcon, toUrlPath} from '../../readAppIcon.js'\nimport {resolveWorkbenchApp} from '../../resolveWorkbenchApp.js'\nimport {createServerLifecycle, toDisplayHost} from '../../util/serverOrchestration.js'\nimport {deriveConfigs} from '../dev/deriveConfigs.js'\nimport {\n dashboardPath,\n type DevServerManifest,\n localAppIdentity,\n registerDevServer,\n} from '../dev/registry.js'\nimport {startWorkbenchDevServer} from '../dev/startWorkbenchDevServer.js'\nimport {serveBuiltApplication} from './serveBuiltApplication.js'\n\nexport interface StartWorkbenchPreviewOptions {\n /** Directory for the workbench Vite server's dependency cache. */\n cacheDir: string\n /** CLI-domain `app.id`/`deployment.appId` deprecation check, run before registering. */\n checkForDeprecatedAppId: () => void\n cliConfig: CliConfig\n /** Extract the project manifest to inline into the registry (studio-vs-app handled by the CLI). */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n /** Where the preview serves the app's icon. */\n iconUrl?: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n httpHost: string\n httpPort: number\n isApp: boolean\n /** The built `dist` directory to serve as the federation remote. */\n outDir: string\n output: Output\n reactStrictMode: boolean\n workDir: string\n}\n\n/**\n * `sanity start` for a workbench app: serve a production build the way dev serves\n * a live one. The same singleton workbench shell renders it and the same registry\n * advertises it — only the remote differs, static files from the build output\n * instead of a live Vite dev server. There's no config watcher or rebuild: a\n * build is fixed, so nothing re-syncs.\n *\n * A running workbench claims the configured port, so the built remote binds the\n * next one. Without one the remote takes the configured port and announces its\n * own URL.\n */\nexport async function startWorkbenchPreview(\n options: StartWorkbenchPreviewOptions,\n): Promise<{close: () => Promise<void>}> {\n const {\n cacheDir,\n checkForDeprecatedAppId,\n cliConfig,\n extractManifest,\n httpHost,\n httpPort,\n isApp,\n outDir,\n output,\n reactStrictMode,\n workDir,\n } = options\n\n // Read before any server starts, so a bad icon path fails with nothing to tear down.\n const app = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined\n const appIcon = isApp ? app?.icon : undefined\n const iconUrlPath = (iconPath: string) =>\n `/${toUrlPath(workDir, path.resolve(workDir, iconPath))}`\n const icons = await Promise.all(\n [appIcon, ...(app?.views ?? []).map((view) => ('icon' in view ? view.icon : undefined))]\n .filter((iconPath) => iconPath !== undefined)\n .map(async (iconPath) => ({\n ...(await readAppIcon(workDir, iconPath)),\n path: iconUrlPath(iconPath),\n })),\n )\n\n const {close, closers, installSignalHandlers} = createServerLifecycle()\n\n const workbench = await startWorkbenchDevServer({\n cacheDir,\n cliConfig,\n httpHost,\n httpPort,\n output,\n reactStrictMode,\n workDir,\n })\n closers.push(workbench.close)\n\n const remotePort = workbench.workbenchAvailable ? workbench.workbenchPort + 1 : httpPort\n\n const remote = await serveBuiltApplication({\n cacheDir,\n httpHost,\n httpPort: remotePort,\n icons,\n outDir,\n workDir,\n }).catch(async (err) => {\n await close()\n throw err\n })\n closers.push(remote.close)\n\n let dashboardAppPath: string | undefined\n try {\n // Callers provide CLI-only validation and manifest extraction to keep them\n // out of workbench-cli.\n checkForDeprecatedAppId()\n const configPath = (await findProjectRoot(workDir)).path\n const workbench = resolveWorkbenchApp(cliConfig)\n\n if (!workbench) {\n throw new Error(\n '`sanity start` was invoked in an application that is not set up for the Dashboard',\n )\n }\n const inlinedId = await readInlinedAppId(outDir)\n const configs = await deriveConfigs(cliConfig)\n const id = inlinedId ?? (await buildAppId(workbench))\n const interfaces = deriveInterfaces(cliConfig.app, {\n iconUrl: (iconPath) => `http://${remote.host}:${remote.port}${iconUrlPath(iconPath)}`,\n isApp,\n })\n const registration = registerDevServer({\n applicationId: cliConfig.deployment?.appId,\n configs,\n host: remote.host,\n id,\n interfaces,\n manifest: await extractManifest({\n applicationId: id,\n configPath,\n iconUrl: appIcon && `http://${remote.host}:${remote.port}${iconUrlPath(appIcon)}`,\n workDir,\n }),\n manifestUpdatedAt: new Date().toISOString(),\n port: remote.port,\n projectId: cliConfig?.api?.projectId,\n ...localAppIdentity(workbench),\n type: isApp ? 'coreApp' : 'studio',\n workDir,\n })\n closers.push(async () => registration.release())\n dashboardAppPath = dashboardPath({\n id,\n interfaces,\n slug: workbench.slug,\n type: isApp ? 'coreApp' : 'studio',\n })\n } catch (err) {\n await close()\n throw err\n }\n\n if (workbench.workbenchAvailable) {\n const appUrl = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}${dashboardAppPath ?? ''}`\n output.log(`Dashboard preview server started at ${styleText(['blue', 'underline'], appUrl)}`)\n } else {\n const remoteUrl = `http://${toDisplayHost(remote.host)}:${remote.port}`\n output.log(`Serving build at ${styleText(['blue', 'underline'], remoteUrl)}`)\n }\n\n installSignalHandlers()\n\n return {close}\n}\n\n/** The id the build inlined into its bundle, or undefined when absent. */\nasync function readInlinedAppId(outDir: string): Promise<string | undefined> {\n try {\n return (await readFile(path.join(outDir, SANITY_APP_ID_FILE), 'utf8')).trim() || undefined\n } catch {\n return undefined\n }\n}\n"],"names":["readFile","path","styleText","findProjectRoot","buildAppId","SANITY_APP_ID_FILE","isWorkbenchApp","deriveInterfaces","readAppIcon","toUrlPath","resolveWorkbenchApp","createServerLifecycle","toDisplayHost","deriveConfigs","dashboardPath","localAppIdentity","registerDevServer","startWorkbenchDevServer","serveBuiltApplication","startWorkbenchPreview","options","cacheDir","checkForDeprecatedAppId","cliConfig","extractManifest","httpHost","httpPort","isApp","outDir","output","reactStrictMode","workDir","app","undefined","appIcon","icon","iconUrlPath","iconPath","resolve","icons","Promise","all","views","map","view","filter","close","closers","installSignalHandlers","workbench","push","remotePort","workbenchAvailable","workbenchPort","remote","catch","err","dashboardAppPath","configPath","Error","inlinedId","readInlinedAppId","configs","id","interfaces","iconUrl","host","port","registration","applicationId","deployment","appId","manifest","manifestUpdatedAt","Date","toISOString","projectId","api","type","release","slug","appUrl","log","remoteUrl","join","trim"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAwBC,eAAe,QAAoB,mBAAkB;AAE7E,SAAQC,UAAU,EAAEC,kBAAkB,QAAO,iBAAgB;AAC7D,SAAQC,cAAc,QAAO,qBAAoB;AACjD,SAAQC,gBAAgB,QAAO,4BAA2B;AAC1D,SAAQC,WAAW,EAAEC,SAAS,QAAO,uBAAsB;AAC3D,SAAQC,mBAAmB,QAAO,+BAA8B;AAChE,SAAQC,qBAAqB,EAAEC,aAAa,QAAO,oCAAmC;AACtF,SAAQC,aAAa,QAAO,0BAAyB;AACr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AAU+B,IAAI;YACpBF,MAAMnD,QAAQ,YAAY;QAC5B;IACF,EAAE,OAAO6B,KAAK;QACZ,MAAMV;QACN,MAAMU;IACR;IAEA,IAAIP,UAAUG,kBAAkB,EAAE;QAChC,MAAM6B,SAAS,CAAC,OAAO,EAAErE,cAAcqC,UAAUxB,QAAQ,EAAE,CAAC,EAAEwB,UAAUI,aAAa,GAAGI,oBAAoB,IAAI;QAChH5B,OAAOqD,GAAG,CAAC,CAAC,oCAAoC,EAAEhF,UAAU;YAAC;YAAQ;SAAY,EAAE+E,SAAS;IAC9F,OAAO;QACL,MAAME,YAAY,CAAC,OAAO,EAAEvE,cAAc0C,OAAOY,IAAI,EAAE,CAAC,EAAEZ,OAAOa,IAAI,EAAE;QACvEtC,OAAOqD,GAAG,CAAC,CAAC,iBAAiB,EAAEhF,UAAU;YAAC;YAAQ;SAAY,EAAEiF,YAAY;IAC9E;IAEAnC;IAEA,OAAO;QAACF;IAAK;AACf;AAEA,wEAAwE,GACxE,eAAee,iBAAiBjC,MAAc;IAC5C,IAAI;QACF,OAAO,AAAC,CAAA,MAAM5B,SAASC,KAAKmF,IAAI,CAACxD,QAAQvB,qBAAqB,OAAM,EAAGgF,IAAI,MAAMpD;IACnF,EAAE,OAAM;QACN,OAAOA;IACT;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/preview/startWorkbenchPreview.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {type CliConfig, findProjectRoot, type Output} from '@sanity/cli-core'\n\nimport {buildAppId, SANITY_APP_ID_FILE} from '../../appId.js'\nimport {isWorkbenchApp} from '../../defineApp.js'\nimport {deriveInterfaces} from '../../deriveInterfaces.js'\nimport {readAppIcon, toUrlPath} from '../../readAppIcon.js'\nimport {type ResolvedWorkbenchApp, resolveWorkbenchApp} from '../../resolveWorkbenchApp.js'\nimport {resolveWorkbenchConfig} from '../../resolveWorkbenchConfig.js'\nimport {createServerLifecycle, toDisplayHost} from '../../util/serverOrchestration.js'\nimport {deriveConfigs} from '../dev/deriveConfigs.js'\nimport {\n dashboardPath,\n type DevServerManifest,\n findServerConflict,\n localAppIdentity,\n registerDevServer,\n} from '../dev/registry.js'\nimport {startWorkbenchDevServer} from '../dev/startWorkbenchDevServer.js'\nimport {serveBuiltApplication} from './serveBuiltApplication.js'\n\nexport interface StartWorkbenchPreviewOptions {\n /** Directory for the workbench Vite server's dependency cache. */\n cacheDir: string\n /** CLI-domain `app.id`/`deployment.appId` deprecation check, run before registering. */\n checkForDeprecatedAppId: () => void\n cliConfig: CliConfig\n /** Extract the project manifest to inline into the registry (studio-vs-app handled by the CLI). */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n /** Where the preview serves the app's icon. */\n iconUrl?: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n httpHost: string\n httpPort: number\n isApp: boolean\n /** The built `dist` directory to serve as the federation remote. */\n outDir: string\n output: Output\n reactStrictMode: boolean\n workDir: string\n}\n\n/**\n * `sanity start` for a workbench app: serve a production build the way dev serves\n * a live one. The same singleton workbench shell renders it and the same registry\n * advertises it — only the remote differs, static files from the build output\n * instead of a live Vite dev server. There's no config watcher or rebuild: a\n * build is fixed, so nothing re-syncs.\n *\n * A running workbench claims the configured port, so the built remote binds the\n * next one. Without one the remote takes the configured port and announces its\n * own URL.\n */\nexport async function startWorkbenchPreview(\n options: StartWorkbenchPreviewOptions,\n): Promise<{close: () => Promise<void>}> {\n const {\n cacheDir,\n checkForDeprecatedAppId,\n cliConfig,\n extractManifest,\n httpHost,\n httpPort,\n isApp,\n outDir,\n output,\n reactStrictMode,\n workDir,\n } = options\n\n // Resolved before any server starts, so a bad icon path, a project that isn't set\n // up for the Dashboard, or one it already serves fails with nothing to tear down.\n const {id, workbenchApp} = await resolvePreviewTarget(cliConfig, outDir)\n const applicationId = workbenchApp ? cliConfig.deployment?.appId : undefined\n const organizationId = cliConfig.app?.organizationId\n const conflict = findServerConflict({\n applicationId,\n id,\n organizationId,\n slug: workbenchApp?.slug,\n })\n\n if (conflict) {\n throw new Error(`${conflict}. Stop that server first.`)\n }\n\n const app = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined\n const appIcon = isApp ? app?.icon : undefined\n const iconUrlPath = (iconPath: string) =>\n `/${toUrlPath(workDir, path.resolve(workDir, iconPath))}`\n const icons = await Promise.all(\n [appIcon, ...(app?.views ?? []).map((view) => ('icon' in view ? view.icon : undefined))]\n .filter((iconPath) => iconPath !== undefined)\n .map(async (iconPath) => ({\n ...(await readAppIcon(workDir, iconPath)),\n path: iconUrlPath(iconPath),\n })),\n )\n\n const {close, closers, installSignalHandlers} = createServerLifecycle()\n\n const workbench = await startWorkbenchDevServer({\n cacheDir,\n cliConfig,\n httpHost,\n httpPort,\n output,\n reactStrictMode,\n workDir,\n })\n closers.push(workbench.close)\n\n const remotePort = workbench.workbenchAvailable ? workbench.workbenchPort + 1 : httpPort\n\n const remote = await serveBuiltApplication({\n cacheDir,\n httpHost,\n httpPort: remotePort,\n icons,\n outDir,\n workDir,\n }).catch(async (err) => {\n await close()\n throw err\n })\n closers.push(remote.close)\n\n let dashboardAppPath: string | undefined\n try {\n // Callers provide CLI-only validation and manifest extraction to keep them\n // out of workbench-cli.\n checkForDeprecatedAppId()\n const configPath = (await findProjectRoot(workDir)).path\n const configs = await deriveConfigs(cliConfig)\n const interfaces = deriveInterfaces(cliConfig.app, {\n iconUrl: (iconPath) => `http://${remote.host}:${remote.port}${iconUrlPath(iconPath)}`,\n isApp,\n })\n const registration = registerDevServer({\n applicationId,\n configs,\n host: remote.host,\n id,\n interfaces,\n manifest: await extractManifest({\n applicationId: id,\n configPath,\n iconUrl: appIcon && `http://${remote.host}:${remote.port}${iconUrlPath(appIcon)}`,\n workDir,\n }),\n manifestUpdatedAt: new Date().toISOString(),\n organizationId,\n port: remote.port,\n projectId: cliConfig?.api?.projectId,\n ...(workbenchApp && localAppIdentity(workbenchApp)),\n type: isApp ? 'coreApp' : 'studio',\n workDir,\n })\n closers.push(async () => registration.release())\n dashboardAppPath = dashboardPath({\n id,\n interfaces,\n slug: workbenchApp?.slug,\n type: isApp ? 'coreApp' : 'studio',\n })\n } catch (err) {\n await close()\n throw err\n }\n\n if (workbench.workbenchAvailable) {\n const appUrl = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}${dashboardAppPath ?? ''}`\n output.log(`Dashboard preview server started at ${styleText(['blue', 'underline'], appUrl)}`)\n } else {\n const remoteUrl = `http://${toDisplayHost(remote.host)}:${remote.port}`\n output.log(`Serving build at ${styleText(['blue', 'underline'], remoteUrl)}`)\n }\n\n installSignalHandlers()\n\n return {close}\n}\n\n/**\n * What the preview registers: a config under its own id namespace (as in dev),\n * or the workbench app under the id its build inlined.\n */\nasync function resolvePreviewTarget(\n cliConfig: CliConfig,\n outDir: string,\n): Promise<{id: string; workbenchApp?: ResolvedWorkbenchApp}> {\n const config = resolveWorkbenchConfig(cliConfig)\n\n if (config) {\n return {id: `config:${config.appType}`}\n }\n\n const workbenchApp = resolveWorkbenchApp(cliConfig)\n\n if (!workbenchApp) {\n throw new Error(\n '`sanity start` was invoked in an application that is not set up for the Dashboard',\n )\n }\n\n return {id: (await readInlinedAppId(outDir)) ?? (await buildAppId(workbenchApp)), workbenchApp}\n}\n\n/** The id the build inlined into its bundle, or undefined when absent. */\nasync function readInlinedAppId(outDir: string): Promise<string | undefined> {\n try {\n return (await readFile(path.join(outDir, SANITY_APP_ID_FILE), 'utf8')).trim() || undefined\n } catch {\n return undefined\n }\n}\n"],"names":["readFile","path","styleText","findProjectRoot","buildAppId","SANITY_APP_ID_FILE","isWorkbenchApp","deriveInterfaces","readAppIcon","toUrlPath","resolveWorkbenchApp","resolveWorkbenchConfig","createServerLifecycle","toDisplayHost","deriveConfigs","dashboardPath","findServerConflict","localAppIdentity","registerDevServer","startWorkbenchDevServer","serveBuiltApplication","startWorkbenchPreview","options","cacheDir","checkForDeprecatedAppId","cliConfig","extractManifest","httpHost","httpPort","isApp","outDir","output","reactStrictMode","workDir","id","workbenchApp","resolvePreviewTarget","applicationId","deployment","appId","undefined","organizationId","app","conflict","slug","Error","appIcon","icon","iconUrlPath","iconPath","resolve","icons","Promise","all","views","map","view","filter","close","closers","installSignalHandlers","workbench","push","remotePort","workbenchAvailable","workbenchPort","remote","catch","err","dashboardAppPath","configPath","configs","interfaces","iconUrl","host","port","registration","manifest","manifestUpdatedAt","Date","toISOString","projectId","api","type","release","appUrl","log","remoteUrl","config","appType","readInlinedAppId","join","trim"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAwBC,eAAe,QAAoB,mBAAkB;AAE7E,SAAQC,UAAU,EAAEC,kBAAkB,QAAO,iBAAgB;AAC7D,SAAQC,cAAc,QAAO,qBAAoB;AACjD,SAAQC,gBAAgB,QAAO,4BAA2B;AAC1D,SAAQC,WAAW,EAAEC,SAAS,QAAO,uBAAsB;AAC3D,SAAmCC,mBAAmB,QAAO,+BAA8B;AAC3F,SAAQC,sBAAsB,QAAO,kCAAiC;AACtE,SAAQC,qBAAqB,EAAEC,aAAa,QAAO,oCAAmC;AACtF,SAAQC,aAAa,QAAO,0BAAyB;AACrD,SACEC,aAAa,EAEbC,kBAAkB,EAClBC,gBAAgB,EAChBC,iBAAiB,QACZ,qBAAoB;AAC3B,SAAQC,uBAAuB,QAAO,oCAAmC;AACzE,SAAQC,qBAAqB,QAAO,6BAA4B;AA0BhE;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,sBACpBC,OAAqC;IAErC,MAAM,EACJC,QAAQ,EACRC,uBAAuB,EACvBC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,eAAe,EACfC,OAAO,EACR,GAAGX;IAEJ,kFAAkF;IAClF,kFAAkF;IAClF,MAAM,EAACY,EAAE,EAAEC,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I;QAChHtC,OAAOuD,GAAG,CAAC,CAAC,oCAAoC,EAAEpF,UAAU;YAAC;YAAQ;SAAY,EAAEmF,SAAS;IAC9F,OAAO;QACL,MAAME,YAAY,CAAC,OAAO,EAAE1E,cAAcqD,OAAOQ,IAAI,EAAE,CAAC,EAAER,OAAOS,IAAI,EAAE;QACvE5C,OAAOuD,GAAG,CAAC,CAAC,iBAAiB,EAAEpF,UAAU;YAAC;YAAQ;SAAY,EAAEqF,YAAY;IAC9E;IAEA3B;IAEA,OAAO;QAACF;IAAK;AACf;AAEA;;;CAGC,GACD,eAAetB,qBACbX,SAAoB,EACpBK,MAAc;IAEd,MAAM0D,SAAS7E,uBAAuBc;IAEtC,IAAI+D,QAAQ;QACV,OAAO;YAACtD,IAAI,CAAC,OAAO,EAAEsD,OAAOC,OAAO,EAAE;QAAA;IACxC;IAEA,MAAMtD,eAAezB,oBAAoBe;IAEzC,IAAI,CAACU,cAAc;QACjB,MAAM,IAAIU,MACR;IAEJ;IAEA,OAAO;QAACX,IAAI,AAAC,MAAMwD,iBAAiB5D,WAAa,MAAM1B,WAAW+B;QAAgBA;IAAY;AAChG;AAEA,wEAAwE,GACxE,eAAeuD,iBAAiB5D,MAAc;IAC5C,IAAI;QACF,OAAO,AAAC,CAAA,MAAM9B,SAASC,KAAK0F,IAAI,CAAC7D,QAAQzB,qBAAqB,OAAM,EAAGuF,IAAI,MAAMpD;IACnF,EAAE,OAAM;QACN,OAAOA;IACT;AACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { deleteApplication, getApplication, getApplicationUrl, getWorkbenchUrl } from '../../services/applications.js';
|
|
2
|
+
import { deleteDashboard, getOrganizationDashboard } from '../../services/dashboard-configs.js';
|
|
2
3
|
import { deleteConfig, listConfigs } from '../../services/installations.js';
|
|
3
4
|
import { resolveInstallationId, summarizeConfig } from '../deploy/deployConfig.js';
|
|
4
5
|
import { summarizeInterfaces } from '../deploy/summarizeInterfaces.js';
|
|
@@ -6,13 +7,14 @@ import { summarizeInterfaces } from '../deploy/summarizeInterfaces.js';
|
|
|
6
7
|
* The undeploy adapter for workbench apps and configs, mirroring what a
|
|
7
8
|
* workbench deploy creates: an app that exposes interfaces deletes its Brett
|
|
8
9
|
* application (the server soft-deletes its deployments and refuses singletons
|
|
9
|
-
* with active installations); a config
|
|
10
|
-
* installation
|
|
10
|
+
* with active installations); a config deletes its deployed config instead
|
|
11
|
+
* (installation snapshots, or the dashboard configuration). The two are severed at the source,
|
|
11
12
|
* so exactly one of `workbench`/`config` is supplied and the brand decides the path.
|
|
12
13
|
*/ export function createWorkbenchUndeployAdapter(options) {
|
|
13
14
|
const { appId, config, organizationId, type, workbench } = options;
|
|
14
15
|
// Workbench-internal, so kept off the reported target; resolveTarget stashes it for the delete.
|
|
15
16
|
let installationId;
|
|
17
|
+
let dashboardId;
|
|
16
18
|
return {
|
|
17
19
|
resolveTarget: async ()=>{
|
|
18
20
|
if (!config) {
|
|
@@ -23,6 +25,11 @@ import { summarizeInterfaces } from '../deploy/summarizeInterfaces.js';
|
|
|
23
25
|
workbench
|
|
24
26
|
});
|
|
25
27
|
}
|
|
28
|
+
if (config.appType === 'dashboard') {
|
|
29
|
+
const resolved = await resolveDashboardConfigTarget(config);
|
|
30
|
+
dashboardId = resolved.dashboardId;
|
|
31
|
+
return resolved.resolution;
|
|
32
|
+
}
|
|
26
33
|
const resolved = await resolveConfigTarget({
|
|
27
34
|
config,
|
|
28
35
|
organizationId
|
|
@@ -32,6 +39,10 @@ import { summarizeInterfaces } from '../deploy/summarizeInterfaces.js';
|
|
|
32
39
|
},
|
|
33
40
|
type,
|
|
34
41
|
async undeploy (target) {
|
|
42
|
+
if (dashboardId) {
|
|
43
|
+
await deleteDashboard(dashboardId);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
35
46
|
if (target.deletes === 'config') {
|
|
36
47
|
if (!installationId) throw new Error('No installation resolved for the config undeploy');
|
|
37
48
|
for (const snapshot of target.configs){
|
|
@@ -117,6 +128,42 @@ async function resolveConfigTarget({ config, organizationId }) {
|
|
|
117
128
|
configs,
|
|
118
129
|
deletes: 'config',
|
|
119
130
|
id: null,
|
|
131
|
+
organizationId,
|
|
132
|
+
payload: {
|
|
133
|
+
appId: null,
|
|
134
|
+
config: summarizeConfig(config),
|
|
135
|
+
type: 'coreApp'
|
|
136
|
+
},
|
|
137
|
+
summary: [
|
|
138
|
+
summarizeConfig(config)
|
|
139
|
+
],
|
|
140
|
+
title: 'Media Library configuration',
|
|
141
|
+
type: 'coreApp',
|
|
142
|
+
url: getWorkbenchUrl(organizationId)
|
|
143
|
+
},
|
|
144
|
+
type: 'found'
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
async function resolveDashboardConfigTarget(config) {
|
|
149
|
+
const { organizationId } = config;
|
|
150
|
+
const dashboard = await getOrganizationDashboard(organizationId);
|
|
151
|
+
if (!dashboard) {
|
|
152
|
+
return {
|
|
153
|
+
resolution: {
|
|
154
|
+
message: `No deployed dashboard configuration for organization "${organizationId}"`,
|
|
155
|
+
type: 'none'
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
dashboardId: dashboard.id,
|
|
161
|
+
resolution: {
|
|
162
|
+
target: {
|
|
163
|
+
configs: [],
|
|
164
|
+
deletes: 'config',
|
|
165
|
+
id: null,
|
|
166
|
+
organizationId,
|
|
120
167
|
payload: {
|
|
121
168
|
appId: null,
|
|
122
169
|
config: summarizeConfig(config),
|
|
@@ -125,7 +172,7 @@ async function resolveConfigTarget({ config, organizationId }) {
|
|
|
125
172
|
summary: [
|
|
126
173
|
summarizeConfig(config)
|
|
127
174
|
],
|
|
128
|
-
title:
|
|
175
|
+
title: 'Dashboard configuration',
|
|
129
176
|
type: 'coreApp',
|
|
130
177
|
url: getWorkbenchUrl(organizationId)
|
|
131
178
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/undeploy/workbenchUndeployAdapter.ts"],"sourcesContent":["import {\n type UndeployAdapter,\n type UndeployApplicationTarget,\n type UndeployConfigTarget,\n type UndeployTargetResolution,\n} from '@sanity/cli-core/undeploy'\n\nimport {type ResolvedMediaLibraryConfig} from '../../resolveWorkbenchConfig.js'\nimport {\n deleteApplication,\n getApplication,\n getApplicationUrl,\n getWorkbenchUrl,\n} from '../../services/applications.js'\nimport {type ConfigSnapshot, deleteConfig, listConfigs} from '../../services/installations.js'\nimport {resolveInstallationId, summarizeConfig} from '../deploy/deployConfig.js'\nimport {type DeployableWorkbenchApp} from '../deploy/getWorkbench.js'\nimport {\n type DeployedView,\n type DeployedWebWorker,\n summarizeInterfaces,\n} from '../deploy/summarizeInterfaces.js'\n\n/** The workbench extension of the shared target; serializes into `--json` as-is. */\nexport type WorkbenchUndeployTarget =\n | (UndeployApplicationTarget & {\n services: DeployedWebWorker[]\n views: DeployedView[]\n })\n | (UndeployConfigTarget & {\n configs: ConfigSnapshot[]\n })\n\n/**\n * The undeploy adapter for workbench apps and configs, mirroring what a\n * workbench deploy creates: an app that exposes interfaces deletes its Brett\n * application (the server soft-deletes its deployments and refuses singletons\n * with active installations); a config — the media library — deletes its\n * installation's config snapshots instead. The two are severed at the source,\n * so exactly one of `workbench`/`config` is supplied and the brand decides the path.\n */\nexport function createWorkbenchUndeployAdapter(options: {\n appId: string | undefined\n config?: ResolvedMediaLibraryConfig\n organizationId: string | undefined\n type: 'coreApp' | 'studio'\n workbench?: DeployableWorkbenchApp\n}): UndeployAdapter<WorkbenchUndeployTarget> {\n const {appId, config, organizationId, type, workbench} = options\n // Workbench-internal, so kept off the reported target; resolveTarget stashes it for the delete.\n let installationId: string | undefined\n\n return {\n resolveTarget: async () => {\n if (!config) {\n if (!workbench) throw new Error('No Dashboard app or config to undeploy')\n return resolveApplicationTarget({appId, type, workbench})\n }\n const resolved = await resolveConfigTarget({config, organizationId})\n installationId = resolved.installationId\n return resolved.resolution\n },\n type,\n async undeploy(target) {\n if (target.deletes === 'config') {\n if (!installationId) throw new Error('No installation resolved for the config undeploy')\n for (const snapshot of target.configs) {\n await deleteConfig(installationId, snapshot.id)\n }\n return\n }\n await deleteApplication(target.id)\n },\n }\n}\n\nasync function resolveApplicationTarget({\n appId,\n type,\n workbench,\n}: {\n appId: string | undefined\n type: 'coreApp' | 'studio'\n workbench: DeployableWorkbenchApp\n}): Promise<UndeployTargetResolution<WorkbenchUndeployTarget>> {\n if (!appId) {\n return {\n message: 'No `deployment.appId` configured',\n solution: 'Add `deployment.appId` to sanity.cli.ts',\n type: 'none',\n }\n }\n\n const application = await getApplication(appId)\n if (!application) {\n return {message: 'Application with the given ID does not exist', type: 'none'}\n }\n\n const {lines, services, views} = summarizeInterfaces(workbench)\n return {\n target: {\n application,\n deletes: 'application',\n id: application.id,\n payload: {appId: application.id, services, type, views},\n services,\n summary: lines,\n title: application.title,\n type,\n url: getApplicationUrl({...application, type}),\n views,\n },\n type: 'found',\n }\n}\n\nasync function resolveConfigTarget({\n config,\n organizationId,\n}: {\n config: ResolvedMediaLibraryConfig\n organizationId: string | undefined\n}): Promise<{\n installationId?: string\n resolution: UndeployTargetResolution<WorkbenchUndeployTarget>\n}> {\n const {appType} = config\n if (!organizationId) {\n throw new Error(\n 'sanity.cli.ts does not contain an organization identifier (\"app.organizationId\"), which is required to resolve the installation',\n )\n }\n\n const installationId = await resolveInstallationId({appType, organizationId})\n if (!installationId) {\n return {\n resolution: {\n message: `No active \"${appType}\" installation for organization \"${organizationId}\"`,\n type: 'none',\n },\n }\n }\n\n const configs = await listConfigs(installationId)\n if (configs.length === 0) {\n return {\n installationId,\n resolution: {\n message: `No deployed config for the \"${appType}\" installation`,\n type: 'none',\n },\n }\n }\n\n return {\n installationId,\n resolution: {\n target: {\n configs,\n deletes: 'config',\n id: null,\n payload: {\n appId: null,\n config: summarizeConfig(config),\n type: 'coreApp',\n },\n summary: [summarizeConfig(config)],\n title: appType,\n type: 'coreApp',\n url: getWorkbenchUrl(organizationId),\n },\n type: 'found',\n },\n }\n}\n"],"names":["deleteApplication","getApplication","getApplicationUrl","getWorkbenchUrl","deleteConfig","listConfigs","resolveInstallationId","summarizeConfig","summarizeInterfaces","createWorkbenchUndeployAdapter","options","appId","config","organizationId","type","workbench","installationId","resolveTarget","Error","resolveApplicationTarget","resolved","resolveConfigTarget","resolution","undeploy","target","deletes","snapshot","configs","id","message","solution","application","lines","services","views","payload","summary","title","url","appType","length"],"mappings":"AAQA,SACEA,iBAAiB,EACjBC,cAAc,EACdC,iBAAiB,EACjBC,eAAe,QACV,iCAAgC;AACvC,SAA6BC,YAAY,EAAEC,WAAW,QAAO,kCAAiC;AAC9F,SAAQC,qBAAqB,EAAEC,eAAe,QAAO,4BAA2B;AAEhF,SAGEC,mBAAmB,QACd,mCAAkC;AAYzC;;;;;;;CAOC,GACD,OAAO,SAASC,+BAA+BC,OAM9C;IACC,MAAM,EAACC,KAAK,EAAEC,MAAM,EAAEC,cAAc,EAAEC,IAAI,EAAEC,SAAS,EAAC,GAAGL;IACzD,gGAAgG;IAChG,IAAIM;IAEJ,OAAO;QACLC,eAAe;YACb,IAAI,CAACL,QAAQ;gBACX,IAAI,CAACG,WAAW,MAAM,IAAIG,MAAM;gBAChC,OAAOC,yBAAyB;oBAACR;oBAAOG;oBAAMC;gBAAS;YACzD;YACA,MAAMK,WAAW,MAAMC,oBAAoB;gBAACT;gBAAQC;YAAc;YAClEG,iBAAiBI,SAASJ,cAAc;YACxC,OAAOI,SAASE,UAAU;QAC5B;QACAR;QACA,MAAMS,UAASC,MAAM;YACnB,IAAIA,OAAOC,OAAO,KAAK,UAAU;gBAC/B,IAAI,CAACT,gBAAgB,MAAM,IAAIE,MAAM;gBACrC,KAAK,MAAMQ,YAAYF,OAAOG,OAAO,CAAE;oBACrC,MAAMvB,aAAaY,gBAAgBU,SAASE,EAAE;gBAChD;gBACA;YACF;YACA,MAAM5B,kBAAkBwB,OAAOI,EAAE;QACnC;IACF;AACF;AAEA,eAAeT,yBAAyB,EACtCR,KA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IAAI;gBACJO,SAAS;oBACPxB,OAAO;oBACPC,QAAQL,gBAAgBK;oBACxBE,MAAM;gBACR;gBACAsB,SAAS;oBAAC7B,gBAAgBK;iBAAQ;gBAClCyB,OAAOE;gBACPzB,MAAM;gBACNwB,KAAKnC,gBAAgBU;YACvB;YACAC,MAAM;QACR;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/undeploy/workbenchUndeployAdapter.ts"],"sourcesContent":["import {\n type UndeployAdapter,\n type UndeployApplicationTarget,\n type UndeployConfigTarget,\n type UndeployTargetResolution,\n} from '@sanity/cli-core/undeploy'\n\nimport {\n type DashboardConfig,\n type MediaLibraryConfig,\n type WorkbenchConfig,\n} from '../../defineApp.js'\nimport {\n deleteApplication,\n getApplication,\n getApplicationUrl,\n getWorkbenchUrl,\n} from '../../services/applications.js'\nimport {deleteDashboard, getOrganizationDashboard} from '../../services/dashboard-configs.js'\nimport {type ConfigSnapshot, deleteConfig, listConfigs} from '../../services/installations.js'\nimport {resolveInstallationId, summarizeConfig} from '../deploy/deployConfig.js'\nimport {type DeployableWorkbenchApp} from '../deploy/getWorkbench.js'\nimport {\n type DeployedView,\n type DeployedWebWorker,\n summarizeInterfaces,\n} from '../deploy/summarizeInterfaces.js'\n\n/** The workbench extension of the shared target; serializes into `--json` as-is. */\nexport type WorkbenchUndeployTarget =\n | (UndeployApplicationTarget & {\n services: DeployedWebWorker[]\n views: DeployedView[]\n })\n | (UndeployConfigTarget & {\n configs: ConfigSnapshot[]\n })\n\n/**\n * The undeploy adapter for workbench apps and configs, mirroring what a\n * workbench deploy creates: an app that exposes interfaces deletes its Brett\n * application (the server soft-deletes its deployments and refuses singletons\n * with active installations); a config deletes its deployed config instead\n * (installation snapshots, or the dashboard configuration). The two are severed at the source,\n * so exactly one of `workbench`/`config` is supplied and the brand decides the path.\n */\nexport function createWorkbenchUndeployAdapter(options: {\n appId: string | undefined\n config?: WorkbenchConfig\n organizationId: string | undefined\n type: 'coreApp' | 'studio'\n workbench?: DeployableWorkbenchApp\n}): UndeployAdapter<WorkbenchUndeployTarget> {\n const {appId, config, organizationId, type, workbench} = options\n // Workbench-internal, so kept off the reported target; resolveTarget stashes it for the delete.\n let installationId: string | undefined\n let dashboardId: string | undefined\n\n return {\n resolveTarget: async () => {\n if (!config) {\n if (!workbench) throw new Error('No Dashboard app or config to undeploy')\n return resolveApplicationTarget({appId, type, workbench})\n }\n\n if (config.appType === 'dashboard') {\n const resolved = await resolveDashboardConfigTarget(config)\n dashboardId = resolved.dashboardId\n return resolved.resolution\n }\n\n const resolved = await resolveConfigTarget({config, organizationId})\n installationId = resolved.installationId\n return resolved.resolution\n },\n type,\n async undeploy(target) {\n if (dashboardId) {\n await deleteDashboard(dashboardId)\n return\n }\n\n if (target.deletes === 'config') {\n if (!installationId) throw new Error('No installation resolved for the config undeploy')\n for (const snapshot of target.configs) {\n await deleteConfig(installationId, snapshot.id)\n }\n return\n }\n await deleteApplication(target.id)\n },\n }\n}\n\nasync function resolveApplicationTarget({\n appId,\n type,\n workbench,\n}: {\n appId: string | undefined\n type: 'coreApp' | 'studio'\n workbench: DeployableWorkbenchApp\n}): Promise<UndeployTargetResolution<WorkbenchUndeployTarget>> {\n if (!appId) {\n return {\n message: 'No `deployment.appId` configured',\n solution: 'Add `deployment.appId` to sanity.cli.ts',\n type: 'none',\n }\n }\n\n const application = await getApplication(appId)\n if (!application) {\n return {message: 'Application with the given ID does not exist', type: 'none'}\n }\n\n const {lines, services, views} = summarizeInterfaces(workbench)\n return {\n target: {\n application,\n deletes: 'application',\n id: application.id,\n payload: {appId: application.id, services, type, views},\n services,\n summary: lines,\n title: application.title,\n type,\n url: getApplicationUrl({...application, type}),\n views,\n },\n type: 'found',\n }\n}\n\nasync function resolveConfigTarget({\n config,\n organizationId,\n}: {\n config: MediaLibraryConfig\n organizationId: string | undefined\n}): Promise<{\n installationId?: string\n resolution: UndeployTargetResolution<WorkbenchUndeployTarget>\n}> {\n const {appType} = config\n if (!organizationId) {\n throw new Error(\n 'sanity.cli.ts does not contain an organization identifier (\"app.organizationId\"), which is required to resolve the installation',\n )\n }\n\n const installationId = await resolveInstallationId({appType, organizationId})\n if (!installationId) {\n return {\n resolution: {\n message: `No active \"${appType}\" installation for organization \"${organizationId}\"`,\n type: 'none',\n },\n }\n }\n\n const configs = await listConfigs(installationId)\n if (configs.length === 0) {\n return {\n installationId,\n resolution: {\n message: `No deployed config for the \"${appType}\" installation`,\n type: 'none',\n },\n }\n }\n\n return {\n installationId,\n resolution: {\n target: {\n configs,\n deletes: 'config',\n id: null,\n organizationId,\n payload: {\n appId: null,\n config: summarizeConfig(config),\n type: 'coreApp',\n },\n summary: [summarizeConfig(config)],\n title: 'Media Library configuration',\n type: 'coreApp',\n url: getWorkbenchUrl(organizationId),\n },\n type: 'found',\n },\n }\n}\n\nasync function resolveDashboardConfigTarget(config: DashboardConfig): Promise<{\n dashboardId?: string\n resolution: UndeployTargetResolution<WorkbenchUndeployTarget>\n}> {\n const {organizationId} = config\n const dashboard = await getOrganizationDashboard(organizationId)\n if (!dashboard) {\n return {\n resolution: {\n message: `No deployed dashboard configuration for organization \"${organizationId}\"`,\n type: 'none',\n },\n }\n }\n\n return {\n dashboardId: dashboard.id,\n resolution: {\n target: {\n configs: [],\n deletes: 'config',\n id: null,\n organizationId,\n payload: {appId: null, config: summarizeConfig(config), type: 'coreApp'},\n summary: [summarizeConfig(config)],\n title: 'Dashboard configuration',\n type: 'coreApp',\n url: getWorkbenchUrl(organizationId),\n },\n type: 'found',\n },\n }\n}\n"],"names":["deleteApplication","getApplication","getApplicationUrl","getWorkbenchUrl","deleteDashboard","getOrganizationDashboard","deleteConfig","listConfigs","resolveInstallationId","summarizeConfig","summarizeInterfaces","createWorkbenchUndeployAdapter","options","appId","config","organizationId","type","workbench","installationId","dashboardId","resolveTarget","Error","resolveApplicationTarget","appType","resolved","resolveDashboardConfigTarget","resolution","resolveConfigTarget","undeploy","target","deletes","snapshot","configs","id","message","solution","application","lines","services","views","payload","summ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S;gBACTG,IAAI;gBACJlB;gBACAyB,SAAS;oBACP3B,OAAO;oBACPC,QAAQL,gBAAgBK;oBACxBE,MAAM;gBACR;gBACAyB,SAAS;oBAAChC,gBAAgBK;iBAAQ;gBAClC4B,OAAO;gBACP1B,MAAM;gBACN2B,KAAKxC,gBAAgBY;YACvB;YACAC,MAAM;QACR;IACF;AACF;AAEA,eAAeS,6BAA6BX,MAAuB;IAIjE,MAAM,EAACC,cAAc,EAAC,GAAGD;IACzB,MAAM+B,YAAY,MAAMxC,yBAAyBU;IACjD,IAAI,CAAC8B,WAAW;QACd,OAAO;YACLnB,YAAY;gBACVQ,SAAS,CAAC,sDAAsD,EAAEnB,eAAe,CAAC,CAAC;gBACnFC,MAAM;YACR;QACF;IACF;IAEA,OAAO;QACLG,aAAa0B,UAAUZ,EAAE;QACzBP,YAAY;YACVG,QAAQ;gBACNG,SAAS,EAAE;gBACXF,SAAS;gBACTG,IAAI;gBACJlB;gBACAyB,SAAS;oBAAC3B,OAAO;oBAAMC,QAAQL,gBAAgBK;oBAASE,MAAM;gBAAS;gBACvEyB,SAAS;oBAAChC,gBAAgBK;iBAAQ;gBAClC4B,OAAO;gBACP1B,MAAM;gBACN2B,KAAKxC,gBAAgBY;YACvB;YACAC,MAAM;QACR;IACF;AACF"}
|
package/dist/contract.js
CHANGED
|
@@ -6,6 +6,8 @@ import { z } from 'zod/mini';
|
|
|
6
6
|
/** @internal */ export const WEB_WORKER_CONTRACT_VERSION = 1;
|
|
7
7
|
/** @internal */ export const WINDOW_CONTRACT_VERSION = 1;
|
|
8
8
|
/** @internal */ export const MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION = 1;
|
|
9
|
+
export const DASHBOARD_CONFIG_CONTRACT_VERSION = 1;
|
|
10
|
+
export const DASHBOARD_CONFIG_TYPE = 'dashboard_config';
|
|
9
11
|
/** Component slots per view surface; windows load outside the component artifact path. @internal */ export const VIEW_COMPONENTS = {
|
|
10
12
|
asset_source: [
|
|
11
13
|
'asset_source'
|
|
@@ -189,12 +191,24 @@ const MediaLibraryConfigSchema = z.object({
|
|
|
189
191
|
appType: z.literal('media-library'),
|
|
190
192
|
fields: z.array(MediaLibraryFieldSchema).check(z.refine((fields)=>new Set(fields.map((field)=>field.name)).size === fields.length, 'Field `name` must be unique within a media library'))
|
|
191
193
|
});
|
|
194
|
+
const DashboardConfigSchema = z.object({
|
|
195
|
+
appType: z.literal('dashboard'),
|
|
196
|
+
src: z.string('Dashboard configuration `src` must be a path to the configuration file')
|
|
197
|
+
});
|
|
192
198
|
/**
|
|
193
199
|
* A workbench config's built value, keyed by `appType`; deploys as a versioned
|
|
194
200
|
* snapshot, not an interface.
|
|
195
201
|
* @internal
|
|
196
202
|
*/ export const ConfigSchema = z.discriminatedUnion('appType', [
|
|
203
|
+
DashboardConfigSchema,
|
|
197
204
|
MediaLibraryConfigSchema
|
|
198
205
|
]);
|
|
206
|
+
const CONFIG_CONTRACT_VERSIONS = {
|
|
207
|
+
dashboard: DASHBOARD_CONFIG_CONTRACT_VERSION,
|
|
208
|
+
'media-library': MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION
|
|
209
|
+
};
|
|
210
|
+
/** @internal */ export function configContractVersion(appType) {
|
|
211
|
+
return String(CONFIG_CONTRACT_VERSIONS[appType]);
|
|
212
|
+
}
|
|
199
213
|
|
|
200
214
|
//# sourceMappingURL=contract.js.map
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contract.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\n// Shared module-federation extension contract: interface (view/web worker) and\n// config declaration schemas, plus the versions the build stamps.\n// `zod/mini` keeps the bundle small.\n\n/** @internal */\nexport const VIEW_CONTRACT_VERSION = 2\n\n/** @internal */\nexport const WEB_WORKER_CONTRACT_VERSION = 1\n\n/** @internal */\nexport const WINDOW_CONTRACT_VERSION = 1\n\n/** @internal */\nexport const MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION = 1\n\n/**\n * A view component. The return is opaque so the runtime helpers carry no React\n * dependency — the generated artifact renders it with the app's own React.\n * @public\n */\nexport type ViewComponent<TProps> = (props: TProps) => unknown\n\n/** @public */\nexport interface ViewComponentBaseProps<TView> {\n view: TView\n}\n\n/** Component slots per view surface; windows load outside the component artifact path. @internal */\nexport const VIEW_COMPONENTS = {\n asset_source: ['asset_source'],\n panel: ['title', 'panel'],\n tile: ['tile'],\n window: [],\n} as const satisfies Record<string, readonly string[]>\n\n/** @public */\nexport type ViewSurface = keyof typeof VIEW_COMPONENTS\n\n/**\n * A tile's footprint family — the shape it occupies on the dashboard. Modelled\n * on iOS WidgetKit families, not a linear scale: `banner` is full-width and\n * shallow, which a `small`→`large` magnitude can't express. The host maps a\n * family to a layout slot; the component reads it to render per footprint.\n * @public\n */\nexport const TileSizeSchema = z.enum(['small', 'large', 'banner'])\n\n/** @public */\nexport type TileSize = z.infer<typeof TileSizeSchema>\n\n/** @public */\nexport type WebWorkerType = 'worker'\n\n/**\n * @deprecated Use `WebWorkerType`.\n * @public\n */\nexport type ServiceType = WebWorkerType\n\nconst DockGroupSchema = z.enum(['system', 'applications'])\n\n/** @public */\nexport type DockGroup = z.output<typeof DockGroupSchema>\n\n/** @internal */\nexport const DockSchema = z.object({\n group: z.optional(DockGroupSchema),\n order: z.optional(z.number()),\n})\n\n/** @internal */\nexport type Dock = z.infer<typeof DockSchema>\n\nconst PanelDockSchema = z.object({order: z.optional(z.number())})\n\n/** @internal */\nexport const ViewPlacementMetadataSchema = z.object({\n dock: z.optional(DockSchema),\n icon: z.optional(z.string()),\n})\n\n/** @internal */\nexport type ViewPlacementMetadata = z.infer<typeof ViewPlacementMetadataSchema>\n\n/**\n * A tile's interface metadata: its footprint `size` and an optional `order`\n * the dashboard sorts on, ascending. Both are authored as top-level view fields\n * (see {@link InterfaceDeclarationSchema}) but stored on the record as metadata.\n * @internal\n */\nexport const TileInterfaceMetadataSchema = z.object({\n order: z.optional(z.number()),\n size: TileSizeSchema,\n})\n\n/** @internal */\nexport type TileInterfaceMetadata = z.infer<typeof TileInterfaceMetadataSchema>\n\n/**\n * The contract version each interface type advertises, so the host can check it\n * renders/runs what it expects.\n * @internal\n */\nconst INTERFACE_CONTRACT_VERSIONS = {\n asset_source: VIEW_CONTRACT_VERSION,\n panel: VIEW_CONTRACT_VERSION,\n tile: VIEW_CONTRACT_VERSION,\n window: WINDOW_CONTRACT_VERSION,\n worker: WEB_WORKER_CONTRACT_VERSION,\n} as const satisfies Record<string, number>\n\n/** Every interface type an app exposes — a window, a view, or a web worker. */\nexport type InterfaceKind = keyof typeof INTERFACE_CONTRACT_VERSIONS\n\n/** @internal */\nexport function interfaceContractVersion(kind: InterfaceKind): string {\n return String(INTERFACE_CONTRACT_VERSIONS[kind])\n}\n\n/**\n * The module-federation id a build exposes an interface at. Dev stamps the same\n * id a deploy would, so the workbench loads a local interface like a deployed one.\n * @internal\n */\nexport function interfaceModuleId(kind: string, name: string): string {\n switch (kind) {\n case 'asset_source':\n case 'panel':\n case 'tile': {\n return `views/${name}`\n }\n case 'window': {\n return 'App'\n }\n case 'worker': {\n return `services/${name}`\n }\n default: {\n throw new Error(`Cannot derive a moduleId for unknown interface kind: ${kind}`)\n }\n }\n}\n\n// Shared `name` + `src`; `kind` only tailors the validation message.\nfunction extensionDeclarationFields(kind: 'Field' | 'View' | 'Web worker') {\n const pattern = /^[a-zA-Z0-9_-]+$/\n return {\n name: z.string().check(z.regex(pattern, `${kind} \\`name\\` must match ${pattern}`)),\n src: z.string(),\n }\n}\n\n// Every interface shares `name` + `src` + a display `title`,\n// which Brett requires on the record each becomes.\nfunction interfaceDeclarationFields(kind: 'View' | 'Web worker') {\n return {\n ...extensionDeclarationFields(kind),\n title: z.string(`${kind} \\`title\\` is required`),\n }\n}\n\nconst PanelViewSchema = z.object({\n surface: z.literal('panel'),\n ...interfaceDeclarationFields('View'),\n dock: z.optional(PanelDockSchema),\n icon: z.optional(z.string()),\n})\n\n/** @public */\nexport type PanelViewDeclaration = z.output<typeof PanelViewSchema>\n\n/** @public */\nexport type DefinePanelViewInput = Omit<PanelViewDeclaration, 'surface'>\n\n/** @public */\nexport function definePanelView(view: DefinePanelViewInput): PanelViewDeclaration {\n return {...view, surface: 'panel'}\n}\n\nconst WindowViewSchema = z.object({\n surface: z.literal('window'),\n ...interfaceDeclarationFields('View'),\n dock: z.optional(DockSchema),\n icon: z.optional(z.string()),\n})\n\n/** @public */\nexport type WindowViewDeclaration = z.output<typeof WindowViewSchema>\n\n/** @public */\nexport type DefineWindowViewInput = Omit<WindowViewDeclaration, 'surface'>\n\n/** @public */\nexport function defineWindowView(view: DefineWindowViewInput): WindowViewDeclaration {\n return {...view, surface: 'window'}\n}\n\nconst AssetSourceViewSchema = z.object({\n surface: z.literal('asset_source'),\n ...interfaceDeclarationFields('View'),\n})\n\n/** @public */\nexport type AssetSourceViewDeclaration = z.output<typeof AssetSourceViewSchema>\n\n/** @public */\nexport type DefineAssetSourceViewInput = Omit<AssetSourceViewDeclaration, 'surface'>\n\n/** @public */\nexport function defineAssetSourceView(\n view: DefineAssetSourceViewInput,\n): AssetSourceViewDeclaration {\n return {...view, surface: 'asset_source'}\n}\n\nconst TileViewSchema = z.object({\n surface: z.literal('tile'),\n ...interfaceDeclarationFields('View'),\n /** Sort position within its layout track, ascending. Optional. */\n order: z.optional(z.number()),\n /** Footprint family the dashboard lays the tile out by. */\n size: TileSizeSchema,\n})\n\n/** @public */\nexport type TileViewDeclaration = z.output<typeof TileViewSchema>\n\n/** @public */\nexport type DefineTileViewInput = Omit<TileViewDeclaration, 'surface'>\n\n/** @public */\nexport function defineTileView(view: DefineTileViewInput): TileViewDeclaration {\n return {...view, surface: 'tile'}\n}\n\n/** @internal */\nexport const InterfaceDeclarationSchema = z.discriminatedUnion('surface', [\n WindowViewSchema,\n PanelViewSchema,\n AssetSourceViewSchema,\n TileViewSchema,\n])\n\n/** @public */\nexport type ViewDeclaration = z.output<typeof InterfaceDeclarationSchema>\n\nconst WebWorkerSchema = z.object({\n type: z.literal('worker'),\n ...interfaceDeclarationFields('Web worker'),\n})\n\n/** @public */\nexport type WebWorkerDeclaration = z.output<typeof WebWorkerSchema>\n\n/** @public */\nexport type DefineWebWorkerInput = Omit<WebWorkerDeclaration, 'type'>\n\n/** @public */\nexport function defineWebWorker(webWorker: DefineWebWorkerInput): WebWorkerDeclaration {\n return {...webWorker, type: 'worker'}\n}\n\n/** @internal */\nexport const WebWorkerDeclarationSchema = z.discriminatedUnion('type', [WebWorkerSchema])\n\nconst MediaLibraryFieldSchema = z.object({\n ...extensionDeclarationFields('Field'),\n public: z.optional(z.boolean()),\n title: z.string(),\n})\n\n/**\n * Stamped where the config crosses a boundary so the authoring model doesn't carry a constant discriminator.\n * @internal\n */\nexport const INSTALLATION_CONFIG_TYPE = 'installation_config'\n\n// `appType` is stamped by `unstable_defineMediaLibrary`, never authored.\nconst MediaLibraryConfigSchema = z.object({\n appType: z.literal('media-library'),\n fields: z\n .array(MediaLibraryFieldSchema)\n .check(\n z.refine(\n (fields) => new Set(fields.map((field) => field.name)).size === fields.length,\n 'Field `name` must be unique within a media library',\n ),\n ),\n})\n\n/**\n * A workbench config's built value, keyed by `appType`; deploys as a versioned\n * snapshot, not an interface.\n * @internal\n */\nexport const ConfigSchema = z.discriminatedUnion('appType', [MediaLibraryConfigSchema])\n\n/**\n * The `{appType, fields}` config value the build expands into a federation\n * remote and the deploy summarizes.\n * @internal\n */\nexport type WorkbenchConfigValue = z.output<typeof ConfigSchema>\n"],"names":["z","VIEW_CONTRACT_VERSION","WEB_WORKER_CONTRACT_VERSION","WINDOW_CONTRACT_VERSION","MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION","VIEW_COMPONENTS","asset_source","panel","tile","window","TileSizeSchema","enum","DockGroupSchema","DockSchema","object","group","optional","order","number","PanelDockSchema","ViewPlacementMetadataSchema","dock","icon","string","TileInterfaceMetadataSchema","size","INTERFACE_CONTRACT_VERSIONS","worker","interfaceContractVersion","kind","String","interfaceModuleId","name","Error","extensionDeclarationFields","pattern","check","regex","src","interfaceDeclarationFields","title","PanelViewSchema","surface","literal","definePanelView","view","WindowViewSchema","defineWindowView","AssetSourceViewSchema","defineAssetSourceView","TileViewSchema","defineTileView","InterfaceDeclarationSchema","discriminatedUnion","WebWorkerSchema","type","defineWebWorker","webWorker","WebWorkerDeclarationSchema","MediaLibraryFieldSchema","public","boolean","INSTALLATION_CONFIG_TYPE","MediaLibraryConfigSchema","appType","fields","array","refine","Set","map","field","length","ConfigSchema"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B,+EAA+E;AAC/E,kEAAkE;AAClE,qCAAqC;AAErC,cAAc,GACd,OAAO,MAAMC,wBAAwB,EAAC;AAEtC,cAAc,GACd,OAAO,MAAMC,8BAA8B,EAAC;AAE5C,cAAc,GACd,OAAO,MAAMC,0BAA0B,EAAC;AAExC,cAAc,GACd,OAAO,MAAMC,wCAAwC,EAAC;AActD,kGAAkG,GAClG,OAAO,MAAMC,kBAAkB;IAC7BC,cAAc;QAAC;KAAe;IAC9BC,OAAO;QAAC;QAAS;KAAQ;IACzBC,MAAM;QAAC;KAAO;IACdC,QAAQ,EAAE;AACZ,EAAsD;AAKtD;;;;;;CAMC,GACD,OAAO,MAAMC,iBAAiBV,EAAEW,IAAI,CAAC;IAAC;IAAS;IAAS;CAAS,EAAC;AAclE,MAAMC,kBAAkBZ,EAAEW,IAAI,CAAC;IAAC;IAAU;CAAe;AAKzD,cAAc,GACd,OAAO,MAAME,aAAab,EAAEc,MAAM,CAAC;IACjCC,OAAOf,EAAEgB,QAAQ,CAACJ;IAClBK,OAAOjB,EAAEgB,QAAQ,CAAChB,EAAEkB,MAAM;AAC5B,GAAE;AAKF,MAAMC,kBAAkBnB,EAAEc,MAAM,CAAC;IAACG,OAAOjB,EAAEgB,QAAQ,CAAChB,EAAEkB,MAAM;AAAG;AAE/D,cAAc,GACd,OAAO,MAAME,8BAA8BpB,EAAEc,MAAM,CAAC;IAClDO,MAAMrB,EAA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BtD,EAAEc,MAAM,CAAC;IAC/ByC,MAAMvD,EAAE2C,OAAO,CAAC;IAChB,GAAGJ,2BAA2B,aAAa;AAC7C;AAQA,YAAY,GACZ,OAAO,SAASiB,gBAAgBC,SAA+B;IAC7D,OAAO;QAAC,GAAGA,SAAS;QAAEF,MAAM;IAAQ;AACtC;AAEA,cAAc,GACd,OAAO,MAAMG,6BAA6B1D,EAAEqD,kBAAkB,CAAC,QAAQ;IAACC;CAAgB,EAAC;AAEzF,MAAMK,0BAA0B3D,EAAEc,MAAM,CAAC;IACvC,GAAGoB,2BAA2B,QAAQ;IACtC0B,QAAQ5D,EAAEgB,QAAQ,CAAChB,EAAE6D,OAAO;IAC5BrB,OAAOxC,EAAEuB,MAAM;AACjB;AAEA;;;CAGC,GACD,OAAO,MAAMuC,2BAA2B,sBAAqB;AAE7D,yEAAyE;AACzE,MAAMC,2BAA2B/D,EAAEc,MAAM,CAAC;IACxCkD,SAAShE,EAAE2C,OAAO,CAAC;IACnBsB,QAAQjE,EACLkE,KAAK,CAACP,yBACNvB,KAAK,CACJpC,EAAEmE,MAAM,CACN,CAACF,SAAW,IAAIG,IAAIH,OAAOI,GAAG,CAAC,CAACC,QAAUA,MAAMtC,IAAI,GAAGP,IAAI,KAAKwC,OAAOM,MAAM,EAC7E;AAGR;AAEA;;;;CAIC,GACD,OAAO,MAAMC,eAAexE,EAAEqD,kBAAkB,CAAC,WAAW;IAACU;CAAyB,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/contract.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\n// Shared module-federation extension contract: interface (view/web worker) and\n// config declaration schemas, plus the versions the build stamps.\n// `zod/mini` keeps the bundle small.\n\n/** @internal */\nexport const VIEW_CONTRACT_VERSION = 2\n\n/** @internal */\nexport const WEB_WORKER_CONTRACT_VERSION = 1\n\n/** @internal */\nexport const WINDOW_CONTRACT_VERSION = 1\n\n/** @internal */\nexport const MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION = 1\n\nexport const DASHBOARD_CONFIG_CONTRACT_VERSION = 1\n\nexport const DASHBOARD_CONFIG_TYPE = 'dashboard_config'\n\n/**\n * A view component. The return is opaque so the runtime helpers carry no React\n * dependency — the generated artifact renders it with the app's own React.\n * @public\n */\nexport type ViewComponent<TProps> = (props: TProps) => unknown\n\n/** @public */\nexport interface ViewComponentBaseProps<TView> {\n view: TView\n}\n\n/** Component slots per view surface; windows load outside the component artifact path. @internal */\nexport const VIEW_COMPONENTS = {\n asset_source: ['asset_source'],\n panel: ['title', 'panel'],\n tile: ['tile'],\n window: [],\n} as const satisfies Record<string, readonly string[]>\n\n/** @public */\nexport type ViewSurface = keyof typeof VIEW_COMPONENTS\n\n/**\n * A tile's footprint family — the shape it occupies on the dashboard. Modelled\n * on iOS WidgetKit families, not a linear scale: `banner` is full-width and\n * shallow, which a `small`→`large` magnitude can't express. The host maps a\n * family to a layout slot; the component reads it to render per footprint.\n * @public\n */\nexport const TileSizeSchema = z.enum(['small', 'large', 'banner'])\n\n/** @public */\nexport type TileSize = z.infer<typeof TileSizeSchema>\n\n/** @public */\nexport type WebWorkerType = 'worker'\n\n/**\n * @deprecated Use `WebWorkerType`.\n * @public\n */\nexport type ServiceType = WebWorkerType\n\nconst DockGroupSchema = z.enum(['system', 'applications'])\n\n/** @public */\nexport type DockGroup = z.output<typeof DockGroupSchema>\n\n/** @internal */\nexport const DockSchema = z.object({\n group: z.optional(DockGroupSchema),\n order: z.optional(z.number()),\n})\n\n/** @internal */\nexport type Dock = z.infer<typeof DockSchema>\n\nconst PanelDockSchema = z.object({order: z.optional(z.number())})\n\n/** @internal */\nexport const ViewPlacementMetadataSchema = z.object({\n dock: z.optional(DockSchema),\n icon: z.optional(z.string()),\n})\n\n/** @internal */\nexport type ViewPlacementMetadata = z.infer<typeof ViewPlacementMetadataSchema>\n\n/**\n * A tile's interface metadata: its footprint `size` and an optional `order`\n * the dashboard sorts on, ascending. Both are authored as top-level view fields\n * (see {@link InterfaceDeclarationSchema}) but stored on the record as metadata.\n * @internal\n */\nexport const TileInterfaceMetadataSchema = z.object({\n order: z.optional(z.number()),\n size: TileSizeSchema,\n})\n\n/** @internal */\nexport type TileInterfaceMetadata = z.infer<typeof TileInterfaceMetadataSchema>\n\n/**\n * The contract version each interface type advertises, so the host can check it\n * renders/runs what it expects.\n * @internal\n */\nconst INTERFACE_CONTRACT_VERSIONS = {\n asset_source: VIEW_CONTRACT_VERSION,\n panel: VIEW_CONTRACT_VERSION,\n tile: VIEW_CONTRACT_VERSION,\n window: WINDOW_CONTRACT_VERSION,\n worker: WEB_WORKER_CONTRACT_VERSION,\n} as const satisfies Record<string, number>\n\n/** Every interface type an app exposes — a window, a view, or a web worker. */\nexport type InterfaceKind = keyof typeof INTERFACE_CONTRACT_VERSIONS\n\n/** @internal */\nexport function interfaceContractVersion(kind: InterfaceKind): string {\n return String(INTERFACE_CONTRACT_VERSIONS[kind])\n}\n\n/**\n * The module-federation id a build exposes an interface at. Dev stamps the same\n * id a deploy would, so the workbench loads a local interface like a deployed one.\n * @internal\n */\nexport function interfaceModuleId(kind: string, name: string): string {\n switch (kind) {\n case 'asset_source':\n case 'panel':\n case 'tile': {\n return `views/${name}`\n }\n case 'window': {\n return 'App'\n }\n case 'worker': {\n return `services/${name}`\n }\n default: {\n throw new Error(`Cannot derive a moduleId for unknown interface kind: ${kind}`)\n }\n }\n}\n\n// Shared `name` + `src`; `kind` only tailors the validation message.\nfunction extensionDeclarationFields(kind: 'Field' | 'View' | 'Web worker') {\n const pattern = /^[a-zA-Z0-9_-]+$/\n return {\n name: z.string().check(z.regex(pattern, `${kind} \\`name\\` must match ${pattern}`)),\n src: z.string(),\n }\n}\n\n// Every interface shares `name` + `src` + a display `title`,\n// which Brett requires on the record each becomes.\nfunction interfaceDeclarationFields(kind: 'View' | 'Web worker') {\n return {\n ...extensionDeclarationFields(kind),\n title: z.string(`${kind} \\`title\\` is required`),\n }\n}\n\nconst PanelViewSchema = z.object({\n surface: z.literal('panel'),\n ...interfaceDeclarationFields('View'),\n dock: z.optional(PanelDockSchema),\n icon: z.optional(z.string()),\n})\n\n/** @public */\nexport type PanelViewDeclaration = z.output<typeof PanelViewSchema>\n\n/** @public */\nexport type DefinePanelViewInput = Omit<PanelViewDeclaration, 'surface'>\n\n/** @public */\nexport function definePanelView(view: DefinePanelViewInput): PanelViewDeclaration {\n return {...view, surface: 'panel'}\n}\n\nconst WindowViewSchema = z.object({\n surface: z.literal('window'),\n ...interfaceDeclarationFields('View'),\n dock: z.optional(DockSchema),\n icon: z.optional(z.string()),\n})\n\n/** @public */\nexport type WindowViewDeclaration = z.output<typeof WindowViewSchema>\n\n/** @public */\nexport type DefineWindowViewInput = Omit<WindowViewDeclaration, 'surface'>\n\n/** @public */\nexport function defineWindowView(view: DefineWindowViewInput): WindowViewDeclaration {\n return {...view, surface: 'window'}\n}\n\nconst AssetSourceViewSchema = z.object({\n surface: z.literal('asset_source'),\n ...interfaceDeclarationFields('View'),\n})\n\n/** @public */\nexport type AssetSourceViewDeclaration = z.output<typeof AssetSourceViewSchema>\n\n/** @public */\nexport type DefineAssetSourceViewInput = Omit<AssetSourceViewDeclaration, 'surface'>\n\n/** @public */\nexport function defineAssetSourceView(\n view: DefineAssetSourceViewInput,\n): AssetSourceViewDeclaration {\n return {...view, surface: 'asset_source'}\n}\n\nconst TileViewSchema = z.object({\n surface: z.literal('tile'),\n ...interfaceDeclarationFields('View'),\n /** Sort position within its layout track, ascending. Optional. */\n order: z.optional(z.number()),\n /** Footprint family the dashboard lays the tile out by. */\n size: TileSizeSchema,\n})\n\n/** @public */\nexport type TileViewDeclaration = z.output<typeof TileViewSchema>\n\n/** @public */\nexport type DefineTileViewInput = Omit<TileViewDeclaration, 'surface'>\n\n/** @public */\nexport function defineTileView(view: DefineTileViewInput): TileViewDeclaration {\n return {...view, surface: 'tile'}\n}\n\n/** @internal */\nexport const InterfaceDeclarationSchema = z.discriminatedUnion('surface', [\n WindowViewSchema,\n PanelViewSchema,\n AssetSourceViewSchema,\n TileViewSchema,\n])\n\n/** @public */\nexport type ViewDeclaration = z.output<typeof InterfaceDeclarationSchema>\n\nconst WebWorkerSchema = z.object({\n type: z.literal('worker'),\n ...interfaceDeclarationFields('Web worker'),\n})\n\n/** @public */\nexport type WebWorkerDeclaration = z.output<typeof WebWorkerSchema>\n\n/** @public */\nexport type DefineWebWorkerInput = Omit<WebWorkerDeclaration, 'type'>\n\n/** @public */\nexport function defineWebWorker(webWorker: DefineWebWorkerInput): WebWorkerDeclaration {\n return {...webWorker, type: 'worker'}\n}\n\n/** @internal */\nexport const WebWorkerDeclarationSchema = z.discriminatedUnion('type', [WebWorkerSchema])\n\nconst MediaLibraryFieldSchema = z.object({\n ...extensionDeclarationFields('Field'),\n public: z.optional(z.boolean()),\n title: z.string(),\n})\n\n/**\n * Stamped where the config crosses a boundary so the authoring model doesn't carry a constant discriminator.\n * @internal\n */\nexport const INSTALLATION_CONFIG_TYPE = 'installation_config'\n\n// `appType` is stamped by `unstable_defineMediaLibrary`, never authored.\nconst MediaLibraryConfigSchema = z.object({\n appType: z.literal('media-library'),\n fields: z\n .array(MediaLibraryFieldSchema)\n .check(\n z.refine(\n (fields) => new Set(fields.map((field) => field.name)).size === fields.length,\n 'Field `name` must be unique within a media library',\n ),\n ),\n})\n\nconst DashboardConfigSchema = z.object({\n appType: z.literal('dashboard'),\n src: z.string('Dashboard configuration `src` must be a path to the configuration file'),\n})\n\n/**\n * A workbench config's built value, keyed by `appType`; deploys as a versioned\n * snapshot, not an interface.\n * @internal\n */\nexport const ConfigSchema = z.discriminatedUnion('appType', [\n DashboardConfigSchema,\n MediaLibraryConfigSchema,\n])\n\n/**\n * The config value, keyed by `appType`, the build expands into a federation\n * remote and the deploy summarizes.\n * @internal\n */\nexport type WorkbenchConfigValue = z.output<typeof ConfigSchema>\n\nconst CONFIG_CONTRACT_VERSIONS: Record<WorkbenchConfigValue['appType'], number> = {\n dashboard: DASHBOARD_CONFIG_CONTRACT_VERSION,\n 'media-library': MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION,\n}\n\n/** @internal */\nexport function configContractVersion(appType: WorkbenchConfigValue['appType']): string {\n return String(CONFIG_CONTRACT_VERSIONS[appType])\n}\n"],"names":["z","VIEW_CONTRACT_VERSION","WEB_WORKER_CONTRACT_VERSION","WINDOW_CONTRACT_VERSION","MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION","DASHBOARD_CONFIG_CONTRACT_VERSION","DASHBOARD_CONFIG_TYPE","VIEW_COMPONENTS","asset_source","panel","tile","window","TileSizeSchema","enum","DockGroupSchema","DockSchema","object","group","optional","order","number","PanelDockSchema","ViewPlacementMetadataSchema","dock","icon","string","TileInterfaceMetadataSchema","size","INTERFACE_CONTRACT_VERSIONS","worker","interfaceContractVersion","kind","String","interfaceModuleId","name","Error","extensionDeclarationFields","pattern","check","regex","src","interfaceDeclarationFields","title","PanelViewSchema","surface","literal","definePanelView","view","WindowViewSchema","defineWindowView","AssetSourceViewSchema","defineAssetSourceView","TileViewSchema","defineTileView","InterfaceDeclarationSchema","discriminatedUnion","WebWorkerSchema","type","defineWebWorker","webWorker","WebWorkerDeclarationSchema","MediaLibraryFieldSchema","public","boolean","INSTALLATION_CONFIG_TYPE","MediaLibraryConfigSchema","appType","fields","array","refine","Set","map","field","length","DashboardConfigSchema","ConfigSchema","CONFIG_CONTRACT_VERSIONS","dashboard","configContractVersion"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B,+EAA+E;AAC/E,kEAAkE;AAClE,qCAAqC;AAErC,cAAc,GACd,OAAO,MAAMC,wBAAwB,EAAC;AAEtC,cAAc,GACd,OAAO,MAAMC,8BAA8B,EAAC;AAE5C,cAAc,GACd,OAAO,MAAMC,0BAA0B,EAAC;AAExC,cAAc,GACd,OAAO,MAAMC,wCAAwC,EAAC;AAEtD,OAAO,MAAMC,oCAAoC,EAAC;AAElD,OAAO,MAAMC,wBAAwB,mBAAkB;AAcvD,kGAAkG,GAClG,OAAO,MAAMC,kBAAkB;I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AO,CAAC;IACnBsB,QAAQnE,EACLoE,KAAK,CAACP,yBACNvB,KAAK,CACJtC,EAAEqE,MAAM,CACN,CAACF,SAAW,IAAIG,IAAIH,OAAOI,GAAG,CAAC,CAACC,QAAUA,MAAMtC,IAAI,GAAGP,IAAI,KAAKwC,OAAOM,MAAM,EAC7E;AAGR;AAEA,MAAMC,wBAAwB1E,EAAEgB,MAAM,CAAC;IACrCkD,SAASlE,EAAE6C,OAAO,CAAC;IACnBL,KAAKxC,EAAEyB,MAAM,CAAC;AAChB;AAEA;;;;CAIC,GACD,OAAO,MAAMkD,eAAe3E,EAAEuD,kBAAkB,CAAC,WAAW;IAC1DmB;IACAT;CACD,EAAC;AASF,MAAMW,2BAA4E;IAChFC,WAAWxE;IACX,iBAAiBD;AACnB;AAEA,cAAc,GACd,OAAO,SAAS0E,sBAAsBZ,OAAwC;IAC5E,OAAOlC,OAAO4C,wBAAwB,CAACV,QAAQ;AACjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dashboardConfig.ts"],"sourcesContent":["import {type CurrentUser} from '@sanity/sdk'\nimport {type View, type ViewApplication} from '@sanity/sdk/dashboard'\n\ninterface ApplicationsContext {\n applications: readonly (ViewApplication & {\n views: readonly View<{includeApplication: false}>[]\n })[]\n currentUser: CurrentUser\n}\n\ninterface DefineDashboardConfigInput {\n applications?: {\n hidden?: (\n references: readonly ViewApplication['reference'][],\n context: ApplicationsContext,\n ) => readonly ViewApplication['reference'][]\n visible?: (\n references: readonly ViewApplication['reference'][],\n context: ApplicationsContext,\n ) => readonly ViewApplication['reference'][]\n }\n views?: (views: readonly View[], context: {currentUser: CurrentUser}) => readonly View[]\n}\n\nexport function defineDashboardConfig(\n config: DefineDashboardConfigInput,\n): DefineDashboardConfigInput {\n return config\n}\n"],"names":["defineDashboardConfig","config"],"mappings":"AAwBA,OAAO,SAASA,sBACdC,MAAkC;IAElC,OAAOA;AACT"}
|
package/dist/defineApp.js
CHANGED
|
@@ -47,7 +47,11 @@ import { DockSchema, InterfaceDeclarationSchema, WebWorkerDeclarationSchema } fr
|
|
|
47
47
|
*/ name: z.optional(z.string().check(z.regex(APP_SLUG_PATTERN, 'App `name` must be lowercase alphanumerics and hyphens, starting with a letter and ending with an alphanumeric'))),
|
|
48
48
|
/** Organization that owns the app — it runs in and deploys to this organization's Dashboard. */ organizationId: z.string("App `organizationId` is required — pass the owning organization's ID to `defineApplication`"),
|
|
49
49
|
slug: z.string('App `slug` is required — the hostname the application is created at on deploy').check(z.regex(APP_SLUG_PATTERN, 'App `slug` must be lowercase alphanumerics and hyphens, starting with a letter and ending with an alphanumeric')),
|
|
50
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* User-facing app title. Wins over studio.config.ts title on merge. Defaults
|
|
52
|
+
* to `name` in start case (`drop-desk` becomes `Drop Desk`), the way Studio
|
|
53
|
+
* titles a workspace without one.
|
|
54
|
+
*/ title: z.optional(z.string()),
|
|
51
55
|
/** Views the app exposes (e.g. a window, dock panels, and tiles). */ views: z.optional(z.array(InterfaceDeclarationSchema, 'must be an array of views')),
|
|
52
56
|
/** Dashboard visibility of the app. Defaults to `default` when omitted. */ visibility: z.optional(z.enum(APP_VISIBILITIES)),
|
|
53
57
|
/** Background web workers the app runs. */ webWorkers: z.optional(z.array(WebWorkerDeclarationSchema, 'must be an array of web workers'))
|
|
@@ -69,6 +73,13 @@ z.refine((input)=>!(input.applicationType === 'studio' && input.entry !== undefi
|
|
|
69
73
|
'entry'
|
|
70
74
|
]
|
|
71
75
|
}));
|
|
76
|
+
/**
|
|
77
|
+
* The app's display title. Without one, `name` (or `slug`) in start case, as
|
|
78
|
+
* Studio's `startCase(name)` does: `my-app-v2` becomes `My App V 2`.
|
|
79
|
+
* @internal
|
|
80
|
+
*/ export function resolveAppTitle(app) {
|
|
81
|
+
return app.title?.trim() || ((app.name ?? app.slug).match(/[a-z]+|\d+/gi) ?? []).map((word)=>word[0].toUpperCase() + word.slice(1)).join(' ');
|
|
82
|
+
}
|
|
72
83
|
/**
|
|
73
84
|
* Nominal brand the CLI discriminates on to enable the workbench build/deploy
|
|
74
85
|
* codepath. Registered via `Symbol.for` so the marker survives module-realm
|
|
@@ -104,7 +115,7 @@ z.refine((input)=>!(input.applicationType === 'studio' && input.entry !== undefi
|
|
|
104
115
|
* same global symbol rather than importing it.
|
|
105
116
|
*/ const WORKBENCH_CONFIG = Symbol.for('sanity.workbench.defineConfig');
|
|
106
117
|
/**
|
|
107
|
-
* Whether `app` is a branded `unstable_defineMediaLibrary(...)` config — a
|
|
118
|
+
* Whether `app` is a branded `unstable_defineMediaLibrary(...)` or `defineDashboard(...)` config — a
|
|
108
119
|
* config-carrier rather than an app. Configs live in `cliConfig.app` alongside
|
|
109
120
|
* apps but resolve through `resolveWorkbenchConfig`, not `resolveWorkbenchApp`.
|
|
110
121
|
* @public
|
|
@@ -129,5 +140,17 @@ z.refine((input)=>!(input.applicationType === 'studio' && input.entry !== undefi
|
|
|
129
140
|
writable: false
|
|
130
141
|
});
|
|
131
142
|
}
|
|
143
|
+
export function defineDashboard(input) {
|
|
144
|
+
return Object.defineProperty({
|
|
145
|
+
appType: 'dashboard',
|
|
146
|
+
organizationId: input.organizationId,
|
|
147
|
+
src: input.src
|
|
148
|
+
}, WORKBENCH_CONFIG, {
|
|
149
|
+
configurable: false,
|
|
150
|
+
enumerable: false,
|
|
151
|
+
value: true,
|
|
152
|
+
writable: false
|
|
153
|
+
});
|
|
154
|
+
}
|
|
132
155
|
|
|
133
156
|
//# sourceMappingURL=defineApp.js.map
|
package/dist/defineApp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defineApp.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\nimport {APP_SLUG_PATTERN} from './appSlug.js'\nimport {DockSchema, InterfaceDeclarationSchema, WebWorkerDeclarationSchema} from './contract.js'\n\n/**\n * Dashboard visibility values. Mirrors `APP_VISIBILITIES` in `@sanity/cli-core`\n * (which can't be imported here — pulling the barrel into this lean module bloats\n * the config-load path). Kept in sync by a type test in `defineApp.test.ts`.\n */\nconst APP_VISIBILITIES = ['default', 'unlisted', 'disabled'] as const\n\n/**\n * Internal application discriminator. Sanity-owned singleton apps only;\n * validated by the schema but excluded from the public `DefineAppInput` type.\n */\nconst ApplicationType = z.enum(['coreApp', 'studio', 'canvas', 'dashboard'])\n\n/**\n * Runtime-validation schema for `defineApplication`.\n * @internal\n */\nexport const DefineAppInputSchema = z\n .object({\n /**\n * Internal — Sanity-owned singleton apps only. Validated here but excluded\n * from the public `DefineAppInput` type.\n * @internal\n */\n applicationType: z.optional(ApplicationType),\n /** Default placement inherited by window views. */\n dock: z.optional(DockSchema),\n /**\n * App entrypoint module. Defaults to `./src/App.tsx` when omitted. The build\n * derives the app's navigable `app` view from it. SDK apps only — setting it\n * on a studio is rejected (studio app views are not yet implemented).\n */\n entry: z.optional(z.string(\"must be a path to the app's entry file\")),\n /**\n * Path to the app's icon, relative to the project root: a PNG, JPEG, GIF,\n * WebP, SVG, BMP, TIFF, HEIF or AVIF image of at most 5 MB. Wins over\n * manifest/studio icon.\n */\n icon: z.optional(z.string()),\n /** Sanity-owned app deployed once and installed per org. @internal */\n isSingleton: z.optional(z.boolean()),\n /**\n * Stable identity, distinct from the `slug` address. Defaults to `slug` when\n * omitted. Identity keys — the build id and derived interface ids — are built\n * from this, so renaming the slug no longer changes identity.\n */\n name: z.optional(\n z\n .string()\n .check(\n z.regex(\n APP_SLUG_PATTERN,\n 'App `name` must be lowercase alphanumerics and hyphens, starting with a letter and ending with an alphanumeric',\n ),\n ),\n ),\n /** Organization that owns the app — it runs in and deploys to this organization's Dashboard. */\n organizationId: z.string(\n \"App `organizationId` is required — pass the owning organization's ID to `defineApplication`\",\n ),\n slug: z\n .string('App `slug` is required — the hostname the application is created at on deploy')\n .check(\n z.regex(\n APP_SLUG_PATTERN,\n 'App `slug` must be lowercase alphanumerics and hyphens, starting with a letter and ending with an alphanumeric',\n ),\n ),\n /** User-facing app title. Wins over studio.config.ts title on merge. */\n title: z.string(),\n /** Views the app exposes (e.g. a window, dock panels, and tiles). */\n views: z.optional(z.array(InterfaceDeclarationSchema, 'must be an array of views')),\n /** Dashboard visibility of the app. Defaults to `default` when omitted. */\n visibility: z.optional(z.enum(APP_VISIBILITIES)),\n /** Background web workers the app runs. */\n webWorkers: z.optional(z.array(WebWorkerDeclarationSchema, 'must be an array of web workers')),\n })\n .check(\n z.refine((input) => {\n const names = [\n ...(input.entry === undefined ? [] : [input.name ?? input.slug]),\n ...(input.views ?? []).map((view) => view.name),\n ...(input.webWorkers ?? []).map((webWorker) => webWorker.name),\n ]\n return new Set(names).size === names.length\n }, '`name` must be unique across views and web workers. Rename one of the duplicates.'),\n // Studio app views are not implemented yet. A studio that declares `entry`\n // (the SDK app-view entrypoint) is rejected here rather than silently\n // generating one; studios keep navigating via their existing render path.\n z.refine((input) => !(input.applicationType === 'studio' && input.entry !== undefined), {\n error: 'App views for studios are not implemented yet',\n path: ['entry'],\n }),\n )\n\n/**\n * User-facing input for `defineApplication`. Excludes the internal\n * `applicationType` and `isSingleton`.\n * @public\n */\nexport type DefineAppInput = Omit<\n z.output<typeof DefineAppInputSchema>,\n 'applicationType' | 'isSingleton'\n>\n\n/**\n * Nominal brand the CLI discriminates on to enable the workbench build/deploy\n * codepath. Registered via `Symbol.for` so the marker survives module-realm\n * boundaries — `@sanity/cli-core` re-derives the same global symbol with\n * `Symbol.for` rather than importing it, so it stays internal to this module.\n */\nconst WORKBENCH_APP: unique symbol = Symbol.for('sanity.workbench.defineApp')\n\n/**\n * The branded result of `defineApplication`. Carries the same fields as the\n * input plus the internal brand — users only ever see `DefineAppInput`.\n * @public\n */\nexport type DefineAppResult = {\n [K in keyof DefineAppInput]: Exclude<DefineAppInput[K], undefined>\n} & {readonly [WORKBENCH_APP]: true}\n\n/**\n * A branded app as the CLI reads it — the full schema shape, including the\n * internal fields `DefineAppInput` omits. Schema-derived so the narrowing\n * can't drift from what the schema validates.\n * @public\n */\nexport type WorkbenchApp = DefineAppResult & z.output<typeof DefineAppInputSchema>\n\n/**\n * Whether `app` is a branded `defineApplication(...)` result — the sole\n * workbench opt-in.\n * @public\n */\nexport function isWorkbenchApp(app: unknown): app is WorkbenchApp {\n return typeof app === 'object' && app !== null && WORKBENCH_APP in app\n}\n\n/**\n * Declare a Sanity Dashboard application. Identity at runtime — returns the same\n * object reference, tagged with the Dashboard brand. Field validation (the\n * `slug` pattern etc.) runs at build time in the CLI via `DefineAppInputSchema`;\n * this helper stays a thin, pure identity wrapper.\n * @public\n */\nexport function defineApplication(input: DefineAppInput): DefineAppResult {\n return Object.defineProperty(input, WORKBENCH_APP, {\n configurable: false,\n enumerable: false,\n value: true,\n writable: false,\n }) as DefineAppResult\n}\n\n/**\n * One custom field a media library exposes. `src` default-exports a `defineField(...)` schema type.\n * @public\n */\nexport interface MediaLibraryField {\n /** Unique within the media library. */\n name: string\n src: string\n title: string\n\n /** Readable outside the owning organization. */\n public?: boolean\n}\n\n/**\n * Sanity-owned singleton, so authors don't name or title the app — only `organizationId` is required.\n * @public\n */\nexport interface DefineMediaLibraryInput {\n /** Organization that owns the media library — the CLI runs and deploys against it. */\n organizationId: string\n\n fields?: MediaLibraryField[]\n}\n\n/**\n * Nominal brand the CLI discriminates a config on. A config is *not* an app: it\n * carries no `slug`/`title`/application identity, only a target `appType`, its\n * owning `organizationId`, and its `fields`. Registered via `Symbol.for` so the\n * marker survives module-realm boundaries — `@sanity/cli-core` re-derives the\n * same global symbol rather than importing it.\n */\nconst WORKBENCH_CONFIG: unique symbol = Symbol.for('sanity.workbench.defineConfig')\n\n/**\n * A branded workbench config as the CLI reads it: bound to its target app by\n * `appType`, not carrying its own app identity. The deploy/undeploy/build paths\n * discriminate it via {@link isWorkbenchConfig}.\n * @public\n */\nexport interface WorkbenchConfig {\n appType: 'media-library'\n fields: MediaLibraryField[]\n organizationId: string\n readonly [WORKBENCH_CONFIG]: true\n}\n\n/**\n * Whether `app` is a branded `unstable_defineMediaLibrary(...)` config — a\n * config-carrier rather than an app. Configs live in `cliConfig.app` alongside\n * apps but resolve through `resolveWorkbenchConfig`, not `resolveWorkbenchApp`.\n * @public\n */\nexport function isWorkbenchConfig(app: unknown): app is WorkbenchConfig {\n return typeof app === 'object' && app !== null && WORKBENCH_CONFIG in app\n}\n\n/**\n * Declare the Sanity Media Library config. The Media Library is a Sanity-owned\n * singleton, so this is not an app — it carries no slug or title, only the\n * target `appType`, its owning organization, and the `fields` it contributes to\n * the installation's config.\n * @public\n */\nexport function unstable_defineMediaLibrary(input: DefineMediaLibraryInput): WorkbenchConfig {\n return Object.defineProperty(\n {appType: 'media-library', fields: input.fields ?? [], organizationId: input.organizationId},\n WORKBENCH_CONFIG,\n {configurable: false, enumerable: false, value: true, writable: false},\n ) as WorkbenchConfig\n}\n"],"names":["z","APP_SLUG_PATTERN","DockSchema","InterfaceDeclarationSchema","WebWorkerDeclarationSchema","APP_VISIBILITIES","ApplicationType","enum","DefineAppInputSchema","object","applicationType","optional","dock","entry","string","icon","isSingleton","boolean","name","check","regex","organizationId","slug","title","views","array","visibility","webWorkers","refine","input","names","undefined","map","view","webWorker","Set","size","length","error","path","WORKBENCH_APP","Symbol","for","isWorkbenchApp","app","defineApplication","Object","defineProperty","configurable","enumerable","value","writable","WORKBENCH_CONFIG","isWorkbenchConfig","unstable_defineMediaLibrary","appType","fields"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B,SAAQC,gBAAgB,QAAO,eAAc;AAC7C,SAAQC,UAAU,EAAEC,0BAA0B,EAAEC,0BAA0B,QAAO,gBAAe;AAEhG;;;;CAIC,GACD,MAAMC,mBAAmB;IAAC;IAAW;IAAY;CAAW;AAE5D;;;CAGC,GACD,MAAMC,kBAAkBN,EAAEO,IAAI,CAAC;IAAC;IAAW;IAAU;IAAU;CAAY;AAE3E;;;CAGC,GACD,OAAO,MAAMC,uBAAuBR,EACjCS,MAAM,CAAC;IACN;;;;KAIC,GACDC,iBAAi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AAG,sFACH,2EAA2E;AAC3E,sEAAsE;AACtE,0EAA0E;AAC1ErC,EAAE4B,MAAM,CAAC,CAACC,QAAU,CAAEA,CAAAA,MAAMnB,eAAe,KAAK,YAAYmB,MAAMhB,KAAK,KAAKkB,SAAQ,GAAI;IACtFO,OAAO;IACPC,MAAM;QAAC;KAAQ;AACjB,IACD;AAYH;;;;;CAKC,GACD,MAAMC,gBAA+BC,OAAOC,GAAG,CAAC;AAmBhD;;;;CAIC,GACD,OAAO,SAASC,eAAeC,GAAY;IACzC,OAAO,OAAOA,QAAQ,YAAYA,QAAQ,QAAQJ,iBAAiBI;AACrE;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,kBAAkBhB,KAAqB;IACrD,OAAOiB,OAAOC,cAAc,CAAClB,OAAOW,eAAe;QACjDQ,cAAc;QACdC,YAAY;QACZC,OAAO;QACPC,UAAU;IACZ;AACF;AA2BA;;;;;;CAMC,GACD,MAAMC,mBAAkCX,OAAOC,GAAG,CAAC;AAenD;;;;;CAKC,GACD,OAAO,SAASW,kBAAkBT,GAAY;IAC5C,OAAO,OAAOA,QAAQ,YAAYA,QAAQ,QAAQQ,oBAAoBR;AACxE;AAEA;;;;;;CAMC,GACD,OAAO,SAASU,4BAA4BzB,KAA8B;IACxE,OAAOiB,OAAOC,cAAc,CAC1B;QAACQ,SAAS;QAAiBC,QAAQ3B,MAAM2B,MAAM,IAAI,EAAE;QAAEnC,gBAAgBQ,MAAMR,cAAc;IAAA,GAC3F+B,kBACA;QAACJ,cAAc;QAAOC,YAAY;QAAOC,OAAO;QAAMC,UAAU;IAAK;AAEzE"}
|
|
1
|
+
{"version":3,"sources":["../src/defineApp.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\nimport {APP_SLUG_PATTERN} from './appSlug.js'\nimport {\n DockSchema,\n InterfaceDeclarationSchema,\n WebWorkerDeclarationSchema,\n type WorkbenchConfigValue,\n} from './contract.js'\n\n/**\n * Dashboard visibility values. Mirrors `APP_VISIBILITIES` in `@sanity/cli-core`\n * (which can't be imported here — pulling the barrel into this lean module bloats\n * the config-load path). Kept in sync by a type test in `defineApp.test.ts`.\n */\nconst APP_VISIBILITIES = ['default', 'unlisted', 'disabled'] as const\n\n/**\n * Internal application discriminator. Sanity-owned singleton apps only;\n * validated by the schema but excluded from the public `DefineAppInput` type.\n */\nconst ApplicationType = z.enum(['coreApp', 'studio', 'canvas', 'dashboard'])\n\n/**\n * Runtime-validation schema for `defineApplication`.\n * @internal\n */\nexport const DefineAppInputSchema = z\n .object({\n /**\n * Internal — Sanity-owned singleton apps only. Validated here but excluded\n * from the public `DefineAppInput` type.\n * @internal\n */\n applicationType: z.optional(ApplicationType),\n /** Default placement inherited by window views. */\n dock: z.optional(DockSchema),\n /**\n * App entrypoint module. Defaults to `./src/App.tsx` when omitted. The build\n * derives the app's navigable `app` view from it. SDK apps only — setting it\n * on a studio is rejected (studio app views are not yet implemented).\n */\n entry: z.optional(z.string(\"must be a path to the app's entry file\")),\n /**\n * Path to the app's icon, relative to the project root: a PNG, JPEG, GIF,\n * WebP, SVG, BMP, TIFF, HEIF or AVIF image of at most 5 MB. Wins over\n * manifest/studio icon.\n */\n icon: z.optional(z.string()),\n /** Sanity-owned app deployed once and installed per org. @internal */\n isSingleton: z.optional(z.boolean()),\n /**\n * Stable identity, distinct from the `slug` address. Defaults to `slug` when\n * omitted. Identity keys — the build id and derived interface ids — are built\n * from this, so renaming the slug no longer changes identity.\n */\n name: z.optional(\n z\n .string()\n .check(\n z.regex(\n APP_SLUG_PATTERN,\n 'App `name` must be lowercase alphanumerics and hyphens, starting with a letter and ending with an alphanumeric',\n ),\n ),\n ),\n /** Organization that owns the app — it runs in and deploys to this organization's Dashboard. */\n organizationId: z.string(\n \"App `organizationId` is required — pass the owning organization's ID to `defineApplication`\",\n ),\n slug: z\n .string('App `slug` is required — the hostname the application is created at on deploy')\n .check(\n z.regex(\n APP_SLUG_PATTERN,\n 'App `slug` must be lowercase alphanumerics and hyphens, starting with a letter and ending with an alphanumeric',\n ),\n ),\n /**\n * User-facing app title. Wins over studio.config.ts title on merge. Defaults\n * to `name` in start case (`drop-desk` becomes `Drop Desk`), the way Studio\n * titles a workspace without one.\n */\n title: z.optional(z.string()),\n /** Views the app exposes (e.g. a window, dock panels, and tiles). */\n views: z.optional(z.array(InterfaceDeclarationSchema, 'must be an array of views')),\n /** Dashboard visibility of the app. Defaults to `default` when omitted. */\n visibility: z.optional(z.enum(APP_VISIBILITIES)),\n /** Background web workers the app runs. */\n webWorkers: z.optional(z.array(WebWorkerDeclarationSchema, 'must be an array of web workers')),\n })\n .check(\n z.refine((input) => {\n const names = [\n ...(input.entry === undefined ? [] : [input.name ?? input.slug]),\n ...(input.views ?? []).map((view) => view.name),\n ...(input.webWorkers ?? []).map((webWorker) => webWorker.name),\n ]\n return new Set(names).size === names.length\n }, '`name` must be unique across views and web workers. Rename one of the duplicates.'),\n // Studio app views are not implemented yet. A studio that declares `entry`\n // (the SDK app-view entrypoint) is rejected here rather than silently\n // generating one; studios keep navigating via their existing render path.\n z.refine((input) => !(input.applicationType === 'studio' && input.entry !== undefined), {\n error: 'App views for studios are not implemented yet',\n path: ['entry'],\n }),\n )\n\n/**\n * User-facing input for `defineApplication`. Excludes the internal\n * `applicationType` and `isSingleton`.\n * @public\n */\nexport type DefineAppInput = Omit<\n z.output<typeof DefineAppInputSchema>,\n 'applicationType' | 'isSingleton'\n>\n\n/**\n * The app's display title. Without one, `name` (or `slug`) in start case, as\n * Studio's `startCase(name)` does: `my-app-v2` becomes `My App V 2`.\n * @internal\n */\nexport function resolveAppTitle(app: Pick<DefineAppInput, 'name' | 'slug' | 'title'>): string {\n return (\n app.title?.trim() ||\n ((app.name ?? app.slug).match(/[a-z]+|\\d+/gi) ?? [])\n .map((word) => word[0].toUpperCase() + word.slice(1))\n .join(' ')\n )\n}\n\n/**\n * Nominal brand the CLI discriminates on to enable the workbench build/deploy\n * codepath. Registered via `Symbol.for` so the marker survives module-realm\n * boundaries — `@sanity/cli-core` re-derives the same global symbol with\n * `Symbol.for` rather than importing it, so it stays internal to this module.\n */\nconst WORKBENCH_APP: unique symbol = Symbol.for('sanity.workbench.defineApp')\n\n/**\n * The branded result of `defineApplication`. Carries the same fields as the\n * input plus the internal brand — users only ever see `DefineAppInput`.\n * @public\n */\nexport type DefineAppResult = {\n [K in keyof DefineAppInput]: Exclude<DefineAppInput[K], undefined>\n} & {readonly [WORKBENCH_APP]: true}\n\n/**\n * A branded app as the CLI reads it — the full schema shape, including the\n * internal fields `DefineAppInput` omits. Schema-derived so the narrowing\n * can't drift from what the schema validates.\n * @public\n */\nexport type WorkbenchApp = DefineAppResult & z.output<typeof DefineAppInputSchema>\n\n/**\n * Whether `app` is a branded `defineApplication(...)` result — the sole\n * workbench opt-in.\n * @public\n */\nexport function isWorkbenchApp(app: unknown): app is WorkbenchApp {\n return typeof app === 'object' && app !== null && WORKBENCH_APP in app\n}\n\n/**\n * Declare a Sanity Dashboard application. Identity at runtime — returns the same\n * object reference, tagged with the Dashboard brand. Field validation (the\n * `slug` pattern etc.) runs at build time in the CLI via `DefineAppInputSchema`;\n * this helper stays a thin, pure identity wrapper.\n * @public\n */\nexport function defineApplication(input: DefineAppInput): DefineAppResult {\n return Object.defineProperty(input, WORKBENCH_APP, {\n configurable: false,\n enumerable: false,\n value: true,\n writable: false,\n }) as DefineAppResult\n}\n\n/**\n * One custom field a media library exposes. `src` default-exports a `defineField(...)` schema type.\n * @public\n */\nexport type MediaLibraryField = MediaLibraryConfig['fields'][number]\n\n/**\n * Sanity-owned singleton, so authors don't name or title the app — only `organizationId` is required.\n * @public\n */\nexport interface DefineMediaLibraryInput {\n /** Organization that owns the media library — the CLI runs and deploys against it. */\n organizationId: string\n\n fields?: MediaLibraryField[]\n}\n\n/**\n * Nominal brand the CLI discriminates a config on. A config is *not* an app: it\n * carries no `slug`/`title`/application identity, only a target `appType`, its\n * owning `organizationId`, and its `fields`. Registered via `Symbol.for` so the\n * marker survives module-realm boundaries — `@sanity/cli-core` re-derives the\n * same global symbol rather than importing it.\n */\nconst WORKBENCH_CONFIG: unique symbol = Symbol.for('sanity.workbench.defineConfig')\n\n/**\n * A branded workbench config as the CLI reads it: bound to its target app by\n * `appType`, not carrying its own app identity. The deploy/undeploy/build paths\n * discriminate it via {@link isWorkbenchConfig}.\n * @public\n */\nexport type WorkbenchConfig = WorkbenchConfigValue & {\n organizationId: string\n readonly [WORKBENCH_CONFIG]: true\n}\n\n/** @public */\nexport type MediaLibraryConfig = Extract<WorkbenchConfig, {appType: 'media-library'}>\n\n/** @public */\nexport type DashboardConfig = Extract<WorkbenchConfig, {appType: 'dashboard'}>\n\n/** @public */\nexport type DefineDashboardInput = Omit<DashboardConfig, 'appType' | typeof WORKBENCH_CONFIG>\n\n/**\n * Whether `app` is a branded `unstable_defineMediaLibrary(...)` or `defineDashboard(...)` config — a\n * config-carrier rather than an app. Configs live in `cliConfig.app` alongside\n * apps but resolve through `resolveWorkbenchConfig`, not `resolveWorkbenchApp`.\n * @public\n */\nexport function isWorkbenchConfig(app: unknown): app is WorkbenchConfig {\n return typeof app === 'object' && app !== null && WORKBENCH_CONFIG in app\n}\n\n/**\n * Declare the Sanity Media Library config. The Media Library is a Sanity-owned\n * singleton, so this is not an app — it carries no slug or title, only the\n * target `appType`, its owning organization, and the `fields` it contributes to\n * the installation's config.\n * @public\n */\nexport function unstable_defineMediaLibrary(input: DefineMediaLibraryInput): MediaLibraryConfig {\n return Object.defineProperty(\n {appType: 'media-library', fields: input.fields ?? [], organizationId: input.organizationId},\n WORKBENCH_CONFIG,\n {configurable: false, enumerable: false, value: true, writable: false},\n ) as MediaLibraryConfig\n}\n\nexport function defineDashboard(input: DefineDashboardInput): DashboardConfig {\n return Object.defineProperty(\n {\n appType: 'dashboard',\n organizationId: input.organizationId,\n src: input.src,\n },\n WORKBENCH_CONFIG,\n {configurable: false, enumerable: false, value: true, writable: false},\n ) as DashboardConfig\n}\n"],"names":["z","APP_SLUG_PATTERN","DockSchema","InterfaceDeclarationSchema","WebWorkerDeclarationSchema","APP_VISIBILITIES","ApplicationType","enum","DefineAppInputSchema","object","applicationType","optional","dock","entry","string","icon","isSingleton","boolean","name","check","regex","organizationId","slug","title","views","array","visibility","webWorkers","refine","input","names","undefined","map","view","webWorker","Set","size","length","error","path","resolveAppTitle","app","trim","match","word","toUpperCase","slice","join","WORKBENCH_APP","Symbol","for","isWorkbenchApp","defineApplication","Object","defineProperty","configurable","enumerable","value","writable","WORKBENCH_CONFIG","isWorkbenchConfig","unstable_defineMediaLibrary","appType","fields","defineDashboard","src"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B,SAAQC,gBAAgB,QAAO,eAAc;AAC7C,SACEC,UAAU,EACVC,0BAA0B,EAC1BC,0BAA0B,QAErB,gBAAe;AAEtB;;;;CAIC,GACD,MAAMC,mBAAmB;IAAC;IAAW;IAAY;CAAW;AAE5D;;;CAGC,GACD,MAAMC,kBAAkBN,EAAEO,IAAI,CAAC;IAAC;IAAW;IAAU;IAAU;CAAY;AAE3E;;;CAGC,GACD,OAAO,MAAMC,uBAAuBR,EACjCS,MAAM,CAAC;IACN;;;;KAIC,GACDC,iBAAiBV,EAAEW,QAAQ,CAACL;IAC5B,iDAAiD,GACjDM,MAAMZ,EAAEW,QAAQ,CAACT;IACjB;;;;KAIC,GACDW,OAAOb,EAAEW,QAAQ,CAACX,EAAEc,MAAM,CAAC;IAC3B;;;;KAIC,GACDC,MAAMf,EAAEW,QAAQ,CAACX,EAAEc,MAAM;IACzB,oEAAoE,GACpEE,aAAahB,EAAEW,QAAQ,CAACX,EAAEiB,OAAO;IACjC;;;;KAIC,GACDC,MAAMlB,EAAEW,QAAQ,CACdX,EACGc,MAAM,GACNK,KAAK,CACJnB,EAAEoB,KAAK,CACLnB,kBACA;IAIR,8FAA8F,GAC9FoB,gBAAgBrB,EAAEc,MAAM,CACtB;IAEFQ,MAAMtB,EACHc,MAAM,CAAC,iFACPK,KAAK,CACJnB,EAAEoB,KAAK,CACLnB,kBAC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