@sanity/workbench-cli 2.19.1 → 2.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/_exports/build.d.ts +3 -2
  2. package/dist/_exports/build.js.map +1 -1
  3. package/dist/_exports/defineApp-COehpvlC.d.ts +376 -0
  4. package/dist/_exports/deploy.d.ts +22 -44
  5. package/dist/_exports/deploy.js +2 -0
  6. package/dist/_exports/deploy.js.map +1 -1
  7. package/dist/_exports/{summarizeInterfaces-AM-QbtIA.d.ts → deploySummary-DU7_Vcyq.d.ts} +30 -4
  8. package/dist/_exports/dev.d.ts +1 -1
  9. package/dist/_exports/index.d.ts +22 -4
  10. package/dist/_exports/index.js +2 -1
  11. package/dist/_exports/index.js.map +1 -1
  12. package/dist/_exports/preview.d.ts +1 -1
  13. package/dist/_exports/{registry-DZWnj09G.d.ts → registry-Da2PAcT1.d.ts} +17 -11
  14. package/dist/_exports/{resolveWorkbenchConfig-_iD6fVUH.d.ts → resolveWorkbenchApp-Bn0tsSDM.d.ts} +5 -20
  15. package/dist/_exports/resolveWorkbenchConfig-DkrkqN9H.d.ts +10 -0
  16. package/dist/_exports/undeploy.d.ts +6 -6
  17. package/dist/_exports/undeploy.js +1 -0
  18. package/dist/_exports/undeploy.js.map +1 -1
  19. package/dist/actions/build/artifact.js +20 -1
  20. package/dist/actions/build/artifact.js.map +1 -1
  21. package/dist/actions/build/configs/artifact.js +10 -50
  22. package/dist/actions/build/configs/artifact.js.map +1 -1
  23. package/dist/actions/build/dashboardConfig/artifact.js +25 -0
  24. package/dist/actions/build/dashboardConfig/artifact.js.map +1 -0
  25. package/dist/actions/build/hotConfigListeners.js +34 -0
  26. package/dist/actions/build/hotConfigListeners.js.map +1 -0
  27. package/dist/actions/build/vite/optimize-deps.js +2 -1
  28. package/dist/actions/build/vite/optimize-deps.js.map +1 -1
  29. package/dist/actions/build/vite/plugins/plugin-sanity-extension-artifacts.js +3 -1
  30. package/dist/actions/build/vite/plugins/plugin-sanity-extension-artifacts.js.map +1 -1
  31. package/dist/actions/deploy/deployConfig.js +9 -7
  32. package/dist/actions/deploy/deployConfig.js.map +1 -1
  33. package/dist/actions/deploy/deployPayload.js.map +1 -1
  34. package/dist/actions/deploy/deploySummary.js +24 -5
  35. package/dist/actions/deploy/deploySummary.js.map +1 -1
  36. package/dist/actions/deploy/deployWorkbenchApp.js +31 -13
  37. package/dist/actions/deploy/deployWorkbenchApp.js.map +1 -1
  38. package/dist/actions/deploy/uploadDashboardConfig.js +34 -0
  39. package/dist/actions/deploy/uploadDashboardConfig.js.map +1 -0
  40. package/dist/actions/dev/deriveConfigs.js +17 -13
  41. package/dist/actions/dev/deriveConfigs.js.map +1 -1
  42. package/dist/actions/dev/registry.js +34 -20
  43. package/dist/actions/dev/registry.js.map +1 -1
  44. package/dist/actions/dev/startDevServerRegistration.js +20 -11
  45. package/dist/actions/dev/startDevServerRegistration.js.map +1 -1
  46. package/dist/actions/dev/startWorkbenchDev.js +2 -2
  47. package/dist/actions/dev/startWorkbenchDev.js.map +1 -1
  48. package/dist/actions/preview/serveBuiltApplication.js +9 -7
  49. package/dist/actions/preview/serveBuiltApplication.js.map +1 -1
  50. package/dist/actions/preview/startWorkbenchPreview.js +52 -19
  51. package/dist/actions/preview/startWorkbenchPreview.js.map +1 -1
  52. package/dist/actions/undeploy/workbenchUndeployAdapter.js +50 -3
  53. package/dist/actions/undeploy/workbenchUndeployAdapter.js.map +1 -1
  54. package/dist/contract.js +20 -3
  55. package/dist/contract.js.map +1 -1
  56. package/dist/dashboardConfig.js +5 -0
  57. package/dist/dashboardConfig.js.map +1 -0
  58. package/dist/defineApp.js +25 -2
  59. package/dist/defineApp.js.map +1 -1
  60. package/dist/deriveInterfaces.js +24 -13
  61. package/dist/deriveInterfaces.js.map +1 -1
  62. package/dist/readAppIcon.js +3 -3
  63. package/dist/readAppIcon.js.map +1 -1
  64. package/dist/resolveWorkbenchApp.js +3 -2
  65. package/dist/resolveWorkbenchApp.js.map +1 -1
  66. package/dist/resolveWorkbenchConfig.js +11 -16
  67. package/dist/resolveWorkbenchConfig.js.map +1 -1
  68. package/dist/services/applications.js +12 -1
  69. package/dist/services/applications.js.map +1 -1
  70. package/dist/services/dashboard-configs.js +54 -0
  71. package/dist/services/dashboard-configs.js.map +1 -0
  72. package/package.json +8 -8
  73. package/dist/_exports/contract-WrU3aOYd.d.ts +0 -187
  74. package/dist/_exports/defineApp-9ppP3UQR.d.ts +0 -175
