@sanity/workbench-cli 2.19.1 → 2.20.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 (29) hide show
  1. package/dist/_exports/build.d.ts +1 -1
  2. package/dist/_exports/{contract-WrU3aOYd.d.ts → contract-BeAds4Yi.d.ts} +21 -17
  3. package/dist/_exports/{defineApp-9ppP3UQR.d.ts → defineApp-DSXAAr3V.d.ts} +3 -1
  4. package/dist/_exports/deploy.d.ts +7 -6
  5. package/dist/_exports/dev.d.ts +1 -1
  6. package/dist/_exports/index.d.ts +3 -3
  7. package/dist/_exports/index.js.map +1 -1
  8. package/dist/_exports/preview.d.ts +1 -1
  9. package/dist/_exports/{registry-DZWnj09G.d.ts → registry-BI8kZVpy.d.ts} +8 -6
  10. package/dist/_exports/{resolveWorkbenchConfig-_iD6fVUH.d.ts → resolveWorkbenchConfig-Eex64aAA.d.ts} +3 -3
  11. package/dist/_exports/{summarizeInterfaces-AM-QbtIA.d.ts → summarizeInterfaces-BKIMEFzw.d.ts} +3 -3
  12. package/dist/_exports/undeploy.d.ts +2 -2
  13. package/dist/actions/deploy/deployWorkbenchApp.js +31 -13
  14. package/dist/actions/deploy/deployWorkbenchApp.js.map +1 -1
  15. package/dist/actions/dev/startDevServerRegistration.js +11 -6
  16. package/dist/actions/dev/startDevServerRegistration.js.map +1 -1
  17. package/dist/actions/preview/serveBuiltApplication.js +9 -7
  18. package/dist/actions/preview/serveBuiltApplication.js.map +1 -1
  19. package/dist/actions/preview/startWorkbenchPreview.js +13 -8
  20. package/dist/actions/preview/startWorkbenchPreview.js.map +1 -1
  21. package/dist/contract.js +6 -3
  22. package/dist/contract.js.map +1 -1
  23. package/dist/deriveInterfaces.js +22 -11
  24. package/dist/deriveInterfaces.js.map +1 -1
  25. package/dist/readAppIcon.js +3 -3
  26. package/dist/readAppIcon.js.map +1 -1
  27. package/dist/services/applications.js +11 -0
  28. package/dist/services/applications.js.map +1 -1
  29. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { a as resolveAppEntry, i as WorkbenchExposes, n as resolveWorkbenchConfig, o as resolveWorkbenchApp, r as ResolvedWorkbenchApp, t as ResolvedMediaLibraryConfig } from "./resolveWorkbenchConfig-_iD6fVUH.js";
1
+ import { a as resolveAppEntry, i as WorkbenchExposes, n as resolveWorkbenchConfig, o as resolveWorkbenchApp, r as ResolvedWorkbenchApp, t as ResolvedMediaLibraryConfig } from "./resolveWorkbenchConfig-Eex64aAA.js";
2
2
  import { InlineConfig, PluginOption } from "vite";
3
3
  /**
4
4
  * Resolves to the parsed federation manifest in `sourceDir`. A workbench build
@@ -51,17 +51,18 @@ declare const PanelViewSchema: z.ZodMiniObject<{
51
51
  dock: z.ZodMiniOptional<z.ZodMiniObject<{
52
52
  order: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
53
53
  }, z.core.$strip>>;
54
+ icon: z.ZodMiniOptional<z.ZodMiniString<string>>;
54
55
  title: z.ZodMiniString<string>;
55
56
  name: z.ZodMiniString<string>;
56
57
  src: z.ZodMiniString<string>;
57
58
  surface: z.ZodMiniLiteral<"panel">;
58
59
  }, z.core.$strip>;
59
60
  /** @public */
60
- type PanelView = z.output<typeof PanelViewSchema>;
61
+ type PanelViewDeclaration = z.output<typeof PanelViewSchema>;
61
62
  /** @public */
62
- type DefinePanelViewInput = Omit<PanelView, 'surface'>;
63
+ type DefinePanelViewInput = Omit<PanelViewDeclaration, 'surface'>;
63
64
  /** @public */