@@ -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 iconPath = isApp && isWorkbenchApp(cliConfig.app) ? cliConfig.app.icon : undefined\n const icon = iconPath ? await readAppIcon(workDir, iconPath) : undefined\n const servedIcon = icon && {...icon, path: `/${toUrlPath(workDir, icon.file)}`}\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 icon: servedIcon,\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, {isApp})\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: servedIcon && `http://${remote.host}:${remote.port}${servedIcon.path}`,\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","iconPath","app","icon","undefined","servedIcon","file","close","closers","installSignalHandlers","workbench","push","remotePort","workbenchAvailable","workbenchPort","remote","catch","err","dashboardAppPath","configPath","Error","inlinedId","readInlinedAppId","configs","id","interfaces","registration","applicationId","deployment","appId","host","manifest","iconUrl","port","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;AACrD,SACEC,aAAa,EAEbC,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,qFAAqF;IACrF,MAAMY,WAAWL,SAASrB,eAAeiB,UAAUU,GAAG,IAAIV,UAAUU,GAAG,CAACC,IAAI,GAAGC;IAC/E,MAAMD,OAAOF,WAAW,MAAMxB,YAAYuB,SAASC,YAAYG;IAC/D,MAAMC,aAAaF,QAAQ;QAAC,GAAGA,IAAI;QAAEjC,MAAM,CAAC,CAAC,EA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AAOC,WAAW;YACzCH,MAAMlB,OAAOkB,IAAI;YACjBI,WAAW7C,WAAW8C,KAAKD;YAC3B,GAAGrD,iBAAiB0B,UAAU;YAC9B6B,MAAM3C,QAAQ,YAAY;YAC1BI;QACF;QACAQ,QAAQG,IAAI,CAAC,UAAYe,aAAac,OAAO;QAC7CtB,mBAAmBnC,cAAc;YAC/ByC;YACAC;YACAgB,MAAM/B,UAAU+B,IAAI;YACpBF,MAAM3C,QAAQ,YAAY;QAC5B;IACF,EAAE,OAAOqB,KAAK;QACZ,MAAMV;QACN,MAAMU;IACR;IAEA,IAAIP,UAAUG,kBAAkB,EAAE;QAChC,MAAM6B,SAAS,CAAC,OAAO,EAAE7D,cAAc6B,UAAUhB,QAAQ,EAAE,CAAC,EAAEgB,UAAUI,aAAa,GAAGI,oBAAoB,IAAI;QAChHpB,OAAO6C,GAAG,CAAC,CAAC,oCAAoC,EAAExE,UAAU;YAAC;YAAQ;SAAY,EAAEuE,SAAS;IAC9F,OAAO;QACL,MAAME,YAAY,CAAC,OAAO,EAAE/D,cAAckC,OAAOe,IAAI,EAAE,CAAC,EAAEf,OAAOkB,IAAI,EAAE;QACvEnC,OAAO6C,GAAG,CAAC,CAAC,iBAAiB,EAAExE,UAAU;YAAC;YAAQ;SAAY,EAAEyE,YAAY;IAC9E;IAEAnC;IAEA,OAAO;QAACF;IAAK;AACf;AAEA,wEAAwE,GACxE,eAAee,iBAAiBzB,MAAc;IAC5C,IAAI;QACF,OAAO,AAAC,CAAA,MAAM5B,SAASC,KAAK2E,IAAI,CAAChD,QAAQvB,qBAAqB,OAAM,EAAGwE,IAAI,MAAM1C;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,eA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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 — the media library — deletes its
10
- * installation's config snapshots instead. The two are severed at the source,
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: appType,
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;AAC9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,OAAOoB,YAAYH,EAAE;gBAAEK;gBAAUnB;gBAAMoB;YAAK;YACtDD;YACAG,SAASJ;YACTK,OAAON,YAAYM,KAAK;YACxBvB;YACAwB,KAAKpC,kBAAkB;gBAAC,GAAG6B,WAAW;gBAAEjB;YAAI;YAC5CoB;QACF;QACApB,MAAM;IACR;AACF;AAEA,eAAeO,oBAAoB,EACjCT,MAAM,EACNC,cAAc,EAIf;IAIC,MAAM,EAAC0B,OAAO,EAAC,GAAG3B;IAClB,IAAI,CAACC,gBAAgB;QACnB,MAAM,IAAIK,MACR;IAEJ;IAEA,MAAMF,iBAAiB,MAAMV,sBAAsB;QAACiC;QAAS1B;IAAc;IAC3E,IAAI,CAACG,gBAAgB;QACnB,OAAO;YACLM,YAAY;gBACVO,SAAS,CAAC,WAAW,EAAEU,QAAQ,iCAAiC,EAAE1B,eAAe,CAAC,CAAC;gBACnFC,MAAM;YACR;QACF;IACF;IAEA,MAAMa,UAAU,MAAMtB,YAAYW;IAClC,IAAIW,QAAQa,MAAM,KAAK,GAAG;QACxB,OAAO;YACLxB;YACAM,YAAY;gBACVO,SAAS,CAAC,4BAA4B,EAAEU,QAAQ,cAAc,CAAC;gBAC/DzB,MAAM;YACR;QACF;IACF;IAEA,OAAO;QACLE;QACAM,YAAY;YACVE,QAAQ;gBACNG;gBACAF,SAAS;gBACTG,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","summary","title","url","length","dashboard"],"mappings":"AAYA,SACEA,iBAAiB,EACjBC,cAAc,EACdC,iBAAiB,EACjBC,eAAe,QACV,iCAAgC;AACvC,SAAQC,eAAe,EAAEC,wBAAwB,QAAO,sCAAqC;AAC7F,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,EAA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,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'
@@ -42,7 +44,8 @@ const PanelDockSchema = z.object({
42
44
  order: z.optional(z.number())
43
45
  });
44
46
  /** @internal */ export const ViewPlacementMetadataSchema = z.object({
45
- dock: DockSchema
47
+ dock: z.optional(DockSchema),
48
+ icon: z.optional(z.string())
46
49
  });
47
50
  /**
48
51
  * A tile's interface metadata: its footprint `size` and an optional `order`
@@ -112,7 +115,8 @@ function interfaceDeclarationFields(kind) {
112
115
  const PanelViewSchema = z.object({
113
116
  surface: z.literal('panel'),
114
117
  ...interfaceDeclarationFields('View'),
115
- dock: z.optional(PanelDockSchema)
118
+ dock: z.optional(PanelDockSchema),
119
+ icon: z.optional(z.string())
116
120
  });
117
121
  /** @public */ export function definePanelView(view) {
118
122
  return {
@@ -123,7 +127,8 @@ const PanelViewSchema = z.object({
123
127
  const WindowViewSchema = z.object({
124
128
  surface: z.literal('window'),
125
129
  ...interfaceDeclarationFields('View'),
126
- dock: z.optional(DockSchema)
130
+ dock: z.optional(DockSchema),
131
+ icon: z.optional(z.string())
127
132
  });
128
133
  /** @public */ export function defineWindowView(view) {
129
134
  return {
@@ -186,12 +191,24 @@ const MediaLibraryConfigSchema = z.object({
186
191
  appType: z.literal('media-library'),
187
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'))
188
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
+ });
189
198
  /**
190
199
  * A workbench config's built value, keyed by `appType`; deploys as a versioned
191
200
  * snapshot, not an interface.
192
201
  * @internal
193
202
  */ export const ConfigSchema = z.discriminatedUnion('appType', [
203
+ DashboardConfigSchema,
194
204
  MediaLibraryConfigSchema
195
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
+ }
196
213
 
197
214
  //# sourceMappingURL=contract.js.map
@@ -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({dock: DockSchema})\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})\n\n/** @public */\nexport type PanelView = z.output<typeof PanelViewSchema>\n\n/** @public */\nexport type DefinePanelViewInput = Omit<PanelView, 'surface'>\n\n/** @public */\nexport function definePanelView(view: DefinePanelViewInput): PanelView {\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})\n\n/** @public */\nexport type WindowView = z.output<typeof WindowViewSchema>\n\n/** @public */\nexport type DefineWindowViewInput = Omit<WindowView, 'surface'>\n\n/** @public */\nexport function defineWindowView(view: DefineWindowViewInput): WindowView {\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 AssetSourceView = z.output<typeof AssetSourceViewSchema>\n\n/** @public */\nexport type DefineAssetSourceViewInput = Omit<AssetSourceView, 'surface'>\n\n/** @public */\nexport function defineAssetSourceView(view: DefineAssetSourceViewInput): AssetSourceView {\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 TileView = z.output<typeof TileViewSchema>\n\n/** @public */\nexport type DefineTileViewInput = Omit<TileView, 'surface'>\n\n/** @public */\nexport function defineTileView(view: DefineTileViewInput): TileView {\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 WebWorker = z.output<typeof WebWorkerSchema>\n\n/** @public */\nexport type DefineWebWorkerInput = Omit<WebWorker, 'type'>\n\n/** @public */\nexport function defineWebWorker(webWorker: DefineWebWorkerInput): WebWorker {\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","TileInterfaceMetadataSchema","size","INTERFACE_CONTRACT_VERSIONS","worker","interfaceContractVersion","kind","String","interfaceModuleId","name","Error","extensionDeclarationFields","pattern","string","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;IAACO,MAAMR;AAAU,GAAE;AAKvE;;;;;CAKC,GACD,OAAO,MAAMS,8BAA8BtB,EAAEc,MAAM,CAAC;IAClDG,OAAOjB,EAAEgB,QAAQ,CAAChB,EAAEkB,MAAM;IAC1BK,MAAMb;AACR,GAAE;AAKF;;;;CAIC,GACD,MA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Q;IACtC2B,QAAQ3D,EAAEgB,QAAQ,CAAChB,EAAE4D,OAAO;IAC5BrB,OAAOvC,EAAEkC,MAAM;AACjB;AAEA;;;CAGC,GACD,OAAO,MAAM2B,2BAA2B,sBAAqB;AAE7D,yEAAyE;AACzE,MAAMC,2BAA2B9D,EAAEc,MAAM,CAAC;IACxCiD,SAAS/D,EAAE0C,OAAO,CAAC;IACnBsB,QAAQhE,EACLiE,KAAK,CAACP,yBACNvB,KAAK,CACJnC,EAAEkE,MAAM,CACN,CAACF,SAAW,IAAIG,IAAIH,OAAOI,GAAG,CAAC,CAACC,QAAUA,MAAMvC,IAAI,GAAGP,IAAI,KAAKyC,OAAOM,MAAM,EAC7E;AAGR;AAEA;;;;CAIC,GACD,OAAO,MAAMC,eAAevE,EAAEoD,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;IAC7BC,cAAc;QAAC;KAAe;IAC9BC,OAAO;QAAC;QAAS;KAAQ;IACzBC,MAAM;QAAC;KAAO;IACdC,QAAQ,EAAE;AACZ,EAAsD;AAKtD;;;;;;CAMC,GACD,OAAO,MAAMC,iBAAiBZ,EAAEa,IAAI,CAAC;IAAC;IAAS;IAAS;CAAS,EAAC;AAclE,MAAMC,kBAAkBd,EAAEa,IAAI,CAAC;IAAC;IAAU;CAAe;AAKzD,cAAc,GACd,OAAO,MAAME,aAAaf,EAAEgB,MAAM,CAAC;IACjCC,OAAOjB,EAAEkB,QAAQ,CAACJ;IA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,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,5 @@
1
+ export function defineDashboardConfig(config) {
2
+ return config;
3
+ }
4
+
5
+ //# sourceMappingURL=dashboardConfig.js.map
@@ -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
- /** User-facing app title. Wins over studio.config.ts title on merge. */ title: z.string(),
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
@@ -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,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,kBACA;IAGN,sEAAsE,GACtEsB,OAAOvB,EAAEc,MAAM;IACf,mEAAmE,GACnEU,OAAOxB,EAAEW,QAAQ,CAACX,EAAEyB,KAAK,CAACtB,4BAA4B;IACtD,yEAAyE,GAC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AY;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,uBAAu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QlC,MAAMkC,MAAM,IAAI,EAAE;QAAE1C,gBAAgBQ,MAAMR,cAAc;IAAA,GAC3FsC,kBACA;QAACJ,cAAc;QAAOC,YAAY;QAAOC,OAAO;QAAMC,UAAU;IAAK;AAEzE;AAEA,OAAO,SAASM,gBAAgBnC,KAA2B;IACzD,OAAOwB,OAAOC,cAAc,CAC1B;QACEQ,SAAS;QACTzC,gBAAgBQ,MAAMR,cAAc;QACpC4C,KAAKpC,MAAMoC,GAAG;IAChB,GACAN,kBACA;QAACJ,cAAc;QAAOC,YAAY;QAAOC,OAAO;QAAMC,UAAU;IAAK;AAEzE"}
@@ -1,12 +1,13 @@
1
1
  import { FEDERATION_FILE_NAME, RUNTIME_DIR } from './actions/build/vite/constants.js';
2
2
  import { interfaceContractVersion, interfaceModuleId } from './contract.js';
3
- import { isWorkbenchApp } from './defineApp.js';
3
+ import { isWorkbenchApp, resolveAppTitle } from './defineApp.js';
4
4
  /** What a studio exposes as `./App` — the generated entry that renders `sanity.config.ts`. */ const GENERATED_ENTRY = `./${RUNTIME_DIR}/${FEDERATION_FILE_NAME}.jsx`;
5
5
  /**
6
6
  * `appTitle` titles the window where a deploy resolved one through `--title`;
7
- * dev takes it from the config.
7
+ * dev takes it from the config. `iconUrl` resolves an interface's `icon` path to
8
+ * the `metadata.icon` a local server serves it at; a deploy uploads it instead.
8
9
  * @internal
9
- */ export function deriveInterfaces(app, { appTitle, isApp }) {
10
+ */ export function deriveInterfaces(app, { appTitle, iconUrl, isApp }) {
10
11
  if (!isWorkbenchApp(app)) return [];
11
12
  // The schema rejects a *declared* studio with an `entry`; `isApp` is resolved
12
13
  // from the project, so a detected one only fails here.
@@ -25,18 +26,25 @@ import { isWorkbenchApp } from './defineApp.js';
25
26
  title: declaration.title,
26
27
  version: interfaceContractVersion(kind)
27
28
  });
28
- const placementMetadata = (dock, surface = 'window')=>{
29
+ const placementMetadata = (dock, surface = 'window', iconPath)=>{
29
30
  const group = surface === 'panel' ? undefined : dock?.group ?? app.dock?.group;
30
31
  const order = dock?.order ?? app.dock?.order;
31
- if (group === undefined && order === undefined) return null;
32
+ const hasDock = group !== undefined || order !== undefined;
33
+ const icon = iconPath && iconUrl?.(iconPath);
34
+ if (!hasDock && !icon) return null;
32
35
  return {
33
- dock: {
34
- ...group === undefined ? {} : {
35
- group
36
- },
37
- ...order === undefined ? {} : {
38
- order
36
+ ...hasDock && {
37
+ dock: {
38
+ ...group === undefined ? {} : {
39
+ group
40
+ },
41
+ ...order === undefined ? {} : {
42
+ order
43
+ }
39
44
  }
45
+ },
46
+ ...icon && {
47
+ icon
40
48
  }
41
49
  };
42
50
  };
@@ -57,7 +65,10 @@ import { isWorkbenchApp } from './defineApp.js';
57
65
  if (view.surface === 'panel' || view.surface === 'window') {
58
66
  return {
59
67
  ...shared(view.surface, view),
60
- metadata: placementMetadata(view.dock, view.surface),
68
+ ...view.icon && !iconUrl && {
69
+ icon: view.icon
70
+ },
71
+ metadata: placementMetadata(view.dock, view.surface, view.icon),
61
72
  surface: view.surface
62
73
  };
63
74
  }
@@ -77,7 +88,7 @@ import { isWorkbenchApp } from './defineApp.js';
77
88
  ...shared('window', {
78
89
  name: appName,
79
90
  src: entry,
80
- title: appTitle ?? app.title
91
+ title: appTitle ?? resolveAppTitle(app)
81
92
  }),
82
93
  metadata: placementMetadata(),
83
94
  surface: 'window'
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deriveInterfaces.ts"],"sourcesContent":["import {type CliConfig} from '@sanity/cli-core'\n\nimport {FEDERATION_FILE_NAME, RUNTIME_DIR} from './actions/build/vite/constants.js'\nimport {\n type Dock,\n interfaceContractVersion,\n type InterfaceKind,\n interfaceModuleId,\n type PanelView,\n type TileInterfaceMetadata,\n type ViewPlacementMetadata,\n type WindowView,\n} from './contract.js'\nimport {isWorkbenchApp} from './defineApp.js'\n\n/** What a studio exposes as `./App` — the generated entry that renders `sanity.config.ts`. */\nconst GENERATED_ENTRY = `./${RUNTIME_DIR}/${FEDERATION_FILE_NAME}.jsx`\n\ninterface DerivedInterfaceBase {\n /** CLI-minted for a local interface; a deployed one gets its id from Brett. */\n id: string\n moduleId: string\n name: string\n src: string\n title: string\n\n version: string\n}\n\n/** @internal */\nexport type DerivedInterface =\n | (DerivedInterfaceBase & {metadata: null; surface: 'asset_source'})\n | (DerivedInterfaceBase & {metadata: null; type: 'worker'})\n | (DerivedInterfaceBase & {metadata: TileInterfaceMetadata; surface: 'tile'})\n | (DerivedInterfaceBase & {metadata: ViewPlacementMetadata | null; surface: 'panel'})\n | (DerivedInterfaceBase & {metadata: ViewPlacementMetadata | null; surface: 'window'})\n\n/**\n * `appTitle` titles the window where a deploy resolved one through `--title`;\n * dev takes it from the config.\n * @internal\n */\nexport function deriveInterfaces(\n app: CliConfig['app'],\n {appTitle, isApp}: {appTitle?: string; isApp: boolean},\n): DerivedInterface[] {\n if (!isWorkbenchApp(app)) return []\n\n // The schema rejects a *declared* studio with an `entry`; `isApp` is resolved\n // from the project, so a detected one only fails here.\n if (!isApp && app.entry !== undefined) {\n throw new Error('App views for studios are not implemented yet')\n }\n const entry = isApp ? app.entry : GENERATED_ENTRY\n\n // Identity, not address: interface ids and the window name key on `name`\n // (which defaults to `slug`, so existing apps derive byte-identical ids).\n const appName = app.name ?? app.slug\n\n const shared = (\n kind: InterfaceKind,\n declaration: {name: string; src: string; title: string},\n ) => ({\n id: `${appName}-${kind}-${declaration.name}`,\n moduleId: interfaceModuleId(kind, declaration.name),\n name: declaration.name,\n src: declaration.src,\n title: declaration.title,\n version: interfaceContractVersion(kind),\n })\n\n const placementMetadata = (\n dock?: Dock,\n surface: (PanelView | WindowView)['surface'] = 'window',\n ): ViewPlacementMetadata | null => {\n const group = surface === 'panel' ? undefined : (dock?.group ?? app.dock?.group)\n const order = dock?.order ?? app.dock?.order\n if (group === undefined && order === undefined) return null\n return {\n dock: {\n ...(group === undefined ? {} : {group}),\n ...(order === undefined ? {} : {order}),\n },\n }\n }\n\n return [\n ...(app.views ?? []).map((view): DerivedInterface => {\n if (view.surface === 'tile') {\n return {\n ...shared(view.surface, view),\n metadata:\n view.order === undefined ? {size: view.size} : {order: view.order, size: view.size},\n surface: view.surface,\n }\n }\n if (view.surface === 'panel' || view.surface === 'window') {\n return {\n ...shared(view.surface, view),\n metadata: placementMetadata(view.dock, view.surface),\n surface: view.surface,\n }\n }\n return {...shared(view.surface, view), metadata: null, surface: view.surface}\n }),\n ...(app.webWorkers ?? []).map((webWorker): DerivedInterface => ({\n ...shared('worker', webWorker),\n metadata: null,\n type: 'worker',\n })),\n ...(entry === undefined\n ? []\n : [\n {\n ...shared('window', {name: appName, src: entry, title: appTitle ?? app.title}),\n metadata: placementMetadata(),\n surface: 'window' as const,\n },\n ]),\n ]\n}\n"],"names":["FEDERATION_FILE_NAME","RUNTIME_DIR","interfaceContractVersion","interfaceModuleId","isWorkbenchApp","GENERATED_ENTRY","deriveInterfaces","app","appTitle","isApp","entry","undefined","Error","appName","name","slug","shared","kind","declaration","id","moduleId","src","title","version","placementMetadata","dock","surface","group","order","views","map","view","metadata","size","webWorkers","webWorker","type"],"mappings":"AAEA,SAAQA,oBAAoB,EAAEC,WAAW,QAAO,oCAAmC;AACnF,SAEEC,wBAAwB,EAExBC,iBAAiB,QAKZ,gBAAe;AACtB,SAAQC,cAAc,QAAO,iBAAgB;AAE7C,4FAA4F,GAC5F,MAAMC,kBAAkB,CAAC,EAAE,EAAEJ,YAAY,CAAC,EAAED,qBAAqB,IAAI,CAAC;AAqBtE;;;;CAIC,GACD,OAAO,SAASM,iBACdC,GAAqB,EACrB,EAACC,QAAQ,EAAEC,KAAK,EAAsC;IAEtD,IAAI,CAACL,eAAeG,MAAM,OAAO,EAAE;IAEnC,8EAA8E;IAC9E,uDAAuD;IACvD,IAAI,CAACE,SAASF,IAAIG,KAAK,KAAKC,WAAW;QACrC,MAAM,IAAIC,MAAM;IAClB;IACA,MAAMF,QAAQD,QAAQF,IAAIG,KAAK,GAAGL;IAElC,yEAAyE;IACzE,0EAA0E;IAC1E,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EK,KAAK;oBAC7BC,UAAUR,kBAAkBO,KAAKN,IAAI,EAAEM,KAAKL,OAAO;oBACnDA,SAASK,KAAKL,OAAO;gBACvB;YACF;YACA,OAAO;gBAAC,GAAGV,OAAOe,KAAKL,OAAO,EAAEK,KAAK;gBAAEC,UAAU;gBAAMN,SAASK,KAAKL,OAAO;YAAA;QAC9E;WACG,AAACnB,CAAAA,IAAI2B,UAAU,IAAI,EAAE,AAAD,EAAGJ,GAAG,CAAC,CAACK,YAAiC,CAAA;gBAC9D,GAAGnB,OAAO,UAAUmB,UAAU;gBAC9BH,UAAU;gBACVI,MAAM;YACR,CAAA;WACI1B,UAAUC,YACV,EAAE,GACF;YACE;gBACE,GAAGK,OAAO,UAAU;oBAACF,MAAMD;oBAASQ,KAAKX;oBAAOY,OAAOd,YAAYD,IAAIe,KAAK;gBAAA,EAAE;gBAC9EU,UAAUR;gBACVE,SAAS;YACX;SACD;KACN;AACH"}
1
+ {"version":3,"sources":["../src/deriveInterfaces.ts"],"sourcesContent":["import {type CliConfig} from '@sanity/cli-core'\n\nimport {FEDERATION_FILE_NAME, RUNTIME_DIR} from './actions/build/vite/constants.js'\nimport {\n type Dock,\n interfaceContractVersion,\n type InterfaceKind,\n interfaceModuleId,\n type PanelViewDeclaration,\n type TileInterfaceMetadata,\n type ViewPlacementMetadata,\n type WindowViewDeclaration,\n} from './contract.js'\nimport {isWorkbenchApp, resolveAppTitle} from './defineApp.js'\n\n/** What a studio exposes as `./App` — the generated entry that renders `sanity.config.ts`. */\nconst GENERATED_ENTRY = `./${RUNTIME_DIR}/${FEDERATION_FILE_NAME}.jsx`\n\ninterface DerivedInterfaceBase {\n /** CLI-minted for a local interface; a deployed one gets its id from Brett. */\n id: string\n moduleId: string\n name: string\n src: string\n title: string\n\n version: string\n}\n\n/** @internal */\nexport type DerivedInterface =\n | (DerivedInterfaceBase & {\n icon?: string\n metadata: ViewPlacementMetadata | null\n surface: 'panel'\n })\n | (DerivedInterfaceBase & {\n icon?: string\n metadata: ViewPlacementMetadata | null\n surface: 'window'\n })\n | (DerivedInterfaceBase & {metadata: null; surface: 'asset_source'})\n | (DerivedInterfaceBase & {metadata: null; type: 'worker'})\n | (DerivedInterfaceBase & {metadata: TileInterfaceMetadata; surface: 'tile'})\n\n/**\n * `appTitle` titles the window where a deploy resolved one through `--title`;\n * dev takes it from the config. `iconUrl` resolves an interface's `icon` path to\n * the `metadata.icon` a local server serves it at; a deploy uploads it instead.\n * @internal\n */\nexport function deriveInterfaces(\n app: CliConfig['app'],\n {\n appTitle,\n iconUrl,\n isApp,\n }: {appTitle?: string; iconUrl?: (iconPath: string) => string; isApp: boolean},\n): DerivedInterface[] {\n if (!isWorkbenchApp(app)) return []\n\n // The schema rejects a *declared* studio with an `entry`; `isApp` is resolved\n // from the project, so a detected one only fails here.\n if (!isApp && app.entry !== undefined) {\n throw new Error('App views for studios are not implemented yet')\n }\n const entry = isApp ? app.entry : GENERATED_ENTRY\n\n // Identity, not address: interface ids and the window name key on `name`\n // (which defaults to `slug`, so existing apps derive byte-identical ids).\n const appName = app.name ?? app.slug\n\n const shared = (\n kind: InterfaceKind,\n declaration: {name: string; src: string; title: string},\n ) => ({\n id: `${appName}-${kind}-${declaration.name}`,\n moduleId: interfaceModuleId(kind, declaration.name),\n name: declaration.name,\n src: declaration.src,\n title: declaration.title,\n version: interfaceContractVersion(kind),\n })\n\n const placementMetadata = (\n dock?: Dock,\n surface: (PanelViewDeclaration | WindowViewDeclaration)['surface'] = 'window',\n iconPath?: string,\n ): ViewPlacementMetadata | null => {\n const group = surface === 'panel' ? undefined : (dock?.group ?? app.dock?.group)\n const order = dock?.order ?? app.dock?.order\n const hasDock = group !== undefined || order !== undefined\n const icon = iconPath && iconUrl?.(iconPath)\n if (!hasDock && !icon) return null\n return {\n ...(hasDock && {\n dock: {\n ...(group === undefined ? {} : {group}),\n ...(order === undefined ? {} : {order}),\n },\n }),\n ...(icon && {icon}),\n }\n }\n\n return [\n ...(app.views ?? []).map((view): DerivedInterface => {\n if (view.surface === 'tile') {\n return {\n ...shared(view.surface, view),\n metadata:\n view.order === undefined ? {size: view.size} : {order: view.order, size: view.size},\n surface: view.surface,\n }\n }\n if (view.surface === 'panel' || view.surface === 'window') {\n return {\n ...shared(view.surface, view),\n ...(view.icon && !iconUrl && {icon: view.icon}),\n metadata: placementMetadata(view.dock, view.surface, view.icon),\n surface: view.surface,\n }\n }\n return {...shared(view.surface, view), metadata: null, surface: view.surface}\n }),\n ...(app.webWorkers ?? []).map((webWorker): DerivedInterface => ({\n ...shared('worker', webWorker),\n metadata: null,\n type: 'worker',\n })),\n ...(entry === undefined\n ? []\n : [\n {\n ...shared('window', {\n name: appName,\n src: entry,\n title: appTitle ?? resolveAppTitle(app),\n }),\n metadata: placementMetadata(),\n surface: 'window' as const,\n },\n ]),\n ]\n}\n"],"names":["FEDERATION_FILE_NAME","RUNTIME_DIR","interfaceContractVersion","interfaceModuleId","isWorkbenchApp","resolveAppTitle","GENERATED_ENTRY","deriveInterfaces","app","appTitle","iconUrl","isApp","entry","undefined","Error","appName","name","slug","shared","kind","declaration","id","moduleId","src","title","version","placementMetadata","dock","surface","iconPath","group","order","hasDock","icon","views","map","view","metadata","size","webWorkers","webWorker","type"],"mappings":"AAEA,SAAQA,oBAAoB,EAAEC,WAAW,QAAO,oCAAmC;AACnF,SAEEC,wBAAwB,EAExBC,iBAAiB,QAKZ,gBAAe;AACtB,SAAQC,cAAc,EAAEC,eAAe,QAAO,iBAAgB;AAE9D,4FAA4F,GAC5F,MAAMC,kBAAkB,CAAC,EAAE,EAAEL,YAAY,CAAC,EAAED,qBAAqB,IAAI,CAAC;AA6BtE;;;;;CAKC,GACD,OAAO,SAASO,iBACdC,GAAqB,EACrB,EACEC,QAAQ,EACRC,OAAO,EACPC,KAAK,EACuE;IAE9E,IAAI,CAACP,eAAeI,MAAM,OAAO,EAAE;IAEnC,8EAA8E;IAC9E,uDAAuD;IACvD,IAAI,CAACG,SAASH,IAAII,KAAK,KAAKC,WAA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