64
- declare function definePanelView(view: DefinePanelViewInput): PanelView;
65
+ declare function definePanelView(view: DefinePanelViewInput): PanelViewDeclaration;
65
66
  declare const WindowViewSchema: z.ZodMiniObject<{
66
67
  dock: z.ZodMiniOptional<z.ZodMiniObject<{
67
68
  group: z.ZodMiniOptional<z.ZodMiniEnum<{
@@ -70,17 +71,18 @@ declare const WindowViewSchema: z.ZodMiniObject<{
70
71
  }>>;
71
72
  order: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
72
73
  }, z.core.$strip>>;
74
+ icon: z.ZodMiniOptional<z.ZodMiniString<string>>;
73
75
  title: z.ZodMiniString<string>;
74
76
  name: z.ZodMiniString<string>;
75
77
  src: z.ZodMiniString<string>;
76
78
  surface: z.ZodMiniLiteral<"window">;
77
79
  }, z.core.$strip>;
78
80
  /** @public */
79
- type WindowView = z.output<typeof WindowViewSchema>;
81
+ type WindowViewDeclaration = z.output<typeof WindowViewSchema>;
80
82
  /** @public */
81
- type DefineWindowViewInput = Omit<WindowView, 'surface'>;
83
+ type DefineWindowViewInput = Omit<WindowViewDeclaration, 'surface'>;
82
84
  /** @public */
83
- declare function defineWindowView(view: DefineWindowViewInput): WindowView;
85
+ declare function defineWindowView(view: DefineWindowViewInput): WindowViewDeclaration;
84
86
  declare const AssetSourceViewSchema: z.ZodMiniObject<{
85
87
  title: z.ZodMiniString<string>;
86
88
  name: z.ZodMiniString<string>;
@@ -88,11 +90,11 @@ declare const AssetSourceViewSchema: z.ZodMiniObject<{
88
90
  surface: z.ZodMiniLiteral<"asset_source">;
89
91
  }, z.core.$strip>;
90
92
  /** @public */
91
- type AssetSourceView = z.output<typeof AssetSourceViewSchema>;
93
+ type AssetSourceViewDeclaration = z.output<typeof AssetSourceViewSchema>;
92
94
  /** @public */
93
- type DefineAssetSourceViewInput = Omit<AssetSourceView, 'surface'>;
95
+ type DefineAssetSourceViewInput = Omit<AssetSourceViewDeclaration, 'surface'>;
94
96
  /** @public */
95
- declare function defineAssetSourceView(view: DefineAssetSourceViewInput): AssetSourceView;
97
+ declare function defineAssetSourceView(view: DefineAssetSourceViewInput): AssetSourceViewDeclaration;
96
98
  declare const TileViewSchema: z.ZodMiniObject<{
97
99
  order: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
98
100
  size: z.ZodMiniEnum<{
@@ -106,11 +108,11 @@ declare const TileViewSchema: z.ZodMiniObject<{
106
108
  surface: z.ZodMiniLiteral<"tile">;
107
109
  }, z.core.$strip>;
108
110
  /** @public */
109
- type TileView = z.output<typeof TileViewSchema>;
111
+ type TileViewDeclaration = z.output<typeof TileViewSchema>;
110
112
  /** @public */
111
- type DefineTileViewInput = Omit<TileView, 'surface'>;
113
+ type DefineTileViewInput = Omit<TileViewDeclaration, 'surface'>;
112
114
  /** @public */
113
- declare function defineTileView(view: DefineTileViewInput): TileView;
115
+ declare function defineTileView(view: DefineTileViewInput): TileViewDeclaration;
114
116
  /** @internal */
115
117
  declare const InterfaceDeclarationSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
116
118
  dock: z.ZodMiniOptional<z.ZodMiniObject<{
@@ -120,6 +122,7 @@ declare const InterfaceDeclarationSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMini
120
122
  }>>;
121
123
  order: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
122
124
  }, z.core.$strip>>;
125
+ icon: z.ZodMiniOptional<z.ZodMiniString<string>>;
123
126
  title: z.ZodMiniString<string>;
124
127
  name: z.ZodMiniString<string>;
125
128
  src: z.ZodMiniString<string>;
@@ -128,6 +131,7 @@ declare const InterfaceDeclarationSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMini
128
131
  dock: z.ZodMiniOptional<z.ZodMiniObject<{
129
132
  order: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
130
133
  }, z.core.$strip>>;
134
+ icon: z.ZodMiniOptional<z.ZodMiniString<string>>;
131
135
  title: z.ZodMiniString<string>;
132
136
  name: z.ZodMiniString<string>;
133
137
  src: z.ZodMiniString<string>;
@@ -158,11 +162,11 @@ declare const WebWorkerSchema: z.ZodMiniObject<{
158
162
  type: z.ZodMiniLiteral<"worker">;
159
163
  }, z.core.$strip>;
160
164
  /** @public */
161
- type WebWorker = z.output<typeof WebWorkerSchema>;
165
+ type WebWorkerDeclaration = z.output<typeof WebWorkerSchema>;
162
166
  /** @public */
163
- type DefineWebWorkerInput = Omit<WebWorker, 'type'>;
167
+ type DefineWebWorkerInput = Omit<WebWorkerDeclaration, 'type'>;
164
168
  /** @public */
165
- declare function defineWebWorker(webWorker: DefineWebWorkerInput): WebWorker;
169
+ declare function defineWebWorker(webWorker: DefineWebWorkerInput): WebWorkerDeclaration;
166
170
  /**
167
171
  * A workbench config's built value, keyed by `appType`; deploys as a versioned
168
172
  * snapshot, not an interface.
@@ -183,5 +187,5 @@ declare const ConfigSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
183
187
  * @internal
184
188
  */
185
189
  type WorkbenchConfigValue = z.output<typeof ConfigSchema>;
186
- export { defineTileView as C, definePanelView as S, defineWindowView as T, WebWorker as _, DefineWebWorkerInput as a, WorkbenchConfigValue as b, PanelView as c, TileView as d, ViewComponent as f, WEB_WORKER_CONTRACT_VERSION as g, ViewSurface as h, DefineTileViewInput as i, ServiceType as l, ViewDeclaration as m, DefineAssetSourceViewInput as n, DefineWindowViewInput as o, ViewComponentBaseProps as p, DefinePanelViewInput as r, DockGroup as s, AssetSourceView as t, TileSize as u, WebWorkerType as v, defineWebWorker as w, defineAssetSourceView as x, WindowView as y };
187
- //# sourceMappingURL=contract-WrU3aOYd.d.ts.map
190
+ export { defineTileView as C, definePanelView as S, defineWindowView as T, WebWorkerDeclaration as _, DefineWebWorkerInput as a, WorkbenchConfigValue as b, PanelViewDeclaration as c, TileViewDeclaration as d, ViewComponent as f, WEB_WORKER_CONTRACT_VERSION as g, ViewSurface as h, DefineTileViewInput as i, ServiceType as l, ViewDeclaration as m, DefineAssetSourceViewInput as n, DefineWindowViewInput as o, ViewComponentBaseProps as p, DefinePanelViewInput as r, DockGroup as s, AssetSourceViewDeclaration as t, TileSize as u, WebWorkerType as v, defineWebWorker as w, defineAssetSourceView as x, WindowViewDeclaration as y };
191
+ //# sourceMappingURL=contract-BeAds4Yi.d.ts.map
@@ -32,6 +32,7 @@ declare const DefineAppInputSchema: z.ZodMiniObject<{
32
32
  }>>;
33
33
  order: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
34
34
  }, z.core.$strip>>;
35
+ icon: z.ZodMiniOptional<z.ZodMiniString<string>>;
35
36
  title: z.ZodMiniString<string>;
36
37
  name: z.ZodMiniString<string>;
37
38
  src: z.ZodMiniString<string>;
@@ -40,6 +41,7 @@ declare const DefineAppInputSchema: z.ZodMiniObject<{
40
41
  dock: z.ZodMiniOptional<z.ZodMiniObject<{
41
42
  order: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
42
43
  }, z.core.$strip>>;
44
+ icon: z.ZodMiniOptional<z.ZodMiniString<string>>;
43
45
  title: z.ZodMiniString<string>;
44
46
  name: z.ZodMiniString<string>;
45
47
  src: z.ZodMiniString<string>;
@@ -172,4 +174,4 @@ declare function isWorkbenchConfig(app: unknown): app is WorkbenchConfig;
172
174
  */
173
175
  declare function unstable_defineMediaLibrary(input: DefineMediaLibraryInput): WorkbenchConfig;
174
176
  export { WorkbenchApp as a, isWorkbenchApp as c, MediaLibraryField as i, isWorkbenchConfig as l, DefineAppResult as n, WorkbenchConfig as o, DefineMediaLibraryInput as r, defineApplication as s, DefineAppInput as t, unstable_defineMediaLibrary as u };
175
- //# sourceMappingURL=defineApp-9ppP3UQR.d.ts.map
177
+ //# sourceMappingURL=defineApp-DSXAAr3V.d.ts.map
@@ -1,6 +1,6 @@
1
- import "./contract-WrU3aOYd.js";
2
- import { n as resolveWorkbenchConfig, t as ResolvedMediaLibraryConfig } from "./resolveWorkbenchConfig-_iD6fVUH.js";
3
- import { a as DeployableWorkbenchApp, i as summarizeInterfaces, n as DeployedView, o as getWorkbench, r as DeployedWebWorker, t as DeployedInterface } from "./summarizeInterfaces-AM-QbtIA.js";
1
+ import "./contract-BeAds4Yi.js";
2
+ import { n as resolveWorkbenchConfig, t as ResolvedMediaLibraryConfig } from "./resolveWorkbenchConfig-Eex64aAA.js";
3
+ import { a as DeployableWorkbenchApp, i as summarizeInterfaces, n as DeployedView, o as getWorkbench, r as DeployedWebWorker, t as DeployedInterface } from "./summarizeInterfaces-BKIMEFzw.js";
4
4
  import { AppVisibility, CliConfig, Output } from "@sanity/cli-core";
5
5
  import { ImageFile } from "@sanity/cli-core/images";
6
6
  import "node:zlib";
@@ -153,7 +153,7 @@ declare function createStudio(options: {
153
153
  * then sync its mutable metadata (`title`, and `slug`/`visibility` when set)
154
154
  * and its icon from config. The deploy endpoint ignores these, so a redeploy
155
155
  * patches them here alongside the new deployment. No `icon` removes the
156
- * application's icon.
156
+ * application's icon. Each interface's `icon` goes on the interface Brett created for it.
157
157
  *
158
158
  * `onDeployed` fires the instant the deployment is live, before the metadata
159
159
  * sync — so a caller can disarm a create-time rollback that must not delete an
@@ -183,6 +183,7 @@ declare function deployWorkbenchApp(options: {
183
183
  title: string;
184
184
  version: string;
185
185
  visibility?: AppVisibility;
186
+ workDir: string;
186
187
  workspaces?: readonly BrettWorkspace[];
187
188
  }): Promise<void>;
188
189
  /**
@@ -200,7 +201,7 @@ declare function selectWorkbenchAppId({ appId, flags, organizationId, type }: {
200
201
  type: ApplicationType;
201
202
  }): Promise<string | undefined>;
202
203
  /**
203
- * An app's `icon` image, read from its project.
204
+ * An app's or view's `icon` image, read from its project.
204
205
  * @internal
205
206
  */
206
207
  interface AppIcon extends ImageFile {
@@ -208,7 +209,7 @@ interface AppIcon extends ImageFile {
208
209
  file: string;
209
210
  }
210
211
  /**
211
- * Read the image `app.icon` points at. The path is relative to the project
212
+ * Read the image an `icon` path points at. The path is relative to the project
212
213
  * root and must stay inside it.
213
214
  * @internal
214
215
  */
@@ -1,4 +1,4 @@
1
- import { t as DevServerManifest } from "./registry-DZWnj09G.js";
1
+ import { t as DevServerManifest } from "./registry-BI8kZVpy.js";
2
2
  import { ViteDevServer } from "vite";
3
3
  import { CliConfig, Output } from "@sanity/cli-core";
4
4
  /**
@@ -1,5 +1,5 @@
1
- import { C as defineTileView, S as definePanelView, T as defineWindowView, _ as WebWorker, a as DefineWebWorkerInput, c as PanelView, d as TileView, f as ViewComponent, g as WEB_WORKER_CONTRACT_VERSION, h as ViewSurface, i as DefineTileViewInput, l as ServiceType, m as ViewDeclaration, n as DefineAssetSourceViewInput, o as DefineWindowViewInput, p as ViewComponentBaseProps, r as DefinePanelViewInput, s as DockGroup, t as AssetSourceView, u as TileSize, v as WebWorkerType, w as defineWebWorker, x as defineAssetSourceView, y as WindowView } from "./contract-WrU3aOYd.js";
2
- import { a as WorkbenchApp, c as isWorkbenchApp, i as MediaLibraryField, l as isWorkbenchConfig, n as DefineAppResult, o as WorkbenchConfig, r as DefineMediaLibraryInput, s as defineApplication, t as DefineAppInput, u as unstable_defineMediaLibrary } from "./defineApp-9ppP3UQR.js";
1
+ import { C as defineTileView, S as definePanelView, T as defineWindowView, _ as WebWorkerDeclaration, a as DefineWebWorkerInput, c as PanelViewDeclaration, d as TileViewDeclaration, f as ViewComponent, g as WEB_WORKER_CONTRACT_VERSION, h as ViewSurface, i as DefineTileViewInput, l as ServiceType, m as ViewDeclaration, n as DefineAssetSourceViewInput, o as DefineWindowViewInput, p as ViewComponentBaseProps, r as DefinePanelViewInput, s as DockGroup, t as AssetSourceViewDeclaration, u as TileSize, v as WebWorkerType, w as defineWebWorker, x as defineAssetSourceView, y as WindowViewDeclaration } from "./contract-BeAds4Yi.js";
2
+ import { a as WorkbenchApp, c as isWorkbenchApp, i as MediaLibraryField, l as isWorkbenchConfig, n as DefineAppResult, o as WorkbenchConfig, r as DefineMediaLibraryInput, s as defineApplication, t as DefineAppInput, u as unstable_defineMediaLibrary } from "./defineApp-DSXAAr3V.js";
3
3
  import { WebWorkerProps, WebWorkerProps as WebWorkerProps$1 } from "@sanity/sdk/dashboard";
4
4
  import { AssetSourceComponentProps } from "@sanity/types";
5
5
  /** @public */
@@ -177,5 +177,5 @@ type ServiceBus = WebWorkerProps$1['bus'];
177
177
  * @public
178
178
  */
179
179
  type ServiceInfo = WebWorkerProps$1['worker'];
180
- export { type AssetSourceComponent, type AssetSourceView, type AssetSourceViewComponents, type DefineAppInput, type DefineAppResult, type DefineAssetSourceViewInput, type DefineMediaLibraryInput, type DefinePanelViewInput, type DefineTileViewInput, type DefineWebWorkerInput, type DefineWindowViewInput, type DefinedService, type DefinedView, type DockGroup, type MediaLibraryField, type PanelComponent, type PanelView, type PanelViewComponents, type PanelViewProps, type ServiceBus, type ServiceCallback, type ServiceContext, type ServiceInfo, type ServiceType, type TileComponent, type TileSize, type TileView, type TileViewComponents, type TileViewProps, type ViewComponentsBySurface, type ViewDeclaration, type ViewSurface, type WebWorker, type WebWorkerBus, type WebWorkerInfo, type WebWorkerProps, type WebWorkerType, type WindowView, type WindowViewProps, type WorkbenchApp, type WorkbenchConfig, defineApplication, defineAssetSourceView, definePanelView, defineTileView, defineWebWorker, defineWindowView, isWorkbenchApp, isWorkbenchConfig, unstable_defineMediaLibrary, unstable_defineService, unstable_defineView };
180
+ export { type AssetSourceComponent, type AssetSourceViewComponents, type AssetSourceViewDeclaration, type DefineAppInput, type DefineAppResult, type DefineAssetSourceViewInput, type DefineMediaLibraryInput, type DefinePanelViewInput, type DefineTileViewInput, type DefineWebWorkerInput, type DefineWindowViewInput, type DefinedService, type DefinedView, type DockGroup, type MediaLibraryField, type PanelComponent, type PanelViewComponents, type PanelViewDeclaration, type PanelViewProps, type ServiceBus, type ServiceCallback, type ServiceContext, type ServiceInfo, type ServiceType, type TileComponent, type TileSize, type TileViewComponents, type TileViewDeclaration, type TileViewProps, type ViewComponentsBySurface, type ViewDeclaration, type ViewSurface, type WebWorkerBus, type WebWorkerDeclaration, type WebWorkerInfo, type WebWorkerProps, type WebWorkerType, type WindowViewDeclaration, type WindowViewProps, type WorkbenchApp, type WorkbenchConfig, defineApplication, defineAssetSourceView, definePanelView, defineTileView, defineWebWorker, defineWindowView, isWorkbenchApp, isWorkbenchConfig, unstable_defineMediaLibrary, unstable_defineService, unstable_defineView };
181
181
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/_exports/index.ts"],"sourcesContent":["export type {\n AssetSourceView,\n DefineAssetSourceViewInput,\n DefinePanelViewInput,\n DefineTileViewInput,\n DefineWebWorkerInput,\n DefineWindowViewInput,\n DockGroup,\n PanelView,\n ServiceType,\n TileSize,\n TileView,\n ViewDeclaration,\n ViewSurface,\n WebWorker,\n WebWorkerType,\n WindowView,\n} from '../contract.js'\nexport {\n defineAssetSourceView,\n definePanelView,\n defineTileView,\n defineWebWorker,\n defineWindowView,\n} from '../contract.js'\nexport {\n defineApplication,\n isWorkbenchApp,\n isWorkbenchConfig,\n unstable_defineMediaLibrary,\n} from '../defineApp.js'\nexport type {\n DefineAppInput,\n DefineAppResult,\n DefineMediaLibraryInput,\n MediaLibraryField,\n WorkbenchApp,\n WorkbenchConfig,\n} from '../defineApp.js'\nexport {unstable_defineView} from '../defineView.js'\nexport type {\n AssetSourceComponent,\n AssetSourceViewComponents,\n DefinedView,\n PanelComponent,\n PanelViewComponents,\n PanelViewProps,\n TileComponent,\n TileViewComponents,\n TileViewProps,\n ViewComponentsBySurface,\n WindowViewProps,\n} from '../defineView.js'\nexport {unstable_defineService} from '../webWorker.js'\nexport type {\n DefinedService,\n ServiceBus,\n ServiceCallback,\n ServiceContext,\n ServiceInfo,\n WebWorkerBus,\n WebWorkerInfo,\n WebWorkerProps,\n} from '../webWorker.js'\n"],"names":["defineAssetSourceView","definePanelView","defineTileView","defineWebWorker","defineWindowView","defineApplication","isWorkbenchApp","isWorkbenchConfig","unstable_defineMediaLibrary","unstable_defineView","unstable_defineService"],"mappings":"AAkBA,SACEA,qBAAqB,EACrBC,eAAe,EACfC,cAAc,EACdC,eAAe,EACfC,gBAAgB,QACX,iBAAgB;AACvB,SACEC,iBAAiB,EACjBC,cAAc,EACdC,iBAAiB,EACjBC,2BAA2B,QACtB,kBAAiB;AASxB,SAAQC,mBAAmB,QAAO,mBAAkB;AAcpD,SAAQC,sBAAsB,QAAO,kBAAiB"}
1
+ {"version":3,"sources":["../../src/_exports/index.ts"],"sourcesContent":["export type {\n AssetSourceViewDeclaration,\n DefineAssetSourceViewInput,\n DefinePanelViewInput,\n DefineTileViewInput,\n DefineWebWorkerInput,\n DefineWindowViewInput,\n DockGroup,\n PanelViewDeclaration,\n ServiceType,\n TileSize,\n TileViewDeclaration,\n ViewDeclaration,\n ViewSurface,\n WebWorkerDeclaration,\n WebWorkerType,\n WindowViewDeclaration,\n} from '../contract.js'\nexport {\n defineAssetSourceView,\n definePanelView,\n defineTileView,\n defineWebWorker,\n defineWindowView,\n} from '../contract.js'\nexport {\n defineApplication,\n isWorkbenchApp,\n isWorkbenchConfig,\n unstable_defineMediaLibrary,\n} from '../defineApp.js'\nexport type {\n DefineAppInput,\n DefineAppResult,\n DefineMediaLibraryInput,\n MediaLibraryField,\n WorkbenchApp,\n WorkbenchConfig,\n} from '../defineApp.js'\nexport {unstable_defineView} from '../defineView.js'\nexport type {\n AssetSourceComponent,\n AssetSourceViewComponents,\n DefinedView,\n PanelComponent,\n PanelViewComponents,\n PanelViewProps,\n TileComponent,\n TileViewComponents,\n TileViewProps,\n ViewComponentsBySurface,\n WindowViewProps,\n} from '../defineView.js'\nexport {unstable_defineService} from '../webWorker.js'\nexport type {\n DefinedService,\n ServiceBus,\n ServiceCallback,\n ServiceContext,\n ServiceInfo,\n WebWorkerBus,\n WebWorkerInfo,\n WebWorkerProps,\n} from '../webWorker.js'\n"],"names":["defineAssetSourceView","definePanelView","defineTileView","defineWebWorker","defineWindowView","defineApplication","isWorkbenchApp","isWorkbenchConfig","unstable_defineMediaLibrary","unstable_defineView","unstable_defineService"],"mappings":"AAkBA,SACEA,qBAAqB,EACrBC,eAAe,EACfC,cAAc,EACdC,eAAe,EACfC,gBAAgB,QACX,iBAAgB;AACvB,SACEC,iBAAiB,EACjBC,cAAc,EACdC,iBAAiB,EACjBC,2BAA2B,QACtB,kBAAiB;AASxB,SAAQC,mBAAmB,QAAO,mBAAkB;AAcpD,SAAQC,sBAAsB,QAAO,kBAAiB"}
@@ -1,4 +1,4 @@
1
- import { t as DevServerManifest } from "./registry-DZWnj09G.js";
1
+ import { t as DevServerManifest } from "./registry-BI8kZVpy.js";
2
2
  import { CliConfig, Output } from "@sanity/cli-core";
3
3
  interface StartWorkbenchPreviewOptions {
4
4
  /** Directory for the workbench Vite server's dependency cache. */
@@ -1,4 +1,4 @@
1
- import "./defineApp-9ppP3UQR.js";
1
+ import "./defineApp-DSXAAr3V.js";
2
2
  import { z } from "zod/mini";
3
3
  declare const devServerManifestSchema: z.ZodMiniObject<{
4
4
  applicationId: z.ZodMiniOptional<z.ZodMiniString<string>>;
@@ -19,13 +19,14 @@ declare const devServerManifestSchema: z.ZodMiniObject<{
19
19
  id: z.ZodMiniOptional<z.ZodMiniString<string>>;
20
20
  interfaces: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnion<readonly [z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
21
21
  metadata: z.ZodMiniNullable<z.ZodMiniObject<{
22
- dock: z.ZodMiniObject<{
22
+ dock: z.ZodMiniOptional<z.ZodMiniObject<{
23
23
  group: z.ZodMiniOptional<z.ZodMiniEnum<{
24
24
  system: "system";
25
25
  applications: "applications";
26
26
  }>>;
27
27
  order: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
28
- }, z.core.$strip>;
28
+ }, z.core.$strip>>;
29
+ icon: z.ZodMiniOptional<z.ZodMiniString<string>>;
29
30
  }, z.core.$strip>>;
30
31
  surface: z.ZodMiniLiteral<"window">;
31
32
  id: z.ZodMiniString<string>;
@@ -36,13 +37,14 @@ declare const devServerManifestSchema: z.ZodMiniObject<{
36
37
  version: z.ZodMiniOptional<z.ZodMiniString<string>>;
37
38
  }, z.core.$strip>, z.ZodMiniObject<{
38
39
  metadata: z.ZodMiniNullable<z.ZodMiniObject<{
39
- dock: z.ZodMiniObject<{
40
+ dock: z.ZodMiniOptional<z.ZodMiniObject<{
40
41
  group: z.ZodMiniOptional<z.ZodMiniEnum<{
41
42
  system: "system";
42
43
  applications: "applications";
43
44
  }>>;
44
45
  order: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
45
- }, z.core.$strip>;
46
+ }, z.core.$strip>>;
47
+ icon: z.ZodMiniOptional<z.ZodMiniString<string>>;
46
48
  }, z.core.$strip>>;
47
49
  surface: z.ZodMiniLiteral<"panel">;
48
50
  id: z.ZodMiniString<string>;
@@ -130,4 +132,4 @@ declare const devServerManifestSchema: z.ZodMiniObject<{
130
132
  */
131
133
  type DevServerManifest = z.infer<typeof devServerManifestSchema>;
132
134
  export { DevServerManifest as t };
133
- //# sourceMappingURL=registry-DZWnj09G.d.ts.map
135
+ //# sourceMappingURL=registry-BI8kZVpy.d.ts.map
@@ -1,5 +1,5 @@
1
- import { b as WorkbenchConfigValue } from "./contract-WrU3aOYd.js";
2
- import { t as DefineAppInput } from "./defineApp-9ppP3UQR.js";
1
+ import { b as WorkbenchConfigValue } from "./contract-BeAds4Yi.js";
2
+ import { t as DefineAppInput } from "./defineApp-DSXAAr3V.js";
3
3
  import { AppVisibility, CliConfig } from "@sanity/cli-core";
4
4
  /**
5
5
  * Bundled so adding a declaration family touches this type and the artifact
@@ -65,4 +65,4 @@ interface ResolvedMediaLibraryConfig {
65
65
  */
66
66
  declare function resolveWorkbenchConfig(cliConfig: CliConfig | null | undefined): ResolvedMediaLibraryConfig | null;
67
67
  export { resolveAppEntry as a, WorkbenchExposes as i, resolveWorkbenchConfig as n, resolveWorkbenchApp as o, ResolvedWorkbenchApp as r, ResolvedMediaLibraryConfig as t };
68
- //# sourceMappingURL=resolveWorkbenchConfig-_iD6fVUH.d.ts.map
68
+ //# sourceMappingURL=resolveWorkbenchConfig-Eex64aAA.d.ts.map
@@ -1,5 +1,5 @@
1
- import { h as ViewSurface, v as WebWorkerType } from "./contract-WrU3aOYd.js";
2
- import { i as WorkbenchExposes, r as ResolvedWorkbenchApp } from "./resolveWorkbenchConfig-_iD6fVUH.js";
1
+ import { h as ViewSurface, v as WebWorkerType } from "./contract-BeAds4Yi.js";
2
+ import { i as WorkbenchExposes, r as ResolvedWorkbenchApp } from "./resolveWorkbenchConfig-Eex64aAA.js";
3
3
  import { CliConfig } from "@sanity/cli-core";
4
4
  import { z } from "zod/mini";
5
5
  /**
@@ -62,4 +62,4 @@ declare function summarizeInterfaces({ views, webWorkers }: WorkbenchExposes): {
62
62
  views: DeployedView[];
63
63
  };
64
64
  export { DeployableWorkbenchApp as a, summarizeInterfaces as i, DeployedView as n, getWorkbench as o, DeployedWebWorker as r, DeployedInterface as t };
65
- //# sourceMappingURL=summarizeInterfaces-AM-QbtIA.d.ts.map
65
+ //# sourceMappingURL=summarizeInterfaces-BKIMEFzw.d.ts.map
@@ -1,5 +1,5 @@
1
- import { t as ResolvedMediaLibraryConfig } from "./resolveWorkbenchConfig-_iD6fVUH.js";
2
- import { a as DeployableWorkbenchApp, n as DeployedView, r as DeployedWebWorker } from "./summarizeInterfaces-AM-QbtIA.js";
1
+ import { t as ResolvedMediaLibraryConfig } from "./resolveWorkbenchConfig-Eex64aAA.js";
2
+ import { a as DeployableWorkbenchApp, n as DeployedView, r as DeployedWebWorker } from "./summarizeInterfaces-BKIMEFzw.js";
3
3
  import "node:zlib";
4
4
  import { UndeployAdapter, UndeployApplicationTarget, UndeployConfigTarget } from "@sanity/cli-core/undeploy";
5
5
  interface ConfigSnapshot {
@@ -4,7 +4,8 @@ import { getErrorMessage } from '@sanity/cli-core/errors';
4
4
  import { spinner } from '@sanity/cli-core/ux';
5
5
  import { c as createTar } from 'tar';
6
6
  import { deriveInterfaces } from '../../deriveInterfaces.js';
7
- import { createApplication, createDeployment, deleteApplication, removeApplicationIcon, setApplicationIcon, updateApplication } from '../../services/applications.js';
7
+ import { readAppIcon } from '../../readAppIcon.js';
8
+ import { createApplication, createDeployment, deleteApplication, removeApplicationIcon, setApplicationIcon, setInterfaceIcon, updateApplication } from '../../services/applications.js';
8
9
  function toBrettInterface(iface) {
9
10
  const { id: _id, src: _src, ...declaration } = iface;
10
11
  if ('type' in declaration) return declaration;
@@ -19,7 +20,7 @@ function toBrettInterface(iface) {
19
20
  }
20
21
  case 'panel':
21
22
  {
22
- const { surface, ...view } = declaration;
23
+ const { icon: _icon, surface, ...view } = declaration;
23
24
  return {
24
25
  ...view,
25
26
  type: surface
@@ -35,7 +36,7 @@ function toBrettInterface(iface) {
35
36
  }
36
37
  case 'window':
37
38
  {
38
- const { surface, ...view } = declaration;
39
+ const { icon: _icon, surface, ...view } = declaration;
39
40
  return {
40
41
  ...view,
41
42
  type: 'app'
@@ -89,7 +90,7 @@ function toBrettInterface(iface) {
89
90
  * then sync its mutable metadata (`title`, and `slug`/`visibility` when set)
90
91
  * and its icon from config. The deploy endpoint ignores these, so a redeploy
91
92
  * patches them here alongside the new deployment. No `icon` removes the
92
- * application's icon.
93
+ * application's icon. Each interface's `icon` goes on the interface Brett created for it.
93
94
  *
94
95
  * `onDeployed` fires the instant the deployment is live, before the metadata
95
96
  * sync — so a caller can disarm a create-time rollback that must not delete an
@@ -99,22 +100,27 @@ function toBrettInterface(iface) {
99
100
  * application's registered origin.
100
101
  * @internal
101
102
  */ export async function deployWorkbenchApp(options) {
102
- const { access, app, applicationId, icon, isApp, isAutoUpdating, isExternal = false, label = 'Deploying...', mfManifest, onDeployed, slug, sourceDir, title, version, visibility, workspaces } = options;
103
+ const { access, app, applicationId, icon, isApp, isAutoUpdating, isExternal = false, label = 'Deploying...', mfManifest, onDeployed, slug, sourceDir, title, version, visibility, workDir, workspaces } = options;
103
104
  const tarball = isExternal ? undefined : createTar({
104
105
  cwd: dirname(sourceDir)
105
106
  }, [
106
107
  basename(sourceDir)
107
108
  ]).pipe(createGzip());
109
+ // Read before deploying, so a bad icon path fails while nothing is live.
110
+ const interfaces = await Promise.all(deriveInterfaces(app, {
111
+ appTitle: title,
112
+ isApp
113
+ }).map(async (iface)=>({
114
+ brett: toBrettInterface(iface),
115
+ icon: 'icon' in iface && iface.icon ? await readAppIcon(workDir, iface.icon) : undefined
116
+ })));
108
117
  const spin = spinner(label).start();
109
118
  try {
110
- await createDeployment({
119
+ const deployment = await createDeployment({
111
120
  access,
112
121
  applicationId,
113
122
  // Brett assigns the id and resolves modules by `moduleId`, so neither travels.
114
- interfaces: deriveInterfaces(app, {
115
- appTitle: title,
116
- isApp
117
- }).map((iface)=>toBrettInterface(iface)),
123
+ interfaces: interfaces.map(({ brett })=>brett),
118
124
  isAutoUpdating,
119
125
  mfManifest,
120
126
  tarball,
@@ -139,11 +145,23 @@ function toBrettInterface(iface) {
139
145
  try {
140
146
  await setApplicationIcon(applicationId, icon);
141
147
  } catch (error) {
142
- throw toIconRejection(error);
148
+ throw toIconRejection(error, 'The app icon was rejected', "The deployment is live with the application's previous icon. Change `app.icon`");
143
149
  }
144
150
  } else {
145
151
  await removeApplicationIcon(applicationId);
146
152
  }
153
+ for (const { brett: { name, type }, icon: interfaceIcon } of interfaces){
154
+ if (!interfaceIcon) continue;
155
+ const iface = deployment.interfaces.find((i)=>i.type === type && i.name === name);
156
+ if (!iface) {
157
+ throw new Error(`The deployment is live, but has no ${type} interface named "${name}" to set its icon on.`);
158
+ }
159
+ try {
160
+ await setInterfaceIcon(applicationId, iface.id, interfaceIcon);
161
+ } catch (error) {
162
+ throw toIconRejection(error, `The icon of view "${name}" was rejected`, "The deployment is live without it. Change the view's `icon`");
163
+ }
164
+ }
147
165
  spin.succeed();
148
166
  } catch (error) {
149
167
  spin.clear();
@@ -162,10 +180,10 @@ function toBrettInterface(iface) {
162
180
  cause: error
163
181
  });
164
182
  }
165
- /** A 4xx on the icon upload is the image being rejected; name the server's reason. */ function toIconRejection(error) {
183
+ /** A 4xx on an icon upload is the image being rejected; name the server's reason. */ function toIconRejection(error, rejected, fix) {
166
184
  const statusCode = error?.statusCode;
167
185
  if (statusCode === undefined || statusCode < 400 || statusCode >= 500) return error;
168
- return new Error(`The app icon was rejected: ${getErrorMessage(error)}. The deployment is live with the application's previous icon. Change \`app.icon\` in sanity.cli.ts and deploy again.`, {
186
+ return new Error(`${rejected}: ${getErrorMessage(error)}. ${fix} in sanity.cli.ts and deploy again.`, {
169
187
  cause: error
170
188
  });
171
189
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/deploy/deployWorkbenchApp.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {createGzip} from 'node:zlib'\n\nimport {type AppVisibility, type CliConfig} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {type ImageFile} from '@sanity/cli-core/images'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {c as createTar} from 'tar'\n\nimport {type DerivedInterface, deriveInterfaces} from '../../deriveInterfaces.js'\nimport {\n type Application,\n type BrettAccess,\n type BrettInterface,\n type BrettWorkspace,\n createApplication,\n createDeployment,\n deleteApplication,\n removeApplicationIcon,\n setApplicationIcon,\n updateApplication,\n} from '../../services/applications.js'\n\n/**\n * `rollback` undoes the creation, so a later failure leaves no record stranded at the slug.\n * @internal\n */\nexport interface CreatedApplication {\n application: Application\n rollback: () => Promise<void>\n}\n\nfunction toBrettInterface(iface: DerivedInterface): BrettInterface {\n const {id: _id, src: _src, ...declaration} = iface\n if ('type' in declaration) return declaration\n\n switch (declaration.surface) {\n case 'asset_source': {\n const {surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'panel': {\n const {surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'tile': {\n const {surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'window': {\n const {surface, ...view} = declaration\n return {...view, type: 'app'}\n }\n }\n}\n\n/**\n * Create a coreApp record (no deployment), so the CLI can build with its id\n * before shipping the first deployment. First deploy only.\n * @internal\n */\nexport async function createCoreApp(options: {\n isSingleton?: boolean\n name?: string\n organizationId: string\n slug: string\n title: string\n visibility?: AppVisibility\n}): Promise<CreatedApplication> {\n const spin = spinner('Creating application...').start()\n try {\n const application = await createApplication({...options, type: 'coreApp'})\n spin.succeed()\n return {application, rollback: () => deleteApplication(application.id)}\n } catch (error) {\n spin.fail()\n throw error\n }\n}\n\n/**\n * Create a studio record (no deployment).\n * @internal\n */\nexport async function createStudio(options: {\n externalUrl?: string\n name?: string\n organizationId: string\n projectId: string | undefined\n slug: string\n title: string\n visibility?: AppVisibility\n}): Promise<CreatedApplication> {\n const spin = spinner('Creating studio...').start()\n try {\n const application = await createApplication({...options, type: 'studio'})\n spin.succeed()\n return {application, rollback: () => deleteApplication(application.id)}\n } catch (error) {\n spin.fail()\n throw error\n }\n}\n\n/**\n * Ship a deployment to an already-created (or `deployment.appId`) application,\n * then sync its mutable metadata (`title`, and `slug`/`visibility` when set)\n * and its icon from config. The deploy endpoint ignores these, so a redeploy\n * patches them here alongside the new deployment. No `icon` removes the\n * application's icon.\n *\n * `onDeployed` fires the instant the deployment is live, before the metadata\n * sync — so a caller can disarm a create-time rollback that must not delete an\n * application once it has an active deployment.\n *\n * `isExternal` skips the tarball: the customer serves the build from the\n * application's registered origin.\n * @internal\n */\nexport async function deployWorkbenchApp(options: {\n access?: readonly BrettAccess[]\n app: CliConfig['app']\n applicationId: string\n icon?: ImageFile\n isApp: boolean\n isAutoUpdating: boolean\n isExternal?: boolean\n label?: string\n mfManifest: Record<string, unknown>\n onDeployed?: () => void\n /**\n * The address from config. Only `createApplication` used to send it, so an\n * app with a `deployment.appId` kept whatever slug it was created at.\n */\n slug?: string\n sourceDir: string\n title: string\n version: string\n visibility?: AppVisibility\n workspaces?: readonly BrettWorkspace[]\n}): Promise<void> {\n const {\n access,\n app,\n applicationId,\n icon,\n isApp,\n isAutoUpdating,\n isExternal = false,\n label = 'Deploying...',\n mfManifest,\n onDeployed,\n slug,\n sourceDir,\n title,\n version,\n visibility,\n workspaces,\n } = options\n const tarball = isExternal\n ? undefined\n : createTar({cwd: dirname(sourceDir)}, [basename(sourceDir)]).pipe(createGzip())\n\n const spin = spinner(label).start()\n try {\n await createDeployment({\n access,\n applicationId,\n // Brett assigns the id and resolves modules by `moduleId`, so neither travels.\n interfaces: deriveInterfaces(app, {appTitle: title, isApp}).map((iface) =>\n toBrettInterface(iface),\n ),\n isAutoUpdating,\n mfManifest,\n tarball,\n version,\n workspaces,\n })\n onDeployed?.()\n try {\n await updateApplication(applicationId, {\n title,\n ...(slug ? {slug} : {}),\n ...(visibility ? {visibility} : {}),\n })\n } catch (error) {\n throw toSlugRejection(error, slug)\n }\n if (icon) {\n try {\n await setApplicationIcon(applicationId, icon)\n } catch (error) {\n throw toIconRejection(error)\n }\n } else {\n await removeApplicationIcon(applicationId)\n }\n spin.succeed()\n } catch (error) {\n spin.clear()\n throw error\n }\n}\n\n/**\n * The slug is the one synced field the server validates — it must be free\n * within the organization, and a singleton app only accepts its reserved\n * identifiers — so a 4xx on the metadata patch is a rejected rename. Name the\n * slug and the server's reason; anything else propagates untouched.\n */\nfunction toSlugRejection(error: unknown, slug: string | undefined): unknown {\n const statusCode = (error as {statusCode?: number})?.statusCode\n if (!slug || statusCode === undefined || statusCode < 400 || statusCode >= 500) return error\n return new Error(\n `Slug \"${slug}\" was rejected: ${getErrorMessage(error)}. The deployment is live at the application's previous slug — change \\`app.slug\\` in sanity.cli.ts and deploy again.`,\n {cause: error},\n )\n}\n\n/** A 4xx on the icon upload is the image being rejected; name the server's reason. */\nfunction toIconRejection(error: unknown): unknown {\n const statusCode = (error as {statusCode?: number})?.statusCode\n if (statusCode === undefined || statusCode < 400 || statusCode >= 500) return error\n return new Error(\n `The app icon was rejected: ${getErrorMessage(error)}. The deployment is live with the application's previous icon. Change \\`app.icon\\` in sanity.cli.ts and deploy again.`,\n {cause: error},\n )\n}\n"],"names":["basename","dirname","createGzip","getErrorMessage","spinner","c","createTar","deriveInterfaces","createApplication","createDeployment","deleteApplication","removeApplicationIcon","setApplicationIcon","updateApplication","toBrettInterface","iface","id","_id","src","_src","declaration","surface","view","type","createCoreApp","options","spin","start","application","succeed","rollback","error","fail","createStudio","deployWorkbenchApp","access","app","applicationId","icon","isApp","isAutoUpdating","isExternal","label","mfManifest","onDeployed","slug","sourceDir","title","version","visibility","workspaces","tarball","undefined","cwd","pipe","interfaces","appTitle","map","toSlugRejection","toIconRejection","clear","statusCode","Error","cause"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQ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Aa;oBAACA;gBAAU,IAAI,CAAC,CAAC;YACpC;QACF,EAAE,OAAOlB,OAAO;YACd,MAAM2B,gBAAgB3B,OAAOc;QAC/B;QACA,IAAIP,MAAM;YACR,IAAI;gBACF,MAAM1B,mBAAmByB,eAAeC;YAC1C,EAAE,OAAOP,OAAO;gBACd,MAAM4B,gBAAgB5B;YACxB;QACF,OAAO;YACL,MAAMpB,sBAAsB0B;QAC9B;QACAX,KAAKG,OAAO;IACd,EAAE,OAAOE,OAAO;QACdL,KAAKkC,KAAK;QACV,MAAM7B;IACR;AACF;AAEA;;;;;CAKC,GACD,SAAS2B,gBAAgB3B,KAAc,EAAEc,IAAwB;IAC/D,MAAMgB,aAAc9B,OAAiC8B;IACrD,IAAI,CAAChB,QAAQgB,eAAeT,aAAaS,aAAa,OAAOA,cAAc,KAAK,OAAO9B;IACvF,OAAO,IAAI+B,MACT,CAAC,MAAM,EAAEjB,KAAK,gBAAgB,EAAE1C,gBAAgB4B,OAAO,oHAAoH,CAAC,EAC5K;QAACgC,OAAOhC;IAAK;AAEjB;AAEA,oFAAoF,GACpF,SAAS4B,gBAAgB5B,KAAc;IACrC,MAAM8B,aAAc9B,OAAiC8B;IACrD,IAAIA,eAAeT,aAAaS,aAAa,OAAOA,cAAc,KAAK,OAAO9B;IAC9E,OAAO,IAAI+B,MACT,CAAC,2BAA2B,EAAE3D,gBAAgB4B,OAAO,qHAAqH,CAAC,EAC3K;QAACgC,OAAOhC;IAAK;AAEjB"}
1
+ {"version":3,"sources":["../../../src/actions/deploy/deployWorkbenchApp.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {createGzip} from 'node:zlib'\n\nimport {type AppVisibility, type CliConfig} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {type ImageFile} from '@sanity/cli-core/images'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {c as createTar} from 'tar'\n\nimport {type DerivedInterface, deriveInterfaces} from '../../deriveInterfaces.js'\nimport {readAppIcon} from '../../readAppIcon.js'\nimport {\n type Application,\n type BrettAccess,\n type BrettInterface,\n type BrettWorkspace,\n createApplication,\n createDeployment,\n deleteApplication,\n removeApplicationIcon,\n setApplicationIcon,\n setInterfaceIcon,\n updateApplication,\n} from '../../services/applications.js'\n\n/**\n * `rollback` undoes the creation, so a later failure leaves no record stranded at the slug.\n * @internal\n */\nexport interface CreatedApplication {\n application: Application\n rollback: () => Promise<void>\n}\n\nfunction toBrettInterface(iface: DerivedInterface): BrettInterface {\n const {id: _id, src: _src, ...declaration} = iface\n if ('type' in declaration) return declaration\n\n switch (declaration.surface) {\n case 'asset_source': {\n const {surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'panel': {\n const {icon: _icon, surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'tile': {\n const {surface, ...view} = declaration\n return {...view, type: surface}\n }\n case 'window': {\n const {icon: _icon, surface, ...view} = declaration\n return {...view, type: 'app'}\n }\n }\n}\n\n/**\n * Create a coreApp record (no deployment), so the CLI can build with its id\n * before shipping the first deployment. First deploy only.\n * @internal\n */\nexport async function createCoreApp(options: {\n isSingleton?: boolean\n name?: string\n organizationId: string\n slug: string\n title: string\n visibility?: AppVisibility\n}): Promise<CreatedApplication> {\n const spin = spinner('Creating application...').start()\n try {\n const application = await createApplication({...options, type: 'coreApp'})\n spin.succeed()\n return {application, rollback: () => deleteApplication(application.id)}\n } catch (error) {\n spin.fail()\n throw error\n }\n}\n\n/**\n * Create a studio record (no deployment).\n * @internal\n */\nexport async function createStudio(options: {\n externalUrl?: string\n name?: string\n organizationId: string\n projectId: string | undefined\n slug: string\n title: string\n visibility?: AppVisibility\n}): Promise<CreatedApplication> {\n const spin = spinner('Creating studio...').start()\n try {\n const application = await createApplication({...options, type: 'studio'})\n spin.succeed()\n return {application, rollback: () => deleteApplication(application.id)}\n } catch (error) {\n spin.fail()\n throw error\n }\n}\n\n/**\n * Ship a deployment to an already-created (or `deployment.appId`) application,\n * then sync its mutable metadata (`title`, and `slug`/`visibility` when set)\n * and its icon from config. The deploy endpoint ignores these, so a redeploy\n * patches them here alongside the new deployment. No `icon` removes the\n * application's icon. Each interface's `icon` goes on the interface Brett created for it.\n *\n * `onDeployed` fires the instant the deployment is live, before the metadata\n * sync — so a caller can disarm a create-time rollback that must not delete an\n * application once it has an active deployment.\n *\n * `isExternal` skips the tarball: the customer serves the build from the\n * application's registered origin.\n * @internal\n */\nexport async function deployWorkbenchApp(options: {\n access?: readonly BrettAccess[]\n app: CliConfig['app']\n applicationId: string\n icon?: ImageFile\n isApp: boolean\n isAutoUpdating: boolean\n isExternal?: boolean\n label?: string\n mfManifest: Record<string, unknown>\n onDeployed?: () => void\n /**\n * The address from config. Only `createApplication` used to send it, so an\n * app with a `deployment.appId` kept whatever slug it was created at.\n */\n slug?: string\n sourceDir: string\n title: string\n version: string\n visibility?: AppVisibility\n workDir: string\n workspaces?: readonly BrettWorkspace[]\n}): Promise<void> {\n const {\n access,\n app,\n applicationId,\n icon,\n isApp,\n isAutoUpdating,\n isExternal = false,\n label = 'Deploying...',\n mfManifest,\n onDeployed,\n slug,\n sourceDir,\n title,\n version,\n visibility,\n workDir,\n workspaces,\n } = options\n const tarball = isExternal\n ? undefined\n : createTar({cwd: dirname(sourceDir)}, [basename(sourceDir)]).pipe(createGzip())\n\n // Read before deploying, so a bad icon path fails while nothing is live.\n const interfaces = await Promise.all(\n deriveInterfaces(app, {appTitle: title, isApp}).map(async (iface) => ({\n brett: toBrettInterface(iface),\n icon: 'icon' in iface && iface.icon ? await readAppIcon(workDir, iface.icon) : undefined,\n })),\n )\n\n const spin = spinner(label).start()\n try {\n const deployment = await createDeployment({\n access,\n applicationId,\n // Brett assigns the id and resolves modules by `moduleId`, so neither travels.\n interfaces: interfaces.map(({brett}) => brett),\n isAutoUpdating,\n mfManifest,\n tarball,\n version,\n workspaces,\n })\n onDeployed?.()\n try {\n await updateApplication(applicationId, {\n title,\n ...(slug ? {slug} : {}),\n ...(visibility ? {visibility} : {}),\n })\n } catch (error) {\n throw toSlugRejection(error, slug)\n }\n if (icon) {\n try {\n await setApplicationIcon(applicationId, icon)\n } catch (error) {\n throw toIconRejection(\n error,\n 'The app icon was rejected',\n \"The deployment is live with the application's previous icon. Change `app.icon`\",\n )\n }\n } else {\n await removeApplicationIcon(applicationId)\n }\n for (const {\n brett: {name, type},\n icon: interfaceIcon,\n } of interfaces) {\n if (!interfaceIcon) continue\n\n const iface = deployment.interfaces.find((i) => i.type === type && i.name === name)\n if (!iface) {\n throw new Error(\n `The deployment is live, but has no ${type} interface named \"${name}\" to set its icon on.`,\n )\n }\n try {\n await setInterfaceIcon(applicationId, iface.id, interfaceIcon)\n } catch (error) {\n throw toIconRejection(\n error,\n `The icon of view \"${name}\" was rejected`,\n \"The deployment is live without it. Change the view's `icon`\",\n )\n }\n }\n spin.succeed()\n } catch (error) {\n spin.clear()\n throw error\n }\n}\n\n/**\n * The slug is the one synced field the server validates — it must be free\n * within the organization, and a singleton app only accepts its reserved\n * identifiers — so a 4xx on the metadata patch is a rejected rename. Name the\n * slug and the server's reason; anything else propagates untouched.\n */\nfunction toSlugRejection(error: unknown, slug: string | undefined): unknown {\n const statusCode = (error as {statusCode?: number})?.statusCode\n if (!slug || statusCode === undefined || statusCode < 400 || statusCode >= 500) return error\n return new Error(\n `Slug \"${slug}\" was rejected: ${getErrorMessage(error)}. The deployment is live at the application's previous slug — change \\`app.slug\\` in sanity.cli.ts and deploy again.`,\n {cause: error},\n )\n}\n\n/** A 4xx on an icon upload is the image being rejected; name the server's reason. */\nfunction toIconRejection(error: unknown, rejected: string, fix: string): unknown {\n const statusCode = (error as {statusCode?: number})?.statusCode\n if (statusCode === undefined || statusCode < 400 || statusCode >= 500) return error\n return new Error(\n `${rejected}: ${getErrorMessage(error)}. ${fix} in sanity.cli.ts and deploy again.`,\n {cause: error},\n )\n}\n"],"names":["basename","dirname","createGzip","getErrorMessage","spinner","c","createTar","deriveInterfaces","readAppIcon","createApplication","createDeployment","deleteApplication","removeApplicationIcon","setApplicationIcon","setInterfaceIcon","updateApplication","toBrettInterface","iface","id","_id","src","_src","declaration","surface","view","type","icon","_icon","createCoreApp","options","spin","start","application","succeed","rollback","error","fail","createStudio","deployWorkbenchApp","access","app","applicationId","isApp","isAutoUpdating","isExternal","label","mfManifest","onDeployed","slug","sourceDir","title","version","visibility","workDir","workspaces","tarball","undefined","cwd","pipe","interfaces","Promise","all","appTitle","map","brett","deployment","toSlugRejection","toIconRejection","name","interfaceIcon","find","i","Error","clear","statusCode","cause","rejected","fix"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,UAAU,QAAO,YAAW;AAGpC,SAAQC,eAAe,QAAO,0BAAyB;AAEvD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,KAAKC,SAAS,QAAO,MAAK;AAElC,SAA+BC,gBAAgB,QAAO,4BAA2B;AACjF,SAAQC,WAAW,QAAO,uBAAsB;AAChD,SAKEC,iBAAiB,EACjBC,gBAAgB,EAChBC,iBAAiB,EACjBC,qBAAqB,EACrBC,kBAAkB,EAClBC,gBAAgB,EAChBC,iBAAiB,QACZ,iCAAgC;AAWvC,SAASC,iBAAiBC,KAAuB;IAC/C,MAAM,EAACC,IAAIC,GAAG,EAAEC,KAAKC,IAAI,EAAE,GAAGC,aAAY,GAAGL;IAC7C,IAAI,UAAUK,aAAa,OAAOA;IAElC,OAAQA,YAAYC,OAAO;QACzB,KAAK;YAAgB;gBACnB,MAAM,EAACA,OAAO,EAAE,GAAGC,MAAK,GAAGF;gBAC3B,OAAO;oBAAC,GAAGE,IAAI;oBAAEC,MAAMF;gBAAO;YAChC;QACA,KAAK;YAAS;gBACZ,MAAM,EAACG,MAAMC,KAAK,EAAEJ,OAAO,EAAE,GAAGC,MAAK,GAAGF;gBACxC,OAAO;oBAAC,GAAGE,IAAI;oBAAEC,MAAMF;gBAAO;YAChC;QACA,KAAK;YAAQ;gBACX,MAAM,EAACA,OAAO,EAAE,GA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,QAAQ8C,EAAEH,IAAI,KAAKA;YAC9E,IAAI,CAACnD,OAAO;gBACV,MAAM,IAAIuD,MACR,CAAC,mCAAmC,EAAE/C,KAAK,kBAAkB,EAAE2C,KAAK,qBAAqB,CAAC;YAE9F;YACA,IAAI;gBACF,MAAMtD,iBAAiB2B,eAAexB,MAAMC,EAAE,EAAEmD;YAClD,EAAE,OAAOlC,OAAO;gBACd,MAAMgC,gBACJhC,OACA,CAAC,kBAAkB,EAAEiC,KAAK,cAAc,CAAC,EACzC;YAEJ;QACF;QACAtC,KAAKG,OAAO;IACd,EAAE,OAAOE,OAAO;QACdL,KAAK2C,KAAK;QACV,MAAMtC;IACR;AACF;AAEA;;;;;CAKC,GACD,SAAS+B,gBAAgB/B,KAAc,EAAEa,IAAwB;IAC/D,MAAM0B,aAAcvC,OAAiCuC;IACrD,IAAI,CAAC1B,QAAQ0B,eAAelB,aAAakB,aAAa,OAAOA,cAAc,KAAK,OAAOvC;IACvF,OAAO,IAAIqC,MACT,CAAC,MAAM,EAAExB,KAAK,gBAAgB,EAAE7C,gBAAgBgC,OAAO,oHAAoH,CAAC,EAC5K;QAACwC,OAAOxC;IAAK;AAEjB;AAEA,mFAAmF,GACnF,SAASgC,gBAAgBhC,KAAc,EAAEyC,QAAgB,EAAEC,GAAW;IACpE,MAAMH,aAAcvC,OAAiCuC;IACrD,IAAIA,eAAelB,aAAakB,aAAa,OAAOA,cAAc,KAAK,OAAOvC;IAC9E,OAAO,IAAIqC,MACT,GAAGI,SAAS,EAAE,EAAEzE,gBAAgBgC,OAAO,EAAE,EAAE0C,IAAI,mCAAmC,CAAC,EACnF;QAACF,OAAOxC;IAAK;AAEjB"}
@@ -1,4 +1,4 @@
1
- import { relative } from 'node:path';
1
+ import { relative, resolve } from 'node:path';
2
2
  import { getCliConfigUncached } from '@sanity/cli-core';
3
3
  import { isWorkbenchApp, isWorkbenchConfig } from '../../defineApp.js';
4
4
  import { deriveInterfaces } from '../../deriveInterfaces.js';
@@ -29,6 +29,13 @@ import { startDevManifestWatcher } from './startDevManifestWatcher.js';
29
29
  port: typeof addr === 'object' && addr ? addr.port : server.config.server.port
30
30
  };
31
31
  }
32
+ function servedUrl(server, file) {
33
+ // Vite serves `public/` at the root, and warns on every request for `/public/...`.
34
+ const { base, publicDir, root } = server.config;
35
+ const inPublicDir = Boolean(publicDir) && !relative(publicDir, file).startsWith('..');
36
+ const { host, https, port } = serverAddress(server);
37
+ return `${https ? 'https' : 'http'}://${host}:${port}${base}${toUrlPath(inPublicDir ? publicDir : root, file)}`;
38
+ }
32
39
  /**
33
40
  * Register the dev server in the registry and watch its config for manifest +
34
41
  * interface changes. The workbench reads the entry to locate and render the
@@ -40,6 +47,7 @@ import { startDevManifestWatcher } from './startDevManifestWatcher.js';
40
47
  // Forwarded alongside (not inside) the manifest so the workbench renders local
41
48
  // panels/workers and reads the configs without a deploy.
42
49
  const interfaces = deriveInterfaces(cliConfig.app, {
50
+ iconUrl: (iconPath)=>servedUrl(server, resolve(workDir, iconPath)),
43
51
  isApp
44
52
  });
45
53
  const configs = await deriveConfigs(cliConfig);
@@ -94,15 +102,12 @@ import { startDevManifestWatcher } from './startDevManifestWatcher.js';
94
102
  if (isApp && isWorkbenchApp(nextConfig.app) && nextConfig.app.icon) {
95
103
  // Read in full so an image a deploy would reject warns here, while editing.
96
104
  const { file } = await readAppIcon(workDir, nextConfig.app.icon);
97
- // Vite serves `public/` at the root, and warns on every request for `/public/...`.
98
- const { base, publicDir, root } = liveServer.config;
99
- const inPublicDir = Boolean(publicDir) && !relative(publicDir, file).startsWith('..');
100
- const { host, https, port } = serverAddress(liveServer);
101
- iconUrl = `${https ? 'https' : 'http'}://${host}:${port}${base}${toUrlPath(inPublicDir ? publicDir : root, file)}`;
105
+ iconUrl = servedUrl(liveServer, file);
102
106
  }
103
107
  return {
104
108
  configs: await deriveConfigs(nextConfig),
105
109
  interfaces: deriveInterfaces(nextConfig.app, {
110
+ iconUrl: (iconPath)=>servedUrl(liveServer, resolve(workDir, iconPath)),
106
111
  isApp
107
112
  }),
108
113
  manifest: await extractManifest({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/dev/startDevServerRegistration.ts"],"sourcesContent":["import {relative} from 'node:path'\n\nimport {type CliConfig, getCliConfigUncached, type Output} from '@sanity/cli-core'\nimport {type ViteDevServer} from 'vite'\n\nimport {isWorkbenchApp, isWorkbenchConfig} from '../../defineApp.js'\nimport {deriveInterfaces} from '../../deriveInterfaces.js'\nimport {readAppIcon, toUrlPath} from '../../readAppIcon.js'\nimport {resolveWorkbenchConfig} from '../../resolveWorkbenchConfig.js'\nimport {formatWorkbenchAppErrors, validateWorkbenchApp} from '../../validateWorkbenchApp.js'\nimport {deriveConfigs} from './deriveConfigs.js'\nimport {trackExposesSet} from './exposesSetId.js'\nimport {\n dashboardPath,\n type DevServerManifest,\n getRegisteredServers,\n localAppIdentity,\n registerDevServer,\n} from './registry.js'\nimport {startDevManifestWatcher} from './startDevManifestWatcher.js'\n\ninterface DevServerRegistrationOptions {\n cliConfig: CliConfig\n /**\n * Extract the project manifest to inline into the registry. The caller owns the\n * studio-vs-app split (manifest formats are CLI-domain); registration re-derives\n * the interface set alongside it.\n */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n /** Where this server serves the app's icon. */\n iconUrl?: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n isApp: boolean\n output: Output\n server: ViteDevServer\n workDir: string\n\n /**\n * Rebuild the app's federation remote when its interface set changes, awaited\n * *before* the registry patch — the patch reloads the workbench page, which must\n * re-fetch a remote that already exposes the new interface. Resolves with the\n * recreated server so the entry gets its actual address (non-strict ports may\n * shift it); must reject if the restart produces no server, so the set stays\n * uncommitted and the next save retries instead of advertising a dead port.\n */\n onInterfaceSetChange?: () => Promise<ViteDevServer>\n}\n\ninterface DevServerRegistrationHandle {\n close: () => Promise<void>\n\n /** Where the Dashboard opens this server; unset when it can't open it there. */\n path?: string\n}\n\n/**\n * Log any app validation errors without aborting. Unlike build and deploy, dev\n * stays up on an invalid app so the author sees the errors and fixes them live on\n * the next save. A config is not an app — it isn't validated by the app schema\n * (which would spuriously demand a slug/title), so skip it here.\n */\nfunction reportConfigErrors(app: CliConfig['app'], output: Output): void {\n if (isWorkbenchConfig(app)) return\n const errors = validateWorkbenchApp(app)\n if (errors.length === 0) return\n output.warn(formatWorkbenchAppErrors(errors))\n}\n\n/** The address the server actually bound — the live socket, which can differ from the configured port under non-strict ports. */\nfunction serverAddress(server: ViteDevServer) {\n const resolvedHost = server.config.server.host\n const addr = server.httpServer?.address()\n return {\n host: typeof resolvedHost === 'string' ? resolvedHost : 'localhost',\n https: Boolean(server.config.server.https),\n port: typeof addr === 'object' && addr ? addr.port : server.config.server.port,\n }\n}\n\n/**\n * Register the dev server in the registry and watch its config for manifest +\n * interface changes. The workbench reads the entry to locate and render the\n * server; the watcher keeps it current as `sanity.cli.ts` is edited.\n */\nexport async function startDevServerRegistration(\n options: DevServerRegistrationOptions,\n): Promise<DevServerRegistrationHandle> {\n const {cliConfig, extractManifest, isApp, onInterfaceSetChange, output, server, workDir} = options\n\n const {host: appHost, https, port: appPort} = serverAddress(server)\n\n reportConfigErrors(cliConfig.app, output)\n\n // Forwarded alongside (not inside) the manifest so the workbench renders local\n // panels/workers and reads the configs without a deploy.\n const interfaces = deriveInterfaces(cliConfig.app, {isApp})\n const configs = await deriveConfigs(cliConfig)\n\n const workbenchApp = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined\n const config = resolveWorkbenchConfig(cliConfig)\n // A config runs alongside the app it configures, so give it its own id\n // namespace — sharing the app's slug would make the two indistinguishable here.\n const id = config ? `config:${config.appType}` : workbenchApp?.slug\n const applicationId = workbenchApp ? cliConfig.deployment?.appId : undefined\n // Identity is resolved and the reference composed here, so the workbench reads\n // both off the registry entry instead of recomposing them.\n const identity = workbenchApp ? localAppIdentity(workbenchApp) : undefined\n\n // The Dashboard tells local apps apart by their bus id and by the application\n // they stand in for.\n const organizationId = cliConfig.app?.organizationId\n const devServer = getRegisteredServers().find(\n (server) =>\n server.organizationId === organizationId &&\n (server.id === id || (applicationId && server.applicationId === applicationId)),\n )\n\n if (id && devServer) {\n const served =\n devServer.id === id\n ? `\"${id}\" is already served`\n : `\"${id}\" is the same application as \"${devServer.id}\", served`\n output.error(\n `${served} by another dev server running on port ${devServer.port}, ` +\n \"so the Dashboard can't tell them apart and this one stays out of it. Stop that server first.\",\n {exit: false},\n )\n return {close: async () => {}}\n }\n\n const registration = registerDevServer({\n applicationId,\n configs,\n host: appHost,\n https,\n id,\n interfaces,\n organizationId,\n port: appPort,\n projectId: cliConfig?.api?.projectId,\n ...identity,\n type: isApp ? 'coreApp' : 'studio',\n workDir,\n })\n\n const exposesSet = trackExposesSet({configs, interfaces})\n let liveServer = server\n\n const watcher = await startDevManifestWatcher({\n // Re-derive every pass (don't omit): the registry patch is a shallow merge,\n // so omitting would wipe the registered set.\n extract: async (params) => {\n const nextConfig = await getCliConfigUncached(params.workDir)\n reportConfigErrors(nextConfig.app, output)\n\n let iconUrl: string | undefined\n if (isApp && isWorkbenchApp(nextConfig.app) && nextConfig.app.icon) {\n // Read in full so an image a deploy would reject warns here, while editing.\n const {file} = await readAppIcon(workDir, nextConfig.app.icon)\n // Vite serves `public/` at the root, and warns on every request for `/public/...`.\n const {base, publicDir, root} = liveServer.config\n const inPublicDir = Boolean(publicDir) && !relative(publicDir, file).startsWith('..')\n const {host, https, port} = serverAddress(liveServer)\n iconUrl = `${https ? 'https' : 'http'}://${host}:${port}${base}${toUrlPath(inPublicDir ? publicDir : root, file)}`\n }\n\n return {\n configs: await deriveConfigs(nextConfig),\n interfaces: deriveInterfaces(nextConfig.app, {isApp}),\n manifest: await extractManifest({...params, applicationId: id, iconUrl}),\n }\n },\n // A studio's root resolves to `sanity.config.*` but its interfaces live in\n // `sanity.cli.*` — watch that too. Apps already root at `sanity.cli.*`.\n extraWatchFilenames: isApp ? undefined : ['sanity.cli.js', 'sanity.cli.ts'],\n output,\n update: async (patch) => {\n if (\n !exposesSet.changed({\n configs: patch.configs,\n interfaces: patch.interfaces,\n })\n ) {\n registration.update(patch)\n return\n }\n // Rebuild the remote *before* patching the registry — the patch reloads the\n // page, which must re-fetch a remote that already exposes the new interface.\n const rebuiltServer = await onInterfaceSetChange?.()\n // Commit only after a successful rebuild, so a thrown one retries next pass.\n exposesSet.commit({\n configs: patch.configs,\n interfaces: patch.interfaces,\n })\n // The recreated server can bind a different port (non-strict ports).\n if (rebuiltServer) liveServer = rebuiltServer\n registration.update(rebuiltServer ? {...patch, ...serverAddress(rebuiltServer)} : patch)\n },\n workDir,\n })\n\n return {\n close: async () => {\n registration.release()\n await watcher.close()\n },\n path: dashboardPath({\n id,\n interfaces,\n slug: identity?.slug,\n type: isApp ? 'coreApp' : 'studio',\n }),\n }\n}\n"],"names":["relative","getCliConfigUncached","isWorkbenchApp","isWorkbenchConfig","deriveInterfaces","readAppIcon","toUrlPath","resolveWorkbenchConfig","formatWorkbenchAppErrors","validateWorkbenchApp","deriveConfigs","trackExposesSet","dashboardPath","getRegisteredServers","localAppIdentity","registerDevServer","startDevManifestWatcher","reportConfigErrors","app","output","errors","length","warn","serverAddress","server","resolvedHost","config","host","addr","httpServer","address","https","Boolean","port","startDevServerRegistration","options","cliConfig","extractManifest","isApp","onInterfaceSetChange","workDir","appHost","appPort","interfaces","configs","workbenchApp","undefined","id","appType","slug","applicationId","deployment","appId","identity","organizationId","devServer","find","served","error","exit","close","registration","projectId","api","type","exposesSet","liveServer","watcher","extract","params","nextConfig","iconUrl","icon","file","base","publicDir","root","inPublicDir","startsWith","manifest","extraWatchFilenames","update","patch","changed","rebuiltServer","commit","release","path"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,YAAW;AAElC,SAAwBC,oBAAoB,QAAoB,mBAAkB;AAGlF,SAAQC,cAAc,EAAEC,iBAAiB,QAAO,qBAAoB;AACpE,SAAQC,gBAAgB,QAAO,4BAA2B;AAC1D,SAAQC,WAAW,EAAEC,SAAS,QAAO,uBAAs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,UAAU;YAC9B,IACA;gBACAkB,aAAaoB,MAAM,CAACC;gBACpB;YACF;YACA,4EAA4E;YAC5E,6EAA6E;YAC7E,MAAME,gBAAgB,MAAM7C;YAC5B,6EAA6E;YAC7E0B,WAAWoB,MAAM,CAAC;gBAChBzC,SAASsC,MAAMtC,OAAO;gBACtBD,YAAYuC,MAAMvC,UAAU;YAC9B;YACA,qEAAqE;YACrE,IAAIyC,eAAelB,aAAakB;YAChCvB,aAAaoB,MAAM,CAACG,gBAAgB;gBAAC,GAAGF,KAAK;gBAAE,GAAG3D,cAAc6D,cAAc;YAAA,IAAIF;QACpF;QACA1C;IACF;IAEA,OAAO;QACLoB,OAAO;YACLC,aAAayB,OAAO;YACpB,MAAMnB,QAAQP,KAAK;QACrB;QACA2B,MAAM3E,cAAc;YAClBmC;YACAJ;YACAM,MAAMI,UAAUJ;YAChBe,MAAM1B,QAAQ,YAAY;QAC5B;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/dev/startDevServerRegistration.ts"],"sourcesContent":["import {relative, resolve} from 'node:path'\n\nimport {type CliConfig, getCliConfigUncached, type Output} from '@sanity/cli-core'\nimport {type ViteDevServer} from 'vite'\n\nimport {isWorkbenchApp, isWorkbenchConfig} from '../../defineApp.js'\nimport {deriveInterfaces} from '../../deriveInterfaces.js'\nimport {readAppIcon, toUrlPath} from '../../readAppIcon.js'\nimport {resolveWorkbenchConfig} from '../../resolveWorkbenchConfig.js'\nimport {formatWorkbenchAppErrors, validateWorkbenchApp} from '../../validateWorkbenchApp.js'\nimport {deriveConfigs} from './deriveConfigs.js'\nimport {trackExposesSet} from './exposesSetId.js'\nimport {\n dashboardPath,\n type DevServerManifest,\n getRegisteredServers,\n localAppIdentity,\n registerDevServer,\n} from './registry.js'\nimport {startDevManifestWatcher} from './startDevManifestWatcher.js'\n\ninterface DevServerRegistrationOptions {\n cliConfig: CliConfig\n /**\n * Extract the project manifest to inline into the registry. The caller owns the\n * studio-vs-app split (manifest formats are CLI-domain); registration re-derives\n * the interface set alongside it.\n */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n /** Where this server serves the app's icon. */\n iconUrl?: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n isApp: boolean\n output: Output\n server: ViteDevServer\n workDir: string\n\n /**\n * Rebuild the app's federation remote when its interface set changes, awaited\n * *before* the registry patch — the patch reloads the workbench page, which must\n * re-fetch a remote that already exposes the new interface. Resolves with the\n * recreated server so the entry gets its actual address (non-strict ports may\n * shift it); must reject if the restart produces no server, so the set stays\n * uncommitted and the next save retries instead of advertising a dead port.\n */\n onInterfaceSetChange?: () => Promise<ViteDevServer>\n}\n\ninterface DevServerRegistrationHandle {\n close: () => Promise<void>\n\n /** Where the Dashboard opens this server; unset when it can't open it there. */\n path?: string\n}\n\n/**\n * Log any app validation errors without aborting. Unlike build and deploy, dev\n * stays up on an invalid app so the author sees the errors and fixes them live on\n * the next save. A config is not an app — it isn't validated by the app schema\n * (which would spuriously demand a slug/title), so skip it here.\n */\nfunction reportConfigErrors(app: CliConfig['app'], output: Output): void {\n if (isWorkbenchConfig(app)) return\n const errors = validateWorkbenchApp(app)\n if (errors.length === 0) return\n output.warn(formatWorkbenchAppErrors(errors))\n}\n\n/** The address the server actually bound — the live socket, which can differ from the configured port under non-strict ports. */\nfunction serverAddress(server: ViteDevServer) {\n const resolvedHost = server.config.server.host\n const addr = server.httpServer?.address()\n return {\n host: typeof resolvedHost === 'string' ? resolvedHost : 'localhost',\n https: Boolean(server.config.server.https),\n port: typeof addr === 'object' && addr ? addr.port : server.config.server.port,\n }\n}\n\nfunction servedUrl(server: ViteDevServer, file: string): string {\n // Vite serves `public/` at the root, and warns on every request for `/public/...`.\n const {base, publicDir, root} = server.config\n const inPublicDir = Boolean(publicDir) && !relative(publicDir, file).startsWith('..')\n const {host, https, port} = serverAddress(server)\n\n return `${https ? 'https' : 'http'}://${host}:${port}${base}${toUrlPath(inPublicDir ? publicDir : root, file)}`\n}\n\n/**\n * Register the dev server in the registry and watch its config for manifest +\n * interface changes. The workbench reads the entry to locate and render the\n * server; the watcher keeps it current as `sanity.cli.ts` is edited.\n */\nexport async function startDevServerRegistration(\n options: DevServerRegistrationOptions,\n): Promise<DevServerRegistrationHandle> {\n const {cliConfig, extractManifest, isApp, onInterfaceSetChange, output, server, workDir} = options\n\n const {host: appHost, https, port: appPort} = serverAddress(server)\n\n reportConfigErrors(cliConfig.app, output)\n\n // Forwarded alongside (not inside) the manifest so the workbench renders local\n // panels/workers and reads the configs without a deploy.\n const interfaces = deriveInterfaces(cliConfig.app, {\n iconUrl: (iconPath) => servedUrl(server, resolve(workDir, iconPath)),\n isApp,\n })\n const configs = await deriveConfigs(cliConfig)\n\n const workbenchApp = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined\n const config = resolveWorkbenchConfig(cliConfig)\n // A config runs alongside the app it configures, so give it its own id\n // namespace — sharing the app's slug would make the two indistinguishable here.\n const id = config ? `config:${config.appType}` : workbenchApp?.slug\n const applicationId = workbenchApp ? cliConfig.deployment?.appId : undefined\n // Identity is resolved and the reference composed here, so the workbench reads\n // both off the registry entry instead of recomposing them.\n const identity = workbenchApp ? localAppIdentity(workbenchApp) : undefined\n\n // The Dashboard tells local apps apart by their bus id and by the application\n // they stand in for.\n const organizationId = cliConfig.app?.organizationId\n const devServer = getRegisteredServers().find(\n (server) =>\n server.organizationId === organizationId &&\n (server.id === id || (applicationId && server.applicationId === applicationId)),\n )\n\n if (id && devServer) {\n const served =\n devServer.id === id\n ? `\"${id}\" is already served`\n : `\"${id}\" is the same application as \"${devServer.id}\", served`\n output.error(\n `${served} by another dev server running on port ${devServer.port}, ` +\n \"so the Dashboard can't tell them apart and this one stays out of it. Stop that server first.\",\n {exit: false},\n )\n return {close: async () => {}}\n }\n\n const registration = registerDevServer({\n applicationId,\n configs,\n host: appHost,\n https,\n id,\n interfaces,\n organizationId,\n port: appPort,\n projectId: cliConfig?.api?.projectId,\n ...identity,\n type: isApp ? 'coreApp' : 'studio',\n workDir,\n })\n\n const exposesSet = trackExposesSet({configs, interfaces})\n let liveServer = server\n\n const watcher = await startDevManifestWatcher({\n // Re-derive every pass (don't omit): the registry patch is a shallow merge,\n // so omitting would wipe the registered set.\n extract: async (params) => {\n const nextConfig = await getCliConfigUncached(params.workDir)\n reportConfigErrors(nextConfig.app, output)\n\n let iconUrl: string | undefined\n if (isApp && isWorkbenchApp(nextConfig.app) && nextConfig.app.icon) {\n // Read in full so an image a deploy would reject warns here, while editing.\n const {file} = await readAppIcon(workDir, nextConfig.app.icon)\n iconUrl = servedUrl(liveServer, file)\n }\n\n return {\n configs: await deriveConfigs(nextConfig),\n interfaces: deriveInterfaces(nextConfig.app, {\n iconUrl: (iconPath) => servedUrl(liveServer, resolve(workDir, iconPath)),\n isApp,\n }),\n manifest: await extractManifest({...params, applicationId: id, iconUrl}),\n }\n },\n // A studio's root resolves to `sanity.config.*` but its interfaces live in\n // `sanity.cli.*` — watch that too. Apps already root at `sanity.cli.*`.\n extraWatchFilenames: isApp ? undefined : ['sanity.cli.js', 'sanity.cli.ts'],\n output,\n update: async (patch) => {\n if (\n !exposesSet.changed({\n configs: patch.configs,\n interfaces: patch.interfaces,\n })\n ) {\n registration.update(patch)\n return\n }\n // Rebuild the remote *before* patching the registry — the patch reloads the\n // page, which must re-fetch a remote that already exposes the new interface.\n const rebuiltServer = await onInterfaceSetChange?.()\n // Commit only after a successful rebuild, so a thrown one retries next pass.\n exposesSet.commit({\n configs: patch.configs,\n interfaces: patch.interfaces,\n })\n // The recreated server can bind a different port (non-strict ports).\n if (rebuiltServer) liveServer = rebuiltServer\n registration.update(rebuiltServer ? {...patch, ...serverAddress(rebuiltServer)} : patch)\n },\n workDir,\n })\n\n return {\n close: async () => {\n registration.release()\n await watcher.close()\n },\n path: dashboardPath({\n id,\n interfaces,\n slug: identity?.slug,\n type: isApp ? 'coreApp' : 'studio',\n }),\n }\n}\n"],"names":["relative","resolve","getCliConfigUncached","isWorkbenchApp","isWorkbenchConfig","deriveInterfaces","readAppIcon","toUrlPath","resolveWorkbenchConfig","formatWorkbenchAppErrors","validateWorkbenchApp","deriveConfigs","trackExposesSet","dashboardPath","getRegisteredServers","localAppIdentity","registerDevServer","startDevManifestWatcher","reportConfigErrors","app","output","errors","length","warn","serverAddress","server","resolvedHost","config","host","addr","httpServer","address","https","Boolean","port","servedUrl","file","base","publicDir","root","inPublicDir","startsWith","startDevServerRegistration","options","cliConfig","extractManifest","isApp","onInterfaceSetChange","workDir","appHost","appPort","interfaces","iconUrl","iconPath","configs","workbenchApp","undefined","id","appType","slug","applicationId","deployment","appId","identity","organizationId","devServer","find","served","error","exit","close","registration","projectId","api","type","exposesSet","liveServer","watcher","extract","params","nextConfig","icon","manifest","extraWatchFilenames","update","patch","changed","rebuiltServer","commit","release","path"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAE3C,SAAwBC,oBAAoB,QAAoB,mBAAkB;AAGlF,SAAQC,cAAc,EAAEC,iBAAiB,QAAO,qBAAoB;AACpE,SAAQC,gBAAgB,QAAO,4BAA2B;AAC1D,SAAQC,WAAW,EAAEC,SAAS,QAAO,uBAAsB;AAC3D,SAAQC,sBAAsB,QAAO,kCAAiC;AACtE,SAAQC,wBAAwB,EAAEC,oBAAoB,QAAO,gCAA+B;AAC5F,SAAQC,aAAa,QAAO,qBAAoB;AAChD,SAAQC,eAAe,QAAO,oBAAmB;AACjD,SACEC,aAAa,EAEbC,oBAAoB,EACpBC,gBAAgB,EAChBC,iBAAiB,QACZ,gBAAe;AACtB,SAAQC,uBAAuB,QAAO,+BAA8B;AAuCpE;;;;;CAKC,GACD,SAASC,mBAAmBC,GAAqB,EAAEC,MAAc;IAC/D,IAAIhB,kBAAkBe,MAAM;IAC5B,MAAME,SAASX,qBAAqBS;IACpC,IAAIE,OAAOC,MAAM,KAAK,GAAG;IACzBF,OAAOG,IAAI,CAACd,yBAAyBY;AACvC;AAEA,+HAA+H,GAC/H,SAASG,cAAcC,MAAqB;IAC1C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AE,GAAG7D,cAAc+D,cAAc;YAAA,IAAIF;QACpF;QACArC;IACF;IAEA,OAAO;QACLsB,OAAO;YACLC,aAAakB,OAAO;YACpB,MAAMZ,QAAQP,KAAK;QACrB;QACAoB,MAAM7E,cAAc;YAClB4C;YACAN;YACAQ,MAAMI,UAAUJ;YAChBe,MAAM5B,QAAQ,YAAY;QAC5B;IACF;AACF"}
@@ -11,7 +11,7 @@ const previewDebug = subdebug('preview');
11
11
  * `readBuiltManifest`) so the command shows the same "run sanity build" hint the
12
12
  * studio preview path does; real I/O errors surface as themselves.
13
13
  */ export async function serveBuiltApplication(options) {
14
- const { cacheDir, httpHost, httpPort, icon, outDir, workDir } = options;
14
+ const { cacheDir, httpHost, httpPort, icons = [], outDir, workDir } = options;
15
15
  await readBuiltManifest(outDir);
16
16
  const config = {
17
17
  // Serve at the root so `mf-manifest.json` and its `publicPath: 'auto'` chunks
@@ -25,17 +25,19 @@ const previewDebug = subdebug('preview');
25
25
  configFile: false,
26
26
  logLevel: 'warn',
27
27
  mode: 'production',
28
- plugins: icon ? [
28
+ plugins: [
29
29
  {
30
30
  configurePreviewServer (server) {
31
- server.middlewares.use(icon.path, (_req, res)=>{
32
- res.setHeader('Content-Type', icon.contentType);
33
- res.end(icon.image);
34
- });
31
+ for (const icon of icons){
32
+ server.middlewares.use(icon.path, (_req, res)=>{
33
+ res.setHeader('Content-Type', icon.contentType);
34
+ res.end(icon.image);
35
+ });
36
+ }
35
37
  },
36
38
  name: 'sanity:app-icon'
37
39
  }
38
- ] : [],
40
+ ],
39
41
  preview: {
40
42
  host: httpHost,
41
43
  port: httpPort,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/preview/serveBuiltApplication.ts"],"sourcesContent":["import {subdebug} from '@sanity/cli-core'\nimport {type ImageFile} from '@sanity/cli-core/images'\nimport {type InlineConfig, preview} from 'vite'\n\nimport {readBuiltManifest} from '../build/readBuiltManifest.js'\n\nconst previewDebug = subdebug('preview')\n\nexport interface BuiltApplicationServer {\n close: () => Promise<void>\n /** Routable host the remote is reachable at, for the registry's remote URL. */\n host: string\n /** Port Vite bound — may differ from the requested one under non-strict ports. */\n port: number\n}\n\n/**\n * Serve a built workbench app's `dist` as static files over a Vite `preview`\n * server, so its manifest and referenced assets are reachable exactly as\n * a live `sanity dev` remote would be — the workbench then federates it in.\n *\n * A missing federation build surfaces as `BUILD_NOT_FOUND` (from\n * `readBuiltManifest`) so the command shows the same \"run sanity build\" hint the\n * studio preview path does; real I/O errors surface as themselves.\n */\nexport async function serveBuiltApplication(options: {\n cacheDir: string\n httpHost: string\n httpPort: number\n /** The app's icon, served at `path`: it lives in the project, not in `outDir`. */\n icon?: ImageFile & {path: string}\n outDir: string\n workDir: string\n}): Promise<BuiltApplicationServer> {\n const {cacheDir, httpHost, httpPort, icon, outDir, workDir} = options\n\n await readBuiltManifest(outDir)\n\n const config: InlineConfig = {\n // Serve at the root so `mf-manifest.json` and its `publicPath: 'auto'` chunks\n // resolve under the registered remote URL.\n base: '/',\n // Needed for vite to serve `outDir` itself rather than `outDir/dist`.\n build: {outDir},\n cacheDir,\n configFile: false,\n logLevel: 'warn',\n mode: 'production',\n plugins: icon\n ? [\n {\n configurePreviewServer(server) {\n server.middlewares.use(icon.path, (_req, res) => {\n res.setHeader('Content-Type', icon.contentType)\n res.end(icon.image)\n })\n },\n name: 'sanity:app-icon',\n },\n ]\n : [],\n preview: {host: httpHost, port: httpPort, strictPort: false},\n root: workDir,\n }\n\n previewDebug('Serving built remote from %s', outDir)\n const server = await preview(config)\n\n const addr = server.httpServer.address()\n const port = typeof addr === 'object' && addr ? addr.port : httpPort\n\n return {\n // Drop idle keep-alive sockets so shutdown doesn't stall on a browser that\n // kept the connection open — otherwise `close` waits out the teardown grace.\n // `closeAllConnections` isn't on Vite's `HttpServer` type, but is on the\n // underlying node server (18.2+); the optional call tolerates its absence.\n close: () =>\n new Promise((resolve, reject) => {\n server.httpServer.close((err) => (err ? reject(err) : resolve()))\n ;(server.httpServer as {closeAllConnections?: () => void}).closeAllConnections?.()\n }),\n host: httpHost,\n port,\n }\n}\n"],"names":["subdebug","preview","readBuiltManifest","previewDebug","serveBuiltApplication","options","cacheDir","httpHost","httpPort","icon","outDir","workDir","config","base","build","configFile","logLevel","mode","plugins","configurePreviewServer","server","middlewares","use","path","_req","res","setHeader","contentType","end","image","name","host","port","strictPort","root","addr","httpServer","address","close","Promise","resolve","reject","err","closeAllConnections"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AAEzC,SAA2BC,OAAO,QAAO,OAAM;AAE/C,SAAQC,iBAAiB,QAAO,gCAA+B;AAE/D,MAAMC,eAAeH,SAAS;AAU9B;;;;;;;;CAQC,GACD,OAAO,eAAeI,sBAAsBC,OAQ3C;IACC,MAAM,EAACC,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGN;IAE9D,MAAMH,kBAAkBQ;IAExB,MAAME,SAAuB;QAC3B,8EAA8E;QAC9E,2CAA2C;QAC3CC,MAAM;QACN,sEAAsE;QACtEC,OAAO;YAACJ;QAAM;QACdJ;QACAS,YAAY;QACZC,UAAU;QACVC,MAAM;QACNC,SAAST,OACL;YACE;gBACEU,wBAAuBC,MAAM;oBAC3BA,OAAOC,WAAW,CAACC,GAAG,CAACb,KAAKc,IAAI,EAAE,CAACC,MAAMC;wBACvCA,IAAIC,SAAS,CAAC,gBAAgBjB,KAAKkB,WAAW;wBAC9CF,IAAIG,GAAG,CAACnB,KAAKoB,KAAK;oBACpB;gBACF;gBACAC,MAAM;YACR;SACD,GACD,EAAE;QACN7B,SAAS;YAAC8B,MAAMxB;YAAUyB,MAAMxB;YAAUyB,YAAY;QAAK;QAC3DC,MAAMvB;IACR;IAEAR,aAAa,gCAAgCO;IAC7C,MAAMU,SAAS,MAAMnB,QAAQW;IAE7B,MAAMuB,OAAOf,OAAOgB,UAAU,CAACC,OAAO;IACtC,MAAML,OAAO,OAAOG,SAAS,YAAYA,OAAOA,KAAKH,IAAI,GAAGxB;IAE5D,OAAO;QACL,2EAA2E;QAC3E,6EAA6E;QAC7E,yEAAyE;QACzE,2EAA2E;QAC3E8B,OAAO,IACL,IAAIC,QAAQ,CAACC,SAASC;gBACpBrB,OAAOgB,UAAU,CAACE,KAAK,CAAC,CAACI,MAASA,MAAMD,OAAOC,OAAOF;gBACpDpB,OAAOgB,UAAU,CAAwCO,mBAAmB;YAChF;QACFZ,MAAMxB;QACNyB;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/preview/serveBuiltApplication.ts"],"sourcesContent":["import {subdebug} from '@sanity/cli-core'\nimport {type ImageFile} from '@sanity/cli-core/images'\nimport {type InlineConfig, preview} from 'vite'\n\nimport {readBuiltManifest} from '../build/readBuiltManifest.js'\n\nconst previewDebug = subdebug('preview')\n\nexport interface BuiltApplicationServer {\n close: () => Promise<void>\n /** Routable host the remote is reachable at, for the registry's remote URL. */\n host: string\n /** Port Vite bound — may differ from the requested one under non-strict ports. */\n port: number\n}\n\n/**\n * Serve a built workbench app's `dist` as static files over a Vite `preview`\n * server, so its manifest and referenced assets are reachable exactly as\n * a live `sanity dev` remote would be — the workbench then federates it in.\n *\n * A missing federation build surfaces as `BUILD_NOT_FOUND` (from\n * `readBuiltManifest`) so the command shows the same \"run sanity build\" hint the\n * studio preview path does; real I/O errors surface as themselves.\n */\nexport async function serveBuiltApplication(options: {\n cacheDir: string\n httpHost: string\n httpPort: number\n /** The app's and views' icons, each served at its `path`: they live in the project, not in `outDir`. */\n icons?: readonly (ImageFile & {path: string})[]\n outDir: string\n workDir: string\n}): Promise<BuiltApplicationServer> {\n const {cacheDir, httpHost, httpPort, icons = [], outDir, workDir} = options\n\n await readBuiltManifest(outDir)\n\n const config: InlineConfig = {\n // Serve at the root so `mf-manifest.json` and its `publicPath: 'auto'` chunks\n // resolve under the registered remote URL.\n base: '/',\n // Needed for vite to serve `outDir` itself rather than `outDir/dist`.\n build: {outDir},\n cacheDir,\n configFile: false,\n logLevel: 'warn',\n mode: 'production',\n plugins: [\n {\n configurePreviewServer(server) {\n for (const icon of icons) {\n server.middlewares.use(icon.path, (_req, res) => {\n res.setHeader('Content-Type', icon.contentType)\n res.end(icon.image)\n })\n }\n },\n name: 'sanity:app-icon',\n },\n ],\n preview: {host: httpHost, port: httpPort, strictPort: false},\n root: workDir,\n }\n\n previewDebug('Serving built remote from %s', outDir)\n const server = await preview(config)\n\n const addr = server.httpServer.address()\n const port = typeof addr === 'object' && addr ? addr.port : httpPort\n\n return {\n // Drop idle keep-alive sockets so shutdown doesn't stall on a browser that\n // kept the connection open — otherwise `close` waits out the teardown grace.\n // `closeAllConnections` isn't on Vite's `HttpServer` type, but is on the\n // underlying node server (18.2+); the optional call tolerates its absence.\n close: () =>\n new Promise((resolve, reject) => {\n server.httpServer.close((err) => (err ? reject(err) : resolve()))\n ;(server.httpServer as {closeAllConnections?: () => void}).closeAllConnections?.()\n }),\n host: httpHost,\n port,\n }\n}\n"],"names":["subdebug","preview","readBuiltManifest","previewDebug","serveBuiltApplication","options","cacheDir","httpHost","httpPort","icons","outDir","workDir","config","base","build","configFile","logLevel","mode","plugins","configurePreviewServer","server","icon","middlewares","use","path","_req","res","setHeader","contentType","end","image","name","host","port","strictPort","root","addr","httpServer","address","close","Promise","resolve","reject","err","closeAllConnections"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AAEzC,SAA2BC,OAAO,QAAO,OAAM;AAE/C,SAAQC,iBAAiB,QAAO,gCAA+B;AAE/D,MAAMC,eAAeH,SAAS;AAU9B;;;;;;;;CAQC,GACD,OAAO,eAAeI,sBAAsBC,OAQ3C;IACC,MAAM,EAACC,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGN;IAEpE,MAAMH,kBAAkBQ;IAExB,MAAME,SAAuB;QAC3B,8EAA8E;QAC9E,2CAA2C;QAC3CC,MAAM;QACN,sEAAsE;QACtEC,OAAO;YAACJ;QAAM;QACdJ;QACAS,YAAY;QACZC,UAAU;QACVC,MAAM;QACNC,SAAS;YACP;gBACEC,wBAAuBC,MAAM;oBAC3B,KAAK,MAAMC,QAAQZ,MAAO;wBACxBW,OAAOE,WAAW,CAACC,GAAG,CAACF,KAAKG,IAAI,EAAE,CAACC,MAAMC;4BACvCA,IAAIC,SAAS,CAAC,gBAAgBN,KAAKO,WAAW;4BAC9CF,IAAIG,GAAG,CAACR,KAAKS,KAAK;wBACpB;oBACF;gBACF;gBACAC,MAAM;YACR;SACD;QACD9B,SAAS;YAAC+B,MAAMzB;YAAU0B,MAAMzB;YAAU0B,YAAY;QAAK;QAC3DC,MAAMxB;IACR;IAEAR,aAAa,gCAAgCO;IAC7C,MAAMU,SAAS,MAAMnB,QAAQW;IAE7B,MAAMwB,OAAOhB,OAAOiB,UAAU,CAACC,OAAO;IACtC,MAAML,OAAO,OAAOG,SAAS,YAAYA,OAAOA,KAAKH,IAAI,GAAGzB;IAE5D,OAAO;QACL,2EAA2E;QAC3E,6EAA6E;QAC7E,yEAAyE;QACzE,2EAA2E;QAC3E+B,OAAO,IACL,IAAIC,QAAQ,CAACC,SAASC;gBACpBtB,OAAOiB,UAAU,CAACE,KAAK,CAAC,CAACI,MAASA,MAAMD,OAAOC,OAAOF;gBACpDrB,OAAOiB,UAAU,CAAwCO,mBAAmB;YAChF;QACFZ,MAAMzB;QACN0B;IACF;AACF"}
@@ -25,12 +25,16 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
25
25
  */ export async function startWorkbenchPreview(options) {
26
26
  const { cacheDir, checkForDeprecatedAppId, cliConfig, extractManifest, httpHost, httpPort, isApp, outDir, output, reactStrictMode, workDir } = options;
27
27
  // Read before any server starts, so a bad icon path fails with nothing to tear down.
28
- const iconPath = isApp && isWorkbenchApp(cliConfig.app) ? cliConfig.app.icon : undefined;
29
- const icon = iconPath ? await readAppIcon(workDir, iconPath) : undefined;
30
- const servedIcon = icon && {
31
- ...icon,
32
- path: `/${toUrlPath(workDir, icon.file)}`
33
- };
28
+ const app = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined;
29
+ const appIcon = isApp ? app?.icon : undefined;
30
+ const iconUrlPath = (iconPath)=>`/${toUrlPath(workDir, path.resolve(workDir, iconPath))}`;
31
+ const icons = await Promise.all([
32
+ appIcon,
33
+ ...(app?.views ?? []).map((view)=>'icon' in view ? view.icon : undefined)
34
+ ].filter((iconPath)=>iconPath !== undefined).map(async (iconPath)=>({
35
+ ...await readAppIcon(workDir, iconPath),
36
+ path: iconUrlPath(iconPath)
37
+ })));
34
38
  const { close, closers, installSignalHandlers } = createServerLifecycle();
35
39
  const workbench = await startWorkbenchDevServer({
36
40
  cacheDir,
@@ -47,7 +51,7 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
47
51
  cacheDir,
48
52
  httpHost,
49
53
  httpPort: remotePort,
50
- icon: servedIcon,
54
+ icons,
51
55
  outDir,
52
56
  workDir
53
57
  }).catch(async (err)=>{
@@ -69,6 +73,7 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
69
73
  const configs = await deriveConfigs(cliConfig);
70
74
  const id = inlinedId ?? await buildAppId(workbench);
71
75
  const interfaces = deriveInterfaces(cliConfig.app, {
76
+ iconUrl: (iconPath)=>`http://${remote.host}:${remote.port}${iconUrlPath(iconPath)}`,
72
77
  isApp
73
78
  });
74
79
  const registration = registerDevServer({
@@ -80,7 +85,7 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
80
85
  manifest: await extractManifest({
81
86
  applicationId: id,
82
87
  configPath,
83
- iconUrl: servedIcon && `http://${remote.host}:${remote.port}${servedIcon.path}`,
88
+ iconUrl: appIcon && `http://${remote.host}:${remote.port}${iconUrlPath(appIcon)}`,
84
89
  workDir
85
90
  }),
86
91
  manifestUpdatedAt: new Date().toISOString(),
@@ -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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E;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 {resolveWorkbenchApp} from '../../resolveWorkbenchApp.js'\nimport {createServerLifecycle, toDisplayHost} from '../../util/serverOrchestration.js'\nimport {deriveConfigs} from '../dev/deriveConfigs.js'\nimport {\n dashboardPath,\n type DevServerManifest,\n localAppIdentity,\n registerDevServer,\n} from '../dev/registry.js'\nimport {startWorkbenchDevServer} from '../dev/startWorkbenchDevServer.js'\nimport {serveBuiltApplication} from './serveBuiltApplication.js'\n\nexport interface StartWorkbenchPreviewOptions {\n /** Directory for the workbench Vite server's dependency cache. */\n cacheDir: string\n /** CLI-domain `app.id`/`deployment.appId` deprecation check, run before registering. */\n checkForDeprecatedAppId: () => void\n cliConfig: CliConfig\n /** Extract the project manifest to inline into the registry (studio-vs-app handled by the CLI). */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n /** Where the preview serves the app's icon. */\n iconUrl?: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n httpHost: string\n httpPort: number\n isApp: boolean\n /** The built `dist` directory to serve as the federation remote. */\n outDir: string\n output: Output\n reactStrictMode: boolean\n workDir: string\n}\n\n/**\n * `sanity start` for a workbench app: serve a production build the way dev serves\n * a live one. The same singleton workbench shell renders it and the same registry\n * advertises it — only the remote differs, static files from the build output\n * instead of a live Vite dev server. There's no config watcher or rebuild: a\n * build is fixed, so nothing re-syncs.\n *\n * A running workbench claims the configured port, so the built remote binds the\n * next one. Without one the remote takes the configured port and announces its\n * own URL.\n */\nexport async function startWorkbenchPreview(\n options: StartWorkbenchPreviewOptions,\n): Promise<{close: () => Promise<void>}> {\n const {\n cacheDir,\n checkForDeprecatedAppId,\n cliConfig,\n extractManifest,\n httpHost,\n httpPort,\n isApp,\n outDir,\n output,\n reactStrictMode,\n workDir,\n } = options\n\n // Read before any server starts, so a bad icon path fails with nothing to tear down.\n const app = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined\n const appIcon = isApp ? app?.icon : undefined\n const iconUrlPath = (iconPath: string) =>\n `/${toUrlPath(workDir, path.resolve(workDir, iconPath))}`\n const icons = await Promise.all(\n [appIcon, ...(app?.views ?? []).map((view) => ('icon' in view ? view.icon : undefined))]\n .filter((iconPath) => iconPath !== undefined)\n .map(async (iconPath) => ({\n ...(await readAppIcon(workDir, iconPath)),\n path: iconUrlPath(iconPath),\n })),\n )\n\n const {close, closers, installSignalHandlers} = createServerLifecycle()\n\n const workbench = await startWorkbenchDevServer({\n cacheDir,\n cliConfig,\n httpHost,\n httpPort,\n output,\n reactStrictMode,\n workDir,\n })\n closers.push(workbench.close)\n\n const remotePort = workbench.workbenchAvailable ? workbench.workbenchPort + 1 : httpPort\n\n const remote = await serveBuiltApplication({\n cacheDir,\n httpHost,\n httpPort: remotePort,\n icons,\n outDir,\n workDir,\n }).catch(async (err) => {\n await close()\n throw err\n })\n closers.push(remote.close)\n\n let dashboardAppPath: string | undefined\n try {\n // Callers provide CLI-only validation and manifest extraction to keep them\n // out of workbench-cli.\n checkForDeprecatedAppId()\n const configPath = (await findProjectRoot(workDir)).path\n const workbench = resolveWorkbenchApp(cliConfig)\n\n if (!workbench) {\n throw new Error(\n '`sanity start` was invoked in an application that is not set up for the Dashboard',\n )\n }\n const inlinedId = await readInlinedAppId(outDir)\n const configs = await deriveConfigs(cliConfig)\n const id = inlinedId ?? (await buildAppId(workbench))\n const interfaces = deriveInterfaces(cliConfig.app, {\n iconUrl: (iconPath) => `http://${remote.host}:${remote.port}${iconUrlPath(iconPath)}`,\n isApp,\n })\n const registration = registerDevServer({\n applicationId: cliConfig.deployment?.appId,\n configs,\n host: remote.host,\n id,\n interfaces,\n manifest: await extractManifest({\n applicationId: id,\n configPath,\n iconUrl: appIcon && `http://${remote.host}:${remote.port}${iconUrlPath(appIcon)}`,\n workDir,\n }),\n manifestUpdatedAt: new Date().toISOString(),\n port: remote.port,\n projectId: cliConfig?.api?.projectId,\n ...localAppIdentity(workbench),\n type: isApp ? 'coreApp' : 'studio',\n workDir,\n })\n closers.push(async () => registration.release())\n dashboardAppPath = dashboardPath({\n id,\n interfaces,\n slug: workbench.slug,\n type: isApp ? 'coreApp' : 'studio',\n })\n } catch (err) {\n await close()\n throw err\n }\n\n if (workbench.workbenchAvailable) {\n const appUrl = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}${dashboardAppPath ?? ''}`\n output.log(`Dashboard preview server started at ${styleText(['blue', 'underline'], appUrl)}`)\n } else {\n const remoteUrl = `http://${toDisplayHost(remote.host)}:${remote.port}`\n output.log(`Serving build at ${styleText(['blue', 'underline'], remoteUrl)}`)\n }\n\n installSignalHandlers()\n\n return {close}\n}\n\n/** The id the build inlined into its bundle, or undefined when absent. */\nasync function readInlinedAppId(outDir: string): Promise<string | undefined> {\n try {\n return (await readFile(path.join(outDir, SANITY_APP_ID_FILE), 'utf8')).trim() || undefined\n } catch {\n return undefined\n }\n}\n"],"names":["readFile","path","styleText","findProjectRoot","buildAppId","SANITY_APP_ID_FILE","isWorkbenchApp","deriveInterfaces","readAppIcon","toUrlPath","resolveWorkbenchApp","createServerLifecycle","toDisplayHost","deriveConfigs","dashboardPath","localAppIdentity","registerDevServer","startWorkbenchDevServer","serveBuiltApplication","startWorkbenchPreview","options","cacheDir","checkForDeprecatedAppId","cliConfig","extractManifest","httpHost","httpPort","isApp","outDir","output","reactStrictMode","workDir","app","undefined","appIcon","icon","iconUrlPath","iconPath","resolve","icons","Promise","all","views","map","view","filter","close","closers","installSignalHandlers","workbench","push","remotePort","workbenchAvailable","workbenchPort","remote","catch","err","dashboardAppPath","configPath","Error","inlinedId","readInlinedAppId","configs","id","interfaces","iconUrl","host","port","registration","applicationId","deployment","appId","manifest","manifestUpdatedAt","Date","toISOString","projectId","api","type","release","slug","appUrl","log","remoteUrl","join","trim"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAwBC,eAAe,QAAoB,mBAAkB;AAE7E,SAAQC,UAAU,EAAEC,kBAAkB,QAAO,iBAAgB;AAC7D,SAAQC,cAAc,QAAO,qBAAoB;AACjD,SAAQC,gBAAgB,QAAO,4BAA2B;AAC1D,SAAQC,WAAW,EAAEC,SAAS,QAAO,uBAAsB;AAC3D,SAAQC,mBAAmB,QAAO,+BAA8B;AAChE,SAAQC,qBAAqB,EAAEC,aAAa,QAAO,oCAAmC;AACtF,SAAQC,aAAa,QAAO,0BAAyB;AACrD,SACEC,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AAI;YACpBF,MAAMnD,QAAQ,YAAY;QAC5B;IACF,EAAE,OAAO6B,KAAK;QACZ,MAAMV;QACN,MAAMU;IACR;IAEA,IAAIP,UAAUG,kBAAkB,EAAE;QAChC,MAAM6B,SAAS,CAAC,OAAO,EAAErE,cAAcqC,UAAUxB,QAAQ,EAAE,CAAC,EAAEwB,UAAUI,aAAa,GAAGI,oBAAoB,IAAI;QAChH5B,OAAOqD,GAAG,CAAC,CAAC,oCAAoC,EAAEhF,UAAU;YAAC;YAAQ;SAAY,EAAE+E,SAAS;IAC9F,OAAO;QACL,MAAME,YAAY,CAAC,OAAO,EAAEvE,cAAc0C,OAAOY,IAAI,EAAE,CAAC,EAAEZ,OAAOa,IAAI,EAAE;QACvEtC,OAAOqD,GAAG,CAAC,CAAC,iBAAiB,EAAEhF,UAAU;YAAC;YAAQ;SAAY,EAAEiF,YAAY;IAC9E;IAEAnC;IAEA,OAAO;QAACF;IAAK;AACf;AAEA,wEAAwE,GACxE,eAAee,iBAAiBjC,MAAc;IAC5C,IAAI;QACF,OAAO,AAAC,CAAA,MAAM5B,SAASC,KAAKmF,IAAI,CAACxD,QAAQvB,qBAAqB,OAAM,EAAGgF,IAAI,MAAMpD;IACnF,EAAE,OAAM;QACN,OAAOA;IACT;AACF"}
package/dist/contract.js CHANGED
@@ -42,7 +42,8 @@ const PanelDockSchema = z.object({
42
42
  order: z.optional(z.number())
43
43
  });
44
44
  /** @internal */ export const ViewPlacementMetadataSchema = z.object({
45
- dock: DockSchema
45
+ dock: z.optional(DockSchema),
46
+ icon: z.optional(z.string())
46
47
  });
47
48
  /**
48
49
  * A tile's interface metadata: its footprint `size` and an optional `order`
@@ -112,7 +113,8 @@ function interfaceDeclarationFields(kind) {
112
113
  const PanelViewSchema = z.object({
113
114
  surface: z.literal('panel'),
114
115
  ...interfaceDeclarationFields('View'),
115
- dock: z.optional(PanelDockSchema)
116
+ dock: z.optional(PanelDockSchema),
117
+ icon: z.optional(z.string())
116
118
  });
117
119
  /** @public */ export function definePanelView(view) {
118
120
  return {
@@ -123,7 +125,8 @@ const PanelViewSchema = z.object({
123
125
  const WindowViewSchema = z.object({
124
126
  surface: z.literal('window'),
125
127
  ...interfaceDeclarationFields('View'),
126
- dock: z.optional(DockSchema)
128
+ dock: z.optional(DockSchema),
129
+ icon: z.optional(z.string())
127
130
  });
128
131
  /** @public */ export function defineWindowView(view) {
129
132
  return {
@@ -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;CA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Y,GACZ,OAAO,SAASwC,eAAeN,IAAyB;IACtD,OAAO;QAAC,GAAGA,IAAI;QAAEH,SAAS;IAAM;AAClC;AAEA,cAAc,GACd,OAAO,MAAMU,6BAA6BnD,EAAEoD,kBAAkB,CAAC,WAAW;IACxEP;IACAL;IACAO;IACAE;CACD,EAAC;AAKF,MAAMI,kBAAkBrD,EAAEc,MAAM,CAAC;IAC/BwC,MAAMtD,EAAE0C,OAAO,CAAC;IAChB,GAAGJ,2BAA2B,aAAa;AAC7C;AAQA,YAAY,GACZ,OAAO,SAASiB,gBAAgBC,SAA+B;IAC7D,OAAO;QAAC,GAAGA,SAAS;QAAEF,MAAM;IAAQ;AACtC;AAEA,cAAc,GACd,OAAO,MAAMG,6BAA6BzD,EAAEoD,kBAAkB,CAAC,QAAQ;IAACC;CAAgB,EAAC;AAEzF,MAAMK,0BAA0B1D,EAAEc,MAAM,CAAC;IACvC,GAAGkB,2BAA2B,QAAQ;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\n/**\n * A view component. The return is opaque so the runtime helpers carry no React\n * dependency — the generated artifact renders it with the app's own React.\n * @public\n */\nexport type ViewComponent<TProps> = (props: TProps) => unknown\n\n/** @public */\nexport interface ViewComponentBaseProps<TView> {\n view: TView\n}\n\n/** Component slots per view surface; windows load outside the component artifact path. @internal */\nexport const VIEW_COMPONENTS = {\n asset_source: ['asset_source'],\n panel: ['title', 'panel'],\n tile: ['tile'],\n window: [],\n} as const satisfies Record<string, readonly string[]>\n\n/** @public */\nexport type ViewSurface = keyof typeof VIEW_COMPONENTS\n\n/**\n * A tile's footprint family — the shape it occupies on the dashboard. Modelled\n * on iOS WidgetKit families, not a linear scale: `banner` is full-width and\n * shallow, which a `small`→`large` magnitude can't express. The host maps a\n * family to a layout slot; the component reads it to render per footprint.\n * @public\n */\nexport const TileSizeSchema = z.enum(['small', 'large', 'banner'])\n\n/** @public */\nexport type TileSize = z.infer<typeof TileSizeSchema>\n\n/** @public */\nexport type WebWorkerType = 'worker'\n\n/**\n * @deprecated Use `WebWorkerType`.\n * @public\n */\nexport type ServiceType = WebWorkerType\n\nconst DockGroupSchema = z.enum(['system', 'applications'])\n\n/** @public */\nexport type DockGroup = z.output<typeof DockGroupSchema>\n\n/** @internal */\nexport const DockSchema = z.object({\n group: z.optional(DockGroupSchema),\n order: z.optional(z.number()),\n})\n\n/** @internal */\nexport type Dock = z.infer<typeof DockSchema>\n\nconst PanelDockSchema = z.object({order: z.optional(z.number())})\n\n/** @internal */\nexport const ViewPlacementMetadataSchema = z.object({\n dock: z.optional(DockSchema),\n icon: z.optional(z.string()),\n})\n\n/** @internal */\nexport type ViewPlacementMetadata = z.infer<typeof ViewPlacementMetadataSchema>\n\n/**\n * A tile's interface metadata: its footprint `size` and an optional `order`\n * the dashboard sorts on, ascending. Both are authored as top-level view fields\n * (see {@link InterfaceDeclarationSchema}) but stored on the record as metadata.\n * @internal\n */\nexport const TileInterfaceMetadataSchema = z.object({\n order: z.optional(z.number()),\n size: TileSizeSchema,\n})\n\n/** @internal */\nexport type TileInterfaceMetadata = z.infer<typeof TileInterfaceMetadataSchema>\n\n/**\n * The contract version each interface type advertises, so the host can check it\n * renders/runs what it expects.\n * @internal\n */\nconst INTERFACE_CONTRACT_VERSIONS = {\n asset_source: VIEW_CONTRACT_VERSION,\n panel: VIEW_CONTRACT_VERSION,\n tile: VIEW_CONTRACT_VERSION,\n window: WINDOW_CONTRACT_VERSION,\n worker: WEB_WORKER_CONTRACT_VERSION,\n} as const satisfies Record<string, number>\n\n/** Every interface type an app exposes — a window, a view, or a web worker. */\nexport type InterfaceKind = keyof typeof INTERFACE_CONTRACT_VERSIONS\n\n/** @internal */\nexport function interfaceContractVersion(kind: InterfaceKind): string {\n return String(INTERFACE_CONTRACT_VERSIONS[kind])\n}\n\n/**\n * The module-federation id a build exposes an interface at. Dev stamps the same\n * id a deploy would, so the workbench loads a local interface like a deployed one.\n * @internal\n */\nexport function interfaceModuleId(kind: string, name: string): string {\n switch (kind) {\n case 'asset_source':\n case 'panel':\n case 'tile': {\n return `views/${name}`\n }\n case 'window': {\n return 'App'\n }\n case 'worker': {\n return `services/${name}`\n }\n default: {\n throw new Error(`Cannot derive a moduleId for unknown interface kind: ${kind}`)\n }\n }\n}\n\n// Shared `name` + `src`; `kind` only tailors the validation message.\nfunction extensionDeclarationFields(kind: 'Field' | 'View' | 'Web worker') {\n const pattern = /^[a-zA-Z0-9_-]+$/\n return {\n name: z.string().check(z.regex(pattern, `${kind} \\`name\\` must match ${pattern}`)),\n src: z.string(),\n }\n}\n\n// Every interface shares `name` + `src` + a display `title`,\n// which Brett requires on the record each becomes.\nfunction interfaceDeclarationFields(kind: 'View' | 'Web worker') {\n return {\n ...extensionDeclarationFields(kind),\n title: z.string(`${kind} \\`title\\` is required`),\n }\n}\n\nconst PanelViewSchema = z.object({\n surface: z.literal('panel'),\n ...interfaceDeclarationFields('View'),\n dock: z.optional(PanelDockSchema),\n icon: z.optional(z.string()),\n})\n\n/** @public */\nexport type PanelViewDeclaration = z.output<typeof PanelViewSchema>\n\n/** @public */\nexport type DefinePanelViewInput = Omit<PanelViewDeclaration, 'surface'>\n\n/** @public */\nexport function definePanelView(view: DefinePanelViewInput): PanelViewDeclaration {\n return {...view, surface: 'panel'}\n}\n\nconst WindowViewSchema = z.object({\n surface: z.literal('window'),\n ...interfaceDeclarationFields('View'),\n dock: z.optional(DockSchema),\n icon: z.optional(z.string()),\n})\n\n/** @public */\nexport type WindowViewDeclaration = z.output<typeof WindowViewSchema>\n\n/** @public */\nexport type DefineWindowViewInput = Omit<WindowViewDeclaration, 'surface'>\n\n/** @public */\nexport function defineWindowView(view: DefineWindowViewInput): WindowViewDeclaration {\n return {...view, surface: 'window'}\n}\n\nconst AssetSourceViewSchema = z.object({\n surface: z.literal('asset_source'),\n ...interfaceDeclarationFields('View'),\n})\n\n/** @public */\nexport type AssetSourceViewDeclaration = z.output<typeof AssetSourceViewSchema>\n\n/** @public */\nexport type DefineAssetSourceViewInput = Omit<AssetSourceViewDeclaration, 'surface'>\n\n/** @public */\nexport function defineAssetSourceView(\n view: DefineAssetSourceViewInput,\n): AssetSourceViewDeclaration {\n return {...view, surface: 'asset_source'}\n}\n\nconst TileViewSchema = z.object({\n surface: z.literal('tile'),\n ...interfaceDeclarationFields('View'),\n /** Sort position within its layout track, ascending. Optional. */\n order: z.optional(z.number()),\n /** Footprint family the dashboard lays the tile out by. */\n size: TileSizeSchema,\n})\n\n/** @public */\nexport type TileViewDeclaration = z.output<typeof TileViewSchema>\n\n/** @public */\nexport type DefineTileViewInput = Omit<TileViewDeclaration, 'surface'>\n\n/** @public */\nexport function defineTileView(view: DefineTileViewInput): TileViewDeclaration {\n return {...view, surface: 'tile'}\n}\n\n/** @internal */\nexport const InterfaceDeclarationSchema = z.discriminatedUnion('surface', [\n WindowViewSchema,\n PanelViewSchema,\n AssetSourceViewSchema,\n TileViewSchema,\n])\n\n/** @public */\nexport type ViewDeclaration = z.output<typeof InterfaceDeclarationSchema>\n\nconst WebWorkerSchema = z.object({\n type: z.literal('worker'),\n ...interfaceDeclarationFields('Web worker'),\n})\n\n/** @public */\nexport type WebWorkerDeclaration = z.output<typeof WebWorkerSchema>\n\n/** @public */\nexport type DefineWebWorkerInput = Omit<WebWorkerDeclaration, 'type'>\n\n/** @public */\nexport function defineWebWorker(webWorker: DefineWebWorkerInput): WebWorkerDeclaration {\n return {...webWorker, type: 'worker'}\n}\n\n/** @internal */\nexport const WebWorkerDeclarationSchema = z.discriminatedUnion('type', [WebWorkerSchema])\n\nconst MediaLibraryFieldSchema = z.object({\n ...extensionDeclarationFields('Field'),\n public: z.optional(z.boolean()),\n title: z.string(),\n})\n\n/**\n * Stamped where the config crosses a boundary so the authoring model doesn't carry a constant discriminator.\n * @internal\n */\nexport const INSTALLATION_CONFIG_TYPE = 'installation_config'\n\n// `appType` is stamped by `unstable_defineMediaLibrary`, never authored.\nconst MediaLibraryConfigSchema = z.object({\n appType: z.literal('media-library'),\n fields: z\n .array(MediaLibraryFieldSchema)\n .check(\n z.refine(\n (fields) => new Set(fields.map((field) => field.name)).size === fields.length,\n 'Field `name` must be unique within a media library',\n ),\n ),\n})\n\n/**\n * A workbench config's built value, keyed by `appType`; deploys as a versioned\n * snapshot, not an interface.\n * @internal\n */\nexport const ConfigSchema = z.discriminatedUnion('appType', [MediaLibraryConfigSchema])\n\n/**\n * The `{appType, fields}` config value the build expands into a federation\n * remote and the deploy summarizes.\n * @internal\n */\nexport type WorkbenchConfigValue = z.output<typeof ConfigSchema>\n"],"names":["z","VIEW_CONTRACT_VERSION","WEB_WORKER_CONTRACT_VERSION","WINDOW_CONTRACT_VERSION","MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION","VIEW_COMPONENTS","asset_source","panel","tile","window","TileSizeSchema","enum","DockGroupSchema","DockSchema","object","group","optional","order","number","PanelDockSchema","ViewPlacementMetadataSchema","dock","icon","string","TileInterfaceMetadataSchema","size","INTERFACE_CONTRACT_VERSIONS","worker","interfaceContractVersion","kind","String","interfaceModuleId","name","Error","extensionDeclarationFields","pattern","check","regex","src","interfaceDeclarationFields","title","PanelViewSchema","surface","literal","definePanelView","view","WindowViewSchema","defineWindowView","AssetSourceViewSchema","defineAssetSourceView","TileViewSchema","defineTileView","InterfaceDeclarationSchema","discriminatedUnion","WebWorkerSchema","type","defineWebWorker","webWorker","WebWorkerDeclarationSchema","MediaLibraryFieldSchema","public","boolean","INSTALLATION_CONFIG_TYPE","MediaLibraryConfigSchema","appType","fields","array","refine","Set","map","field","length","ConfigSchema"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B,+EAA+E;AAC/E,kEAAkE;AAClE,qCAAqC;AAErC,cAAc,GACd,OAAO,MAAMC,wBAAwB,EAAC;AAEtC,cAAc,GACd,OAAO,MAAMC,8BAA8B,EAAC;AAE5C,cAAc,GACd,OAAO,MAAMC,0BAA0B,EAAC;AAExC,cAAc,GACd,OAAO,MAAMC,wCAAwC,EAAC;AActD,kGAAkG,GAClG,OAAO,MAAMC,kBAAkB;IAC7BC,cAAc;QAAC;KAAe;IAC9BC,OAAO;QAAC;QAAS;KAAQ;IACzBC,MAAM;QAAC;KAAO;IACdC,QAAQ,EAAE;AACZ,EAAsD;AAKtD;;;;;;CAMC,GACD,OAAO,MAAMC,iBAAiBV,EAAEW,IAAI,CAAC;IAAC;IAAS;IAAS;CAAS,EAAC;AAclE,MAAMC,kBAAkBZ,EAAEW,IAAI,CAAC;IAAC;IAAU;CAAe;AAKzD,cAAc,GACd,OAAO,MAAME,aAAab,EAAEc,MAAM,CAAC;IACjCC,OAAOf,EAAEgB,QAAQ,CAACJ;IAClBK,OAAOjB,EAAEgB,QAAQ,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GACZ,OAAO,SAASyC,eAAeN,IAAyB;IACtD,OAAO;QAAC,GAAGA,IAAI;QAAEH,SAAS;IAAM;AAClC;AAEA,cAAc,GACd,OAAO,MAAMU,6BAA6BpD,EAAEqD,kBAAkB,CAAC,WAAW;IACxEP;IACAL;IACAO;IACAE;CACD,EAAC;AAKF,MAAMI,kBAAkBtD,EAAEc,MAAM,CAAC;IAC/ByC,MAAMvD,EAAE2C,OAAO,CAAC;IAChB,GAAGJ,2BAA2B,aAAa;AAC7C;AAQA,YAAY,GACZ,OAAO,SAASiB,gBAAgBC,SAA+B;IAC7D,OAAO;QAAC,GAAGA,SAAS;QAAEF,MAAM;IAAQ;AACtC;AAEA,cAAc,GACd,OAAO,MAAMG,6BAA6B1D,EAAEqD,kBAAkB,CAAC,QAAQ;IAACC;CAAgB,EAAC;AAEzF,MAAMK,0BAA0B3D,EAAEc,MAAM,CAAC;IACvC,GAAGoB,2BAA2B,QAAQ;IACtC0B,QAAQ5D,EAAEgB,QAAQ,CAAChB,EAAE6D,OAAO;IAC5BrB,OAAOxC,EAAEuB,MAAM;AACjB;AAEA;;;CAGC,GACD,OAAO,MAAMuC,2BAA2B,sBAAqB;AAE7D,yEAAyE;AACzE,MAAMC,2BAA2B/D,EAAEc,MAAM,CAAC;IACxCkD,SAAShE,EAAE2C,OAAO,CAAC;IACnBsB,QAAQjE,EACLkE,KAAK,CAACP,yBACNvB,KAAK,CACJpC,EAAEmE,MAAM,CACN,CAACF,SAAW,IAAIG,IAAIH,OAAOI,GAAG,CAAC,CAACC,QAAUA,MAAMtC,IAAI,GAAGP,IAAI,KAAKwC,OAAOM,MAAM,EAC7E;AAGR;AAEA;;;;CAIC,GACD,OAAO,MAAMC,eAAexE,EAAEqD,kBAAkB,CAAC,WAAW;IAACU;CAAyB,EAAC"}
@@ -4,9 +4,10 @@ import { isWorkbenchApp } 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
  }
@@ -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,MAAM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B,IAAIA,KAAKL,OAAO,KAAK,QAAQ;gBAC3B,OAAO;oBACL,GAAGV,OAAOe,KAAKL,OAAO,EAAEK,KAAK;oBAC7BC,UACED,KAAKH,KAAK,KAAKjB,YAAY;wBAACsB,MAAMF,KAAKE,IAAI;oBAAA,IAAI;wBAACL,OAAOG,KAAKH,KAAK;wBAAEK,MAAMF,KAAKE,IAAI;oBAAA;oBACpFP,SAASK,KAAKL,OAAO;gBACvB;YACF;YACA,IAAIK,KAAKL,OAAO,KAAK,WAAWK,KAAKL,OAAO,KAAK,UAAU;gBACzD,OAAO;oBACL,GAAGV,OAAOe,KAAKL,OAAO,EAAEK,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} 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', {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","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,S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,OAAOf,YAAYD,IAAIgB,KAAK;gBAAA,EAAE;gBAC9Ea,UAAUX;gBACVE,SAAS;YACX;SACD;KACN;AACH"}
@@ -2,13 +2,13 @@ import { relative, resolve, sep } from 'node:path';
2
2
  import { getErrorMessage } from '@sanity/cli-core/errors';
3
3
  import { readImageFile } from '@sanity/cli-core/images';
4
4
  /**
5
- * Read the image `app.icon` points at. The path is relative to the project
5
+ * Read the image an `icon` path points at. The path is relative to the project
6
6
  * root and must stay inside it.
7
7
  * @internal
8
8
  */ export async function readAppIcon(workDir, iconPath) {
9
9
  const file = resolve(workDir, iconPath);
10
10
  if (relative(workDir, file).startsWith('..')) {
11
- throw new Error(`App icon "${iconPath}" is outside the project directory. Move the image into the project and update \`app.icon\` in sanity.cli.ts.`);
11
+ throw new Error(`Icon "${iconPath}" is outside the project directory. Move the image into the project and update the icon path in sanity.cli.ts.`);
12
12
  }
13
13
  try {
14
14
  return {
@@ -16,7 +16,7 @@ import { readImageFile } from '@sanity/cli-core/images';
16
16
  file
17
17
  };
18
18
  } catch (err) {
19
- throw new Error(`Can't use app icon "${iconPath}": ${getErrorMessage(err)}`, {
19
+ throw new Error(`Can't use icon "${iconPath}": ${getErrorMessage(err)}`, {
20
20
  cause: err
21
21
  });
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/readAppIcon.ts"],"sourcesContent":["import {relative, resolve, sep} from 'node:path'\n\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {type ImageFile, readImageFile} from '@sanity/cli-core/images'\n\n/**\n * An app's `icon` image, read from its project.\n * @internal\n */\nexport interface AppIcon extends ImageFile {\n /** Absolute path to the file. */\n file: string\n}\n\n/**\n * Read the image `app.icon` points at. The path is relative to the project\n * root and must stay inside it.\n * @internal\n */\nexport async function readAppIcon(workDir: string, iconPath: string): Promise<AppIcon> {\n const file = resolve(workDir, iconPath)\n if (relative(workDir, file).startsWith('..')) {\n throw new Error(\n `App icon \"${iconPath}\" is outside the project directory. Move the image into the project and update \\`app.icon\\` in sanity.cli.ts.`,\n )\n }\n\n try {\n return {...(await readImageFile(file)), file}\n } catch (err) {\n throw new Error(`Can't use app icon \"${iconPath}\": ${getErrorMessage(err)}`, {cause: err})\n }\n}\n\n/**\n * The URL path a server rooted at `dir` serves `file` at, without a leading slash.\n * @internal\n */\nexport function toUrlPath(dir: string, file: string): string {\n return relative(dir, file)\n .split(sep)\n .map((segment) => encodeURIComponent(segment))\n .join('/')\n}\n"],"names":["relative","resolve","sep","getErrorMessage","readImageFile","readAppIcon","workDir","iconPath","file","startsWith","Error","err","cause","toUrlPath","dir","split","map","segment","encodeURIComponent","join"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,EAAEC,GAAG,QAAO,YAAW;AAEhD,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAwBC,aAAa,QAAO,0BAAyB;AAWrE;;;;CAIC,GACD,OAAO,eAAeC,YAAYC,OAAe,EAAEC,QAAgB;IACjE,MAAMC,OAAOP,QAAQK,SAASC;IAC9B,IAAIP,SAASM,SAASE,MAAMC,UAAU,CAAC,OAAO;QAC5C,MAAM,IAAIC,MACR,CAAC,UAAU,EAAEH,SAAS,6GAA6G,CAAC;IAExI;IAEA,IAAI;QACF,OAAO;YAAC,GAAI,MAAMH,cAAcI,KAAK;YAAGA;QAAI;IAC9C,EAAE,OAAOG,KAAK;QACZ,MAAM,IAAID,MAAM,CAAC,oBAAoB,EAAEH,SAAS,GAAG,EAAEJ,gBAAgBQ,MAAM,EAAE;YAACC,OAAOD;QAAG;IAC1F;AACF;AAEA;;;CAGC,GACD,OAAO,SAASE,UAAUC,GAAW,EAAEN,IAAY;IACjD,OAAOR,SAASc,KAAKN,MAClBO,KAAK,CAACb,KACNc,GAAG,CAAC,CAACC,UAAYC,mBAAmBD,UACpCE,IAAI,CAAC;AACV"}
1
+ {"version":3,"sources":["../src/readAppIcon.ts"],"sourcesContent":["import {relative, resolve, sep} from 'node:path'\n\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {type ImageFile, readImageFile} from '@sanity/cli-core/images'\n\n/**\n * An app's or view's `icon` image, read from its project.\n * @internal\n */\nexport interface AppIcon extends ImageFile {\n /** Absolute path to the file. */\n file: string\n}\n\n/**\n * Read the image an `icon` path points at. The path is relative to the project\n * root and must stay inside it.\n * @internal\n */\nexport async function readAppIcon(workDir: string, iconPath: string): Promise<AppIcon> {\n const file = resolve(workDir, iconPath)\n if (relative(workDir, file).startsWith('..')) {\n throw new Error(\n `Icon \"${iconPath}\" is outside the project directory. Move the image into the project and update the icon path in sanity.cli.ts.`,\n )\n }\n\n try {\n return {...(await readImageFile(file)), file}\n } catch (err) {\n throw new Error(`Can't use icon \"${iconPath}\": ${getErrorMessage(err)}`, {cause: err})\n }\n}\n\n/**\n * The URL path a server rooted at `dir` serves `file` at, without a leading slash.\n * @internal\n */\nexport function toUrlPath(dir: string, file: string): string {\n return relative(dir, file)\n .split(sep)\n .map((segment) => encodeURIComponent(segment))\n .join('/')\n}\n"],"names":["relative","resolve","sep","getErrorMessage","readImageFile","readAppIcon","workDir","iconPath","file","startsWith","Error","err","cause","toUrlPath","dir","split","map","segment","encodeURIComponent","join"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,EAAEC,GAAG,QAAO,YAAW;AAEhD,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAwBC,aAAa,QAAO,0BAAyB;AAWrE;;;;CAIC,GACD,OAAO,eAAeC,YAAYC,OAAe,EAAEC,QAAgB;IACjE,MAAMC,OAAOP,QAAQK,SAASC;IAC9B,IAAIP,SAASM,SAASE,MAAMC,UAAU,CAAC,OAAO;QAC5C,MAAM,IAAIC,MACR,CAAC,MAAM,EAAEH,SAAS,8GAA8G,CAAC;IAErI;IAEA,IAAI;QACF,OAAO;YAAC,GAAI,MAAMH,cAAcI,KAAK;YAAGA;QAAI;IAC9C,EAAE,OAAOG,KAAK;QACZ,MAAM,IAAID,MAAM,CAAC,gBAAgB,EAAEH,SAAS,GAAG,EAAEJ,gBAAgBQ,MAAM,EAAE;YAACC,OAAOD;QAAG;IACtF;AACF;AAEA;;;CAGC,GACD,OAAO,SAASE,UAAUC,GAAW,EAAEN,IAAY;IACjD,OAAOR,SAASc,KAAKN,MAClBO,KAAK,CAACb,KACNc,GAAG,CAAC,CAACC,UAAYC,mBAAmBD,UACpCE,IAAI,CAAC;AACV"}
@@ -127,6 +127,17 @@ export async function updateApplication(applicationId, update) {
127
127
  url: `/applications/${applicationId}/icon`
128
128
  });
129
129
  }
130
+ /** Upload an app or panel interface's icon, replacing any it has. */ export async function setInterfaceIcon(applicationId, interfaceId, icon) {
131
+ const client = await getClient();
132
+ await client.request({
133
+ body: icon.image,
134
+ headers: {
135
+ 'Content-Type': icon.contentType
136
+ },
137
+ method: 'PUT',
138
+ url: `/applications/${applicationId}/interfaces/${interfaceId}/icon`
139
+ });
140
+ }
130
141
  /**
131
142
  * Deploy a new active version to an existing application. `mfManifest` is the
132
143
  * build's federation manifest; `tarball` is omitted for an external application,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/services/applications.ts"],"sourcesContent":["import {PassThrough} from 'node:stream'\nimport {type Gzip} from 'node:zlib'\n\nimport {type AppVisibility, getGlobalCliClient} from '@sanity/cli-core'\nimport {type ImageFile} from '@sanity/cli-core/images'\nimport {isStaging} from '@sanity/cli-core/util'\nimport FormData from 'form-data'\n\nimport {type TileInterfaceMetadata, type ViewPlacementMetadata} from '../contract.js'\nimport {APP_WORKBENCH_API_VERSION} from './apiVersion.js'\n\nexport type ApplicationType = 'coreApp' | 'studio'\n\nexport interface Application {\n id: string\n organizationId: string\n slug: string | null\n title: string\n type: ApplicationType\n\n /** Set when the customer serves the build; such an application never receives a tarball. */\n externalUrl?: string\n}\n\ninterface BrettInterfaceBase {\n moduleId: string\n name: string\n title: string\n version: string\n}\n\n/**\n * An interface as Brett stores it, discriminated on `type`. `moduleId` is\n * remote-relative — the host prepends the app's id. Brett assigns the id.\n * @internal\n */\nexport type BrettInterface =\n | (BrettInterfaceBase & {metadata: null; type: 'asset_source'})\n | (BrettInterfaceBase & {metadata: null; type: 'worker'})\n | (BrettInterfaceBase & {metadata: TileInterfaceMetadata; type: 'tile'})\n | (BrettInterfaceBase & {metadata: ViewPlacementMetadata | null; type: 'app'})\n | (BrettInterfaceBase & {metadata: ViewPlacementMetadata | null; type: 'panel'})\n\n/**\n * A resource a deployment may interact with, as Brett stores it. Per-deployment\n * and forbidden for singletons (the server 400s).\n */\nexport interface BrettAccess {\n resourceId: string\n resourceType: 'canvas' | 'dashboard' | 'dataset' | 'media-library'\n}\n\n/** A studio workspace as Brett stores it. */\nexport interface BrettWorkspace {\n dataset: string\n projectId: string\n /** Lexicon schema descriptor id; Brett requires one per workspace. */\n schemaDescriptorId: string\n\n basePath?: string\n icon?: string\n name?: string\n subtitle?: string\n title?: string\n}\n\nexport function getWorkbenchUrl(organizationId: string): string {\n return `https://${organizationId}.${isStaging() ? 'run.sanity.work' : 'sanity.run'}`\n}\n\n/** Where a deployed application is served on its organization's workbench. */\nexport function getApplicationUrl(\n application: Pick<Application, 'id' | 'organizationId' | 'slug' | 'type'>,\n): string {\n const segment = application.type === 'studio' ? 'studios' : 'applications'\n return `${getWorkbenchUrl(application.organizationId)}/${segment}/${application.slug ?? application.id}`\n}\n\nasync function getClient() {\n return getGlobalCliClient({apiVersion: APP_WORKBENCH_API_VERSION, requireUser: true})\n}\n\nexport async function getApplication(applicationId: string): Promise<Application | null> {\n const client = await getClient()\n try {\n return await client.request({url: `/applications/${applicationId}`})\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode === 404) return null\n throw err\n }\n}\n\nexport async function getOrganizationApplication(\n organizationId: string,\n idOrSlug: string,\n signal?: AbortSignal,\n): Promise<\n (Application & {activeDeployment: {createdAt: string; deployedBy: string} | null}) | null\n> {\n const client = await getGlobalCliClient({\n apiVersion: APP_WORKBENCH_API_VERSION,\n ignoreWarnings: ['This is an experimental API version', 'which will change without warning'],\n requireUser: true,\n })\n try {\n return await client.request({\n query: {include: 'activeDeployment'},\n signal,\n url: `/organizations/${organizationId}/applications/${idOrSlug}`,\n })\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode === 404) return null\n throw err\n }\n}\n\n/** Every application in an organization, in one page (`limit=none`). */\nexport async function listApplications(organizationId: string): Promise<Application[]> {\n const client = await getClient()\n const {data}: {data: Application[]} = await client.request({\n query: {limit: 'none', organizationId},\n url: '/applications',\n })\n return data\n}\n\n/**\n * Create an application record (no deployment), so the CLI can build with the\n * returned id, then ship it via {@link createDeployment}.\n */\nexport async function createApplication(options: {\n /** The origin a customer serves the build from; Brett then never hosts a bundle for it. */\n externalUrl?: string\n isSingleton?: boolean\n name?: string\n organizationId: string\n projectId?: string\n slug: string\n title: string\n type: ApplicationType\n visibility?: AppVisibility\n}): Promise<Application> {\n const {externalUrl, isSingleton, name, organizationId, projectId, slug, title, type, visibility} =\n options\n const client = await getClient()\n return client.request({\n body: {\n organizationId,\n slug,\n title,\n type,\n // Identity, distinct from the slug address. Omitted → Brett defaults it to slug.\n ...(name ? {name} : {}),\n // Brett requires `isSingleton` on `POST /applications`, so the request\n // builder keeps forwarding it even though the CLI itself never sets it.\n ...(isSingleton === undefined ? {} : {isSingleton}),\n ...(visibility ? {visibility} : {}),\n ...(externalUrl ? {externalUrl} : {}),\n // Studio config is set once, at create — it's immutable on redeploy.\n ...(projectId ? {config: {studio: {projectId}}} : {}),\n },\n method: 'POST',\n url: `/applications`,\n })\n}\n\n/** Mutable application fields the deploy flow patches after create. */\nexport interface ApplicationUpdate {\n /** The address the application is served at; renaming moves it. */\n slug?: string\n title?: string\n visibility?: AppVisibility\n}\n\n// Patch an application's mutable fields.\nexport async function updateApplication(\n applicationId: string,\n update: ApplicationUpdate,\n): Promise<void> {\n const client = await getClient()\n await client.request({body: update, method: 'PATCH', url: `/applications/${applicationId}`})\n}\n\n/** Upload the application's icon, replacing any it has. */\nexport async function setApplicationIcon(applicationId: string, icon: ImageFile): Promise<void> {\n const client = await getClient()\n await client.request({\n body: icon.image,\n headers: {'Content-Type': icon.contentType},\n method: 'PUT',\n url: `/applications/${applicationId}/icon`,\n })\n}\n\n/** Remove the application's icon; removing one that isn't set changes nothing. */\nexport async function removeApplicationIcon(applicationId: string): Promise<void> {\n const client = await getClient()\n await client.request({method: 'DELETE', url: `/applications/${applicationId}/icon`})\n}\n\n/**\n * Deploy a new active version to an existing application. `mfManifest` is the\n * build's federation manifest; `tarball` is omitted for an external application,\n * whose build the customer serves themselves.\n */\nexport async function createDeployment(options: {\n access?: readonly BrettAccess[]\n applicationId: string\n interfaces: readonly BrettInterface[]\n isAutoUpdating: boolean\n mfManifest: Record<string, unknown>\n tarball?: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n}): Promise<{id: string}> {\n const {\n access,\n applicationId,\n interfaces,\n isAutoUpdating,\n mfManifest,\n tarball,\n version,\n workspaces,\n } = options\n const formData = new FormData()\n formData.append('isAutoUpdating', isAutoUpdating.toString())\n appendDeploymentParts(formData, {access, interfaces, mfManifest, tarball, version, workspaces})\n return request(`/applications/${applicationId}/deployments`, formData)\n}\n\n/** Soft-deletes the application and all its deployments; already deleted counts as done. */\nexport async function deleteApplication(applicationId: string): Promise<void> {\n const client = await getClient()\n try {\n await client.request({method: 'DELETE', url: `/applications/${applicationId}`})\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode !== 404) throw err\n }\n}\n\nfunction appendDeploymentParts(\n formData: FormData,\n {\n access,\n interfaces,\n mfManifest,\n tarball,\n version,\n workspaces,\n }: {\n access?: readonly BrettAccess[]\n interfaces: readonly BrettInterface[]\n mfManifest: Record<string, unknown>\n tarball?: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n },\n): void {\n formData.append('version', version)\n appendJson(formData, 'interfaces', interfaces)\n // Studio-only — the server rejects a workspaces part on non-studio types.\n if (workspaces?.length) appendJson(formData, 'workspaces', workspaces)\n // Per-deployment; forbidden for singletons, so callers omit it there.\n if (access?.length) appendJson(formData, 'access', access)\n appendJson(formData, 'mfManifest', mfManifest)\n // Last: the server requires every field part to precede the tarball.\n if (tarball) {\n formData.append('tarball', tarball, {contentType: 'application/gzip', filename: 'app.tar.gz'})\n }\n}\n\n/** Structured parts must arrive as JSON so the server parses them. */\nfunction appendJson(formData: FormData, name: string, value: unknown): void {\n formData.append(name, JSON.stringify(value), {contentType: 'application/json'})\n}\n\nasync function request<T>(url: string, formData: FormData): Promise<T> {\n const client = await getClient()\n return client.request({\n body: formData.pipe(new PassThrough()),\n headers: formData.getHeaders(),\n method: 'POST',\n url,\n })\n}\n"],"names":["PassThrough","getGlobalCliClient","isStaging","FormData","APP_WORKBENCH_API_VERSION","getWorkbenchUrl","organizationId","getApplicationUrl","application","segment","type","slug","id","getClient","apiVersion","requireUser","getApplication","applicationId","client","request","url","err","statusCode","getOrganizationApplication","idOrSlug","signal","ignoreWarnings","query","include","listApplications","data","limit","createApplication","options","externalUrl","isSingleton","name","projectId","title","visibility","body","undefined","config","studio","method","updateApplication","update","setApplicationIcon","icon","image","headers","contentType","removeApplicationIcon","createDeployment","access","interfaces","isAutoUpdating","mfManifest","tarball","version","workspaces","formData","append","toString","appendDeploymentParts","deleteApplication","appendJson","length","filename","value","JSON","stringify","pipe","getHeaders"],"mappings":"AAAA,SAAQA,WAAW,QAAO,cAAa;AAGvC,SAA4BC,kBAAkB,QAAO,mBAAkB;AAEvE,SAAQC,SAAS,QAAO,wBAAuB;AAC/C,OAAOC,cAAc,YAAW;AAGhC,SAAQC,yBAAyB,QAAO,kBAAiB;AAyDzD,OAAO,SAASC,gBAAgBC,cAAsB;IACpD,OAAO,CAAC,QAAQ,EAAEA,eAAe,CAAC,EAAEJ,cAAc,oBAAoB,cAAc;AACtF;AAEA,4EAA4E,GAC5E,OAAO,SAASK,kBACdC,WAAyE;IAEzE,MAAMC,UAAUD,YAAYE,IAAI,KAAK,WAAW,YAAY;IAC5D,OAAO,GAAGL,gBAAgBG,YAAYF,cAAc,EAAE,CAAC,EAAEG,QAAQ,CAAC,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eAAehC,QAAWC,GAAW,EAAEyC,QAAkB;IACvD,MAAM3C,SAAS,MAAML;IACrB,OAAOK,OAAOC,OAAO,CAAC;QACpBqB,MAAMqB,SAASW,IAAI,CAAC,IAAIxE;QACxBkD,SAASW,SAASY,UAAU;QAC5B7B,QAAQ;QACRxB;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/services/applications.ts"],"sourcesContent":["import {PassThrough} from 'node:stream'\nimport {type Gzip} from 'node:zlib'\n\nimport {type AppVisibility, getGlobalCliClient} from '@sanity/cli-core'\nimport {type ImageFile} from '@sanity/cli-core/images'\nimport {isStaging} from '@sanity/cli-core/util'\nimport FormData from 'form-data'\n\nimport {type TileInterfaceMetadata, type ViewPlacementMetadata} from '../contract.js'\nimport {APP_WORKBENCH_API_VERSION} from './apiVersion.js'\n\nexport type ApplicationType = 'coreApp' | 'studio'\n\nexport interface Application {\n id: string\n organizationId: string\n slug: string | null\n title: string\n type: ApplicationType\n\n /** Set when the customer serves the build; such an application never receives a tarball. */\n externalUrl?: string\n}\n\ninterface BrettInterfaceBase {\n moduleId: string\n name: string\n title: string\n version: string\n}\n\n/**\n * An interface as Brett stores it, discriminated on `type`. `moduleId` is\n * remote-relative — the host prepends the app's id. Brett assigns the id.\n * @internal\n */\nexport type BrettInterface =\n | (BrettInterfaceBase & {metadata: null; type: 'asset_source'})\n | (BrettInterfaceBase & {metadata: null; type: 'worker'})\n | (BrettInterfaceBase & {metadata: TileInterfaceMetadata; type: 'tile'})\n | (BrettInterfaceBase & {metadata: ViewPlacementMetadata | null; type: 'app'})\n | (BrettInterfaceBase & {metadata: ViewPlacementMetadata | null; type: 'panel'})\n\n/**\n * A resource a deployment may interact with, as Brett stores it. Per-deployment\n * and forbidden for singletons (the server 400s).\n */\nexport interface BrettAccess {\n resourceId: string\n resourceType: 'canvas' | 'dashboard' | 'dataset' | 'media-library'\n}\n\n/** A studio workspace as Brett stores it. */\nexport interface BrettWorkspace {\n dataset: string\n projectId: string\n /** Lexicon schema descriptor id; Brett requires one per workspace. */\n schemaDescriptorId: string\n\n basePath?: string\n icon?: string\n name?: string\n subtitle?: string\n title?: string\n}\n\nexport function getWorkbenchUrl(organizationId: string): string {\n return `https://${organizationId}.${isStaging() ? 'run.sanity.work' : 'sanity.run'}`\n}\n\n/** Where a deployed application is served on its organization's workbench. */\nexport function getApplicationUrl(\n application: Pick<Application, 'id' | 'organizationId' | 'slug' | 'type'>,\n): string {\n const segment = application.type === 'studio' ? 'studios' : 'applications'\n return `${getWorkbenchUrl(application.organizationId)}/${segment}/${application.slug ?? application.id}`\n}\n\nasync function getClient() {\n return getGlobalCliClient({apiVersion: APP_WORKBENCH_API_VERSION, requireUser: true})\n}\n\nexport async function getApplication(applicationId: string): Promise<Application | null> {\n const client = await getClient()\n try {\n return await client.request({url: `/applications/${applicationId}`})\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode === 404) return null\n throw err\n }\n}\n\nexport async function getOrganizationApplication(\n organizationId: string,\n idOrSlug: string,\n signal?: AbortSignal,\n): Promise<\n (Application & {activeDeployment: {createdAt: string; deployedBy: string} | null}) | null\n> {\n const client = await getGlobalCliClient({\n apiVersion: APP_WORKBENCH_API_VERSION,\n ignoreWarnings: ['This is an experimental API version', 'which will change without warning'],\n requireUser: true,\n })\n try {\n return await client.request({\n query: {include: 'activeDeployment'},\n signal,\n url: `/organizations/${organizationId}/applications/${idOrSlug}`,\n })\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode === 404) return null\n throw err\n }\n}\n\n/** Every application in an organization, in one page (`limit=none`). */\nexport async function listApplications(organizationId: string): Promise<Application[]> {\n const client = await getClient()\n const {data}: {data: Application[]} = await client.request({\n query: {limit: 'none', organizationId},\n url: '/applications',\n })\n return data\n}\n\n/**\n * Create an application record (no deployment), so the CLI can build with the\n * returned id, then ship it via {@link createDeployment}.\n */\nexport async function createApplication(options: {\n /** The origin a customer serves the build from; Brett then never hosts a bundle for it. */\n externalUrl?: string\n isSingleton?: boolean\n name?: string\n organizationId: string\n projectId?: string\n slug: string\n title: string\n type: ApplicationType\n visibility?: AppVisibility\n}): Promise<Application> {\n const {externalUrl, isSingleton, name, organizationId, projectId, slug, title, type, visibility} =\n options\n const client = await getClient()\n return client.request({\n body: {\n organizationId,\n slug,\n title,\n type,\n // Identity, distinct from the slug address. Omitted → Brett defaults it to slug.\n ...(name ? {name} : {}),\n // Brett requires `isSingleton` on `POST /applications`, so the request\n // builder keeps forwarding it even though the CLI itself never sets it.\n ...(isSingleton === undefined ? {} : {isSingleton}),\n ...(visibility ? {visibility} : {}),\n ...(externalUrl ? {externalUrl} : {}),\n // Studio config is set once, at create — it's immutable on redeploy.\n ...(projectId ? {config: {studio: {projectId}}} : {}),\n },\n method: 'POST',\n url: `/applications`,\n })\n}\n\n/** Mutable application fields the deploy flow patches after create. */\nexport interface ApplicationUpdate {\n /** The address the application is served at; renaming moves it. */\n slug?: string\n title?: string\n visibility?: AppVisibility\n}\n\n// Patch an application's mutable fields.\nexport async function updateApplication(\n applicationId: string,\n update: ApplicationUpdate,\n): Promise<void> {\n const client = await getClient()\n await client.request({body: update, method: 'PATCH', url: `/applications/${applicationId}`})\n}\n\n/** Upload the application's icon, replacing any it has. */\nexport async function setApplicationIcon(applicationId: string, icon: ImageFile): Promise<void> {\n const client = await getClient()\n await client.request({\n body: icon.image,\n headers: {'Content-Type': icon.contentType},\n method: 'PUT',\n url: `/applications/${applicationId}/icon`,\n })\n}\n\n/** Remove the application's icon; removing one that isn't set changes nothing. */\nexport async function removeApplicationIcon(applicationId: string): Promise<void> {\n const client = await getClient()\n await client.request({method: 'DELETE', url: `/applications/${applicationId}/icon`})\n}\n\n/** Upload an app or panel interface's icon, replacing any it has. */\nexport async function setInterfaceIcon(\n applicationId: string,\n interfaceId: string,\n icon: ImageFile,\n): Promise<void> {\n const client = await getClient()\n await client.request({\n body: icon.image,\n headers: {'Content-Type': icon.contentType},\n method: 'PUT',\n url: `/applications/${applicationId}/interfaces/${interfaceId}/icon`,\n })\n}\n\n/**\n * Deploy a new active version to an existing application. `mfManifest` is the\n * build's federation manifest; `tarball` is omitted for an external application,\n * whose build the customer serves themselves.\n */\nexport async function createDeployment(options: {\n access?: readonly BrettAccess[]\n applicationId: string\n interfaces: readonly BrettInterface[]\n isAutoUpdating: boolean\n mfManifest: Record<string, unknown>\n tarball?: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n}): Promise<{id: string; interfaces: {id: string; name: string; type: BrettInterface['type']}[]}> {\n const {\n access,\n applicationId,\n interfaces,\n isAutoUpdating,\n mfManifest,\n tarball,\n version,\n workspaces,\n } = options\n const formData = new FormData()\n formData.append('isAutoUpdating', isAutoUpdating.toString())\n appendDeploymentParts(formData, {access, interfaces, mfManifest, tarball, version, workspaces})\n return request(`/applications/${applicationId}/deployments`, formData)\n}\n\n/** Soft-deletes the application and all its deployments; already deleted counts as done. */\nexport async function deleteApplication(applicationId: string): Promise<void> {\n const client = await getClient()\n try {\n await client.request({method: 'DELETE', url: `/applications/${applicationId}`})\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode !== 404) throw err\n }\n}\n\nfunction appendDeploymentParts(\n formData: FormData,\n {\n access,\n interfaces,\n mfManifest,\n tarball,\n version,\n workspaces,\n }: {\n access?: readonly BrettAccess[]\n interfaces: readonly BrettInterface[]\n mfManifest: Record<string, unknown>\n tarball?: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n },\n): void {\n formData.append('version', version)\n appendJson(formData, 'interfaces', interfaces)\n // Studio-only — the server rejects a workspaces part on non-studio types.\n if (workspaces?.length) appendJson(formData, 'workspaces', workspaces)\n // Per-deployment; forbidden for singletons, so callers omit it there.\n if (access?.length) appendJson(formData, 'access', access)\n appendJson(formData, 'mfManifest', mfManifest)\n // Last: the server requires every field part to precede the tarball.\n if (tarball) {\n formData.append('tarball', tarball, {contentType: 'application/gzip', filename: 'app.tar.gz'})\n }\n}\n\n/** Structured parts must arrive as JSON so the server parses them. */\nfunction appendJson(formData: FormData, name: string, value: unknown): void {\n formData.append(name, JSON.stringify(value), {contentType: 'application/json'})\n}\n\nasync function request<T>(url: string, formData: FormData): Promise<T> {\n const client = await getClient()\n return client.request({\n body: formData.pipe(new PassThrough()),\n headers: formData.getHeaders(),\n method: 'POST',\n url,\n })\n}\n"],"names":["PassThrough","getGlobalCliClient","isStaging","FormData","APP_WORKBENCH_API_VERSION","getWorkbenchUrl","organizationId","getApplicationUrl","application","segment","type","slug","id","getClient","apiVersion","requireUser","getApplication","applicationId","client","request","url","err","statusCode","getOrganizationApplication","idOrSlug","signal","ignoreWarnings","query","include","listApplications","data","limit","createApplication","options","externalUrl","isSingleton","name","projectId","title","visibility","body","undefined","config","studio","method","updateApplication","update","setApplicationIcon","icon","image","headers","contentType","removeApplicationIcon","setInterfaceIcon","interfaceId","createDeployment","access","interfaces","isAutoUpdating","mfManifest","tarball","version","workspaces","formData","append","toString","appendDeploymentParts","deleteApplication","appendJson","length","filename","value","JSON","stringify","pipe","getHeaders"],"mappings":"AAAA,SAAQA,WAAW,QAAO,cAAa;AAGvC,SAA4BC,kBAAkB,QAAO,mBAAkB;AAEvE,SAAQC,SAAS,QAAO,wBAAuB;AAC/C,OAAOC,cAAc,YAAW;AAGhC,SAAQC,yBAAyB,QAAO,kBAAiB;AAyDzD,OAAO,SAASC,gBAAgBC,cAAsB;IACpD,OAAO,CAAC,QAAQ,EAAEA,eAAe,CAAC,EAAEJ,cAAc,oBAAoB,cAAc;AACtF;AAEA,4EAA4E,GAC5E,OAAO,SAASK,kBACdC,WAAyE;IAEzE,MAAMC,UAAUD,YAAYE,IAAI,KAAK,WAAW,YAAY;IAC5D,OAAO,GAAGL,gBAAgBG,YAAYF,cAAc,EAAE,CAAC,EAAEG,QAAQ,CAAC,EAAED,YAAYG,IAAI,IAAIH,YAAYI,EAAE,EAAE;AAC1G;AAEA,eAAeC;IACb,OAAOZ,mBAAmB;QAACa,YAAYV;QAA2BW,aAAa;IAAI;AACrF;AAEA,OAAO,eAAeC,eAAeC,aAAqB;IACx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ACpE,SAASF,WAAWL,QAAkB,EAAE3B,IAAY,EAAEmC,KAAc;IAClER,SAASC,MAAM,CAAC5B,MAAMoC,KAAKC,SAAS,CAACF,QAAQ;QAACpB,aAAa;IAAkB;AAC/E;AAEA,eAAehC,QAAWC,GAAW,EAAE2C,QAAkB;IACvD,MAAM7C,SAAS,MAAML;IACrB,OAAOK,OAAOC,OAAO,CAAC;QACpBqB,MAAMuB,SAASW,IAAI,CAAC,IAAI1E;QACxBkD,SAASa,SAASY,UAAU;QAC5B/B,QAAQ;QACRxB;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/workbench-cli",
3
- "version": "2.19.1",
3
+ "version": "2.20.0",
4
4
  "description": "Internal implementation detail of the Sanity CLI's unstable workbench support. Not intended for direct use.",
5
5
  "homepage": "https://github.com/sanity-io/cli",
6
6
  "bugs": "https://github.com/sanity-io/cli/issues",