@sanity/workbench-cli 1.5.0 → 1.6.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 (34) hide show
  1. package/dist/_exports/build.d.ts +36 -1
  2. package/dist/_exports/build.js +1 -0
  3. package/dist/_exports/build.js.map +1 -1
  4. package/dist/_exports/deploy.d.ts +5 -1
  5. package/dist/_exports/index.d.ts +1 -1
  6. package/dist/_exports/preview.d.ts +169 -0
  7. package/dist/_exports/preview.js +3 -0
  8. package/dist/_exports/preview.js.map +1 -0
  9. package/dist/_exports/undeploy.d.ts +3 -1
  10. package/dist/actions/build/vite/optimize-deps.js +84 -0
  11. package/dist/actions/build/vite/optimize-deps.js.map +1 -0
  12. package/dist/actions/deploy/checkBuiltOutput.js +16 -2
  13. package/dist/actions/deploy/checkBuiltOutput.js.map +1 -1
  14. package/dist/actions/deploy/deployWorkbenchApp.js +17 -3
  15. package/dist/actions/deploy/deployWorkbenchApp.js.map +1 -1
  16. package/dist/actions/dev/registry.js +69 -1
  17. package/dist/actions/dev/registry.js.map +1 -1
  18. package/dist/actions/dev/startWorkbenchDev.js +6 -41
  19. package/dist/actions/dev/startWorkbenchDev.js.map +1 -1
  20. package/dist/actions/dev/startWorkbenchDevServer.js +7 -3
  21. package/dist/actions/dev/startWorkbenchDevServer.js.map +1 -1
  22. package/dist/actions/preview/serveBuiltApplication.js +53 -0
  23. package/dist/actions/preview/serveBuiltApplication.js.map +1 -0
  24. package/dist/actions/preview/startWorkbenchPreview.js +91 -0
  25. package/dist/actions/preview/startWorkbenchPreview.js.map +1 -0
  26. package/dist/defineApp.js +2 -5
  27. package/dist/defineApp.js.map +1 -1
  28. package/dist/resolveWorkbenchApp.js +1 -0
  29. package/dist/resolveWorkbenchApp.js.map +1 -1
  30. package/dist/services/applications.js +14 -1
  31. package/dist/services/applications.js.map +1 -1
  32. package/dist/util/serverOrchestration.js +75 -0
  33. package/dist/util/serverOrchestration.js.map +1 -0
  34. package/package.json +7 -3
@@ -0,0 +1,91 @@
1
+ import { styleText } from 'node:util';
2
+ import { findProjectRoot } from '@sanity/cli-core';
3
+ import { createServerLifecycle, toDisplayHost } from '../../util/serverOrchestration.js';
4
+ import { deriveConfigs, deriveInterfaces } from '../dev/deriveInterfaces.js';
5
+ import { registerDevServer } from '../dev/registry.js';
6
+ import { startWorkbenchDevServer } from '../dev/startWorkbenchDevServer.js';
7
+ import { serveBuiltApplication } from './serveBuiltApplication.js';
8
+ /**
9
+ * `sanity start` for a workbench app: serve a production build the way dev serves
10
+ * a live one. The same singleton workbench shell renders it and the same registry
11
+ * advertises it — only the remote differs, static files from the build output
12
+ * instead of a live Vite dev server. There's no config watcher or rebuild: a
13
+ * build is fixed, so nothing re-syncs.
14
+ *
15
+ * A running workbench claims the configured port, so the built remote binds the
16
+ * next one. Without one the remote takes the configured port and announces its
17
+ * own URL.
18
+ */ export async function startWorkbenchPreview(options) {
19
+ const { cacheDir, checkForDeprecatedAppId, cliConfig, extractManifest, httpHost, httpPort, isApp, outDir, output, reactStrictMode, workDir } = options;
20
+ const { close, closers, installSignalHandlers } = createServerLifecycle();
21
+ const workbench = await startWorkbenchDevServer({
22
+ cacheDir,
23
+ cliConfig,
24
+ httpHost,
25
+ httpPort,
26
+ mode: 'preview',
27
+ output,
28
+ reactStrictMode,
29
+ workDir
30
+ });
31
+ closers.push(workbench.close);
32
+ const remotePort = workbench.workbenchAvailable ? workbench.workbenchPort + 1 : httpPort;
33
+ const remote = await serveBuiltApplication({
34
+ cacheDir,
35
+ httpHost,
36
+ httpPort: remotePort,
37
+ outDir,
38
+ workDir
39
+ }).catch(async (err)=>{
40
+ await close();
41
+ throw err;
42
+ });
43
+ closers.push(remote.close);
44
+ try {
45
+ // Callers provide CLI-only validation and manifest extraction to keep them
46
+ // out of workbench-cli.
47
+ checkForDeprecatedAppId();
48
+ const configPath = (await findProjectRoot(workDir)).path;
49
+ const registration = registerDevServer({
50
+ configs: deriveConfigs(cliConfig.app),
51
+ host: remote.host,
52
+ // A local app is identified by where it's served, matching `sanity dev`.
53
+ id: `${remote.host}-${remote.port}`,
54
+ interfaces: deriveInterfaces(cliConfig.app, {
55
+ isApp
56
+ }),
57
+ manifest: await extractManifest({
58
+ configPath,
59
+ workDir
60
+ }),
61
+ manifestUpdatedAt: new Date().toISOString(),
62
+ port: remote.port,
63
+ projectId: cliConfig?.api?.projectId,
64
+ type: isApp ? 'coreApp' : 'studio',
65
+ workDir
66
+ });
67
+ closers.push(async ()=>registration.release());
68
+ } catch (err) {
69
+ await close();
70
+ throw err;
71
+ }
72
+ if (workbench.workbenchAvailable) {
73
+ const workbenchUrl = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}`;
74
+ output.log(`Workbench preview server started at ${styleText([
75
+ 'blue',
76
+ 'underline'
77
+ ], workbenchUrl)} (serving build on port ${remote.port})`);
78
+ } else {
79
+ const remoteUrl = `http://${toDisplayHost(remote.host)}:${remote.port}`;
80
+ output.log(`Serving build at ${styleText([
81
+ 'blue',
82
+ 'underline'
83
+ ], remoteUrl)}`);
84
+ }
85
+ installSignalHandlers();
86
+ return {
87
+ close
88
+ };
89
+ }
90
+
91
+ //# sourceMappingURL=startWorkbenchPreview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/preview/startWorkbenchPreview.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {type CliConfig, findProjectRoot, type Output} from '@sanity/cli-core'\n\nimport {createServerLifecycle, toDisplayHost} from '../../util/serverOrchestration.js'\nimport {deriveConfigs, deriveInterfaces} from '../dev/deriveInterfaces.js'\nimport {type DevServerManifest, registerDevServer} 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 configPath: 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 const {close, closers, installSignalHandlers} = createServerLifecycle()\n\n const workbench = await startWorkbenchDevServer({\n cacheDir,\n cliConfig,\n httpHost,\n httpPort,\n mode: 'preview',\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 outDir,\n workDir,\n }).catch(async (err) => {\n await close()\n throw err\n })\n closers.push(remote.close)\n\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 registration = registerDevServer({\n configs: deriveConfigs(cliConfig.app),\n host: remote.host,\n // A local app is identified by where it's served, matching `sanity dev`.\n id: `${remote.host}-${remote.port}`,\n interfaces: deriveInterfaces(cliConfig.app, {isApp}),\n manifest: await extractManifest({configPath, workDir}),\n manifestUpdatedAt: new Date().toISOString(),\n port: remote.port,\n projectId: cliConfig?.api?.projectId,\n type: isApp ? 'coreApp' : 'studio',\n workDir,\n })\n closers.push(async () => registration.release())\n } catch (err) {\n await close()\n throw err\n }\n\n if (workbench.workbenchAvailable) {\n const workbenchUrl = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}`\n output.log(\n `Workbench preview server started at ${styleText(['blue', 'underline'], workbenchUrl)} (serving build on port ${remote.port})`,\n )\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"],"names":["styleText","findProjectRoot","createServerLifecycle","toDisplayHost","deriveConfigs","deriveInterfaces","registerDevServer","startWorkbenchDevServer","serveBuiltApplication","startWorkbenchPreview","options","cacheDir","checkForDeprecatedAppId","cliConfig","extractManifest","httpHost","httpPort","isApp","outDir","output","reactStrictMode","workDir","close","closers","installSignalHandlers","workbench","mode","push","remotePort","workbenchAvailable","workbenchPort","remote","catch","err","configPath","path","registration","configs","app","host","id","port","interfaces","manifest","manifestUpdatedAt","Date","toISOString","projectId","api","type","release","workbenchUrl","log","remoteUrl"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAwBC,eAAe,QAAoB,mBAAkB;AAE7E,SAAQC,qBAAqB,EAAEC,aAAa,QAAO,oCAAmC;AACtF,SAAQC,aAAa,EAAEC,gBAAgB,QAAO,6BAA4B;AAC1E,SAAgCC,iBAAiB,QAAO,qBAAoB;AAC5E,SAAQC,uBAAuB,QAAO,oCAAmC;AACzE,SAAQC,qBAAqB,QAAO,6BAA4B;AAuBhE;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,sBACpBC,OAAqC;IAErC,MAAM,EACJC,QAAQ,EACRC,uBAAuB,EACvBC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACN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cAAcsB,UAAUV,QAAQ,EAAE,CAAC,EAAEU,UAAUK,aAAa,EAAE;QAC7FX,OAAOiC,GAAG,CACR,CAAC,oCAAoC,EAAEpD,UAAU;YAAC;YAAQ;SAAY,EAAEmD,cAAc,wBAAwB,EAAEpB,OAAOU,IAAI,CAAC,CAAC,CAAC;IAElI,OAAO;QACL,MAAMY,YAAY,CAAC,OAAO,EAAElD,cAAc4B,OAAOQ,IAAI,EAAE,CAAC,EAAER,OAAOU,IAAI,EAAE;QACvEtB,OAAOiC,GAAG,CAAC,CAAC,iBAAiB,EAAEpD,UAAU;YAAC;YAAQ;SAAY,EAAEqD,YAAY;IAC9E;IAEA7B;IAEA,OAAO;QAACF;IAAK;AACf"}
package/dist/defineApp.js CHANGED
@@ -62,11 +62,7 @@ import { ConfigSchema, InterfaceDeclarationSchema, ServiceDeclarationSchema } fr
62
62
  * application service on deploy, not into the app manifest. Service `name`s
63
63
  * must be unique within the app.
64
64
  */ services: z.optional(z.array(ServiceDeclarationSchema).check(z.refine((services)=>new Set(services.map((service)=>service.name)).size === services.length, 'Service `name` must be unique within an app'))),
65
- /**
66
- * Hostname the application is created at on first deploy. Generated when
67
- * omitted; redeploys target `deployment.appId` and ignore it. SDK apps
68
- * only — studios use `studioHost` in sanity.cli.ts.
69
- */ slug: z.optional(z.string()),
65
+ slug: z.string('App `slug` is required — the hostname the application is created at on deploy'),
70
66
  /** User-facing app title. Wins over studio.config.ts title on merge. */ title: z.string(),
71
67
  /**
72
68
  * Views the app exposes (e.g. dock panels). Metadata only — built into
@@ -144,6 +140,7 @@ z.refine((input)=>!(input.config && !input.isSingleton), {
144
140
  isSingleton: true,
145
141
  name: 'media-library',
146
142
  organizationId: input.organizationId,
143
+ slug: 'media-library',
147
144
  title: 'Media Library'
148
145
  });
149
146
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defineApp.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\nimport {ConfigSchema, InterfaceDeclarationSchema, ServiceDeclarationSchema} from './contract.js'\n\n/** Allowed characters for an app `name`. */\nconst APP_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/\n\n/**\n * Dashboard visibility values. Mirrors `APP_VISIBILITIES` in `@sanity/cli-core`\n * (which can't be imported here — pulling the barrel into this lean module bloats\n * the config-load path). Kept in sync by a type test in `defineApp.test.ts`.\n */\nconst APP_VISIBILITIES = ['default', 'unlisted', 'disabled'] as const\n\n/**\n * Internal application discriminator. Sanity-owned singleton apps only;\n * validated by the schema but excluded from the public `DefineAppInput` type.\n */\nconst ApplicationType = z.enum(['coreApp', 'studio', 'canvas', 'dashboard', 'media-library'])\n\n/** Dock groups an app can place itself into. */\nconst DockGroupSchema = z.enum(['dock.system', 'dock.applications', 'dock.user'])\n\n/**\n * Dock group identifier. The API does not block a user app from declaring a\n * reserved group (e.g. `dock.system`); priority conventions keep Sanity-owned\n * apps ahead.\n * @public\n */\nexport type DockGroup = z.output<typeof DockGroupSchema>\n\n/**\n * Runtime-validation schema for `unstable_defineApp`. Validates the full shape\n * including the internal `applicationType`; the user-facing `DefineAppInput`\n * type below omits that field.\n * @internal\n */\nexport const DefineAppInputSchema = z\n .object({\n /**\n * Internal — Sanity-owned singleton apps only. Validated here but excluded\n * from the public `DefineAppInput` type.\n * @internal\n */\n applicationType: z.optional(ApplicationType),\n /**\n * Deployed as a versioned snapshot on the app's org installation, not the\n * application service. Singletons only. Internal, so excluded from the public\n * `DefineAppInput` and set via `@ts-expect-error` like `applicationType`.\n * @internal\n */\n config: z.optional(ConfigSchema),\n /**\n * App entrypoint module. Defaults to `./src/App.tsx` when omitted. The build\n * derives the app's navigable `app` view from it. SDK apps only — setting it\n * on a studio is rejected (studio app views are not yet implemented).\n */\n entry: z.optional(z.string()),\n /** Dock group to render in. Defaults to `dock.applications` when omitted. */\n group: z.optional(DockGroupSchema),\n /** Optional icon override (path to an SVG). Wins over manifest/studio icon. */\n icon: z.optional(z.string()),\n /**\n * Sanity-owned app deployed once, installed per org; excluded from the public `DefineAppInput`.\n * @internal\n */\n isSingleton: z.optional(z.boolean()),\n /** Unique app identifier — must match `APP_NAME_PATTERN`. */\n name: z.string().check(z.regex(APP_NAME_PATTERN, 'App `name` must match /^[a-zA-Z0-9_-]+$/')),\n /** Organization that owns the app — the workbench runs and deploys against it. */\n organizationId: z.string(\n \"App `organizationId` is required — pass the owning organization's ID to `unstable_defineApp`\",\n ),\n /** Sort position within the group, ascending. Defaults to `100` when omitted. */\n priority: z.optional(z.number()),\n /**\n * Background services the app runs (e.g. a `worker` emitting dock badges).\n * Metadata only — built into worker artifacts and persisted to the\n * application service on deploy, not into the app manifest. Service `name`s\n * must be unique within the app.\n */\n services: z.optional(\n z\n .array(ServiceDeclarationSchema)\n .check(\n z.refine(\n (services) => new Set(services.map((service) => service.name)).size === services.length,\n 'Service `name` must be unique within an app',\n ),\n ),\n ),\n /**\n * Hostname the application is created at on first deploy. Generated when\n * omitted; redeploys target `deployment.appId` and ignore it. SDK apps\n * only — studios use `studioHost` in sanity.cli.ts.\n */\n slug: z.optional(z.string()),\n /** User-facing app title. Wins over studio.config.ts title on merge. */\n title: z.string(),\n /**\n * Views the app exposes (e.g. dock panels). Metadata only — built into\n * render artifacts and persisted to the application service on deploy, not\n * into the app manifest. View `name`s must be unique within the app.\n */\n views: z.optional(\n z\n .array(InterfaceDeclarationSchema)\n .check(\n z.refine(\n (views) => new Set(views.map((view) => view.name)).size === views.length,\n 'View `name` must be unique within an app',\n ),\n ),\n ),\n /** Dashboard visibility of the app. Defaults to `default` when omitted. */\n visibility: z.optional(z.enum(APP_VISIBILITIES)),\n })\n .check(\n // Studio app views are not implemented yet. A studio that declares `entry`\n // (the SDK app-view entrypoint) is rejected here rather than silently\n // generating one; studios keep navigating via their existing render path.\n z.refine((input) => !(input.applicationType === 'studio' && input.entry !== undefined), {\n error: 'App views for studios are not implemented yet',\n path: ['entry'],\n }),\n )\n .check(\n // An config belongs to a Sanity-owned singleton (the Media\n // Library). A non-singleton declaring one is rejected — see\n // {@link readConfig} for the runtime guard.\n z.refine((input) => !(input.config && !input.isSingleton), {\n error: '`config` is only supported for singleton apps',\n path: ['config'],\n }),\n )\n\n/**\n * User-facing input for `unstable_defineApp`. Excludes the internal\n * `applicationType`, `isSingleton`, and `config` — validated by the\n * schema but not part of the public surface (Sanity-owned apps set them via\n * `@ts-expect-error`).\n * @public\n */\nexport type DefineAppInput = Omit<\n z.output<typeof DefineAppInputSchema>,\n 'applicationType' | 'config' | 'isSingleton'\n>\n\n/**\n * Nominal brand the CLI discriminates on to enable the workbench build/deploy\n * codepath. Registered via `Symbol.for` so the marker survives module-realm\n * boundaries — `@sanity/cli-core` re-derives the same global symbol with\n * `Symbol.for` rather than importing it, so it stays internal to this module.\n */\nconst WORKBENCH_APP: unique symbol = Symbol.for('sanity.workbench.defineApp')\n\n/**\n * The branded result of `unstable_defineApp`. Carries the same fields as the\n * input plus the internal brand — users only ever see `DefineAppInput`.\n * @public\n */\nexport interface DefineAppResult extends DefineAppInput {\n readonly [WORKBENCH_APP]: true\n}\n\n/**\n * A branded app as the CLI reads it — the full schema shape, including the\n * internal fields `DefineAppInput` omits. Schema-derived so the narrowing\n * can't drift from what the schema validates.\n * @public\n */\nexport type WorkbenchApp = DefineAppResult & z.output<typeof DefineAppInputSchema>\n\n/**\n * Whether `app` is a branded `unstable_defineApp(...)` result — the sole\n * workbench opt-in.\n * @public\n */\nexport function isWorkbenchApp(app: unknown): app is WorkbenchApp {\n return typeof app === 'object' && app !== null && WORKBENCH_APP in app\n}\n\n/**\n * The app's config, or `undefined` when it declares none. Throws\n * when a non-singleton declares one — configs belong to Sanity-owned singletons,\n * so build/dev/deploy all read it through here to reject the combination\n * consistently.\n * @internal\n */\nexport function readConfig(app: WorkbenchApp): WorkbenchApp['config'] | undefined {\n if (app.config && !app.isSingleton) {\n throw new Error('`config` is only supported for singleton apps')\n }\n return app.config\n}\n\n/**\n * Declare a Sanity Workbench application. Identity at runtime — returns the same\n * object reference, tagged with the workbench brand. Field validation (the\n * `name` pattern etc.) runs at build time in the CLI via `DefineAppInputSchema`;\n * this helper stays a thin, pure identity wrapper.\n * @public\n */\nexport function unstable_defineApp(input: DefineAppInput): DefineAppResult {\n return Object.defineProperty(input, WORKBENCH_APP, {\n configurable: false,\n enumerable: false,\n value: true,\n writable: false,\n }) as DefineAppResult\n}\n\n/**\n * One custom field a media library exposes. `src` default-exports a `defineField(...)` schema type.\n * @public\n */\nexport interface MediaLibraryField {\n /** Unique within the media library. */\n name: string\n src: string\n title: string\n\n /** Readable outside the owning organization. */\n public?: boolean\n}\n\n/**\n * Sanity-owned singleton, so authors don't name or title the app — only `organizationId` is required.\n * @public\n */\nexport interface DefineMediaLibraryInput {\n /** Organization that owns the media library — the CLI runs and deploys against it. */\n organizationId: string\n\n fields?: MediaLibraryField[]\n}\n\n/**\n * Declare the Sanity Media Library as a workbench app — a singleton whose `fields` become its config.\n * @public\n */\nexport function unstable_defineMediaLibrary(input: DefineMediaLibraryInput): DefineAppResult {\n return unstable_defineApp({\n // @ts-expect-error -- `applicationType`/`isSingleton`/`config` are internal, excluded from `DefineAppInput`; Sanity-owned apps set them\n applicationType: 'media-library',\n config: input.fields?.length ? {appType: 'media-library', fields: input.fields} : undefined,\n isSingleton: true,\n name: 'media-library',\n organizationId: input.organizationId,\n title: 'Media Library',\n })\n}\n"],"names":["z","ConfigSchema","InterfaceDeclarationSchema","ServiceDeclarationSchema","APP_NAME_PATTERN","APP_VISIBILITIES","ApplicationType","enum","DockGroupSchema","DefineAppInputSchema","object","applicationType","optional","config","entry","string","group","icon","isSingleton","boolean","name","check","regex","organizationId","priority","number","services","array","refine","Set","map","service","size","length","slug","title","views","view","visibility","input","undefined","error","path","WORKBENCH_APP","Symbol","for","isWorkbenchApp","app","readConfig","Error","unstable_defineApp","Object","defineProperty","configurable","enumerable","value","writable","unstable_defineMediaLibrary","fields","appType"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B,SAAQC,YAAY,EAAEC,0BAA0B,EAAEC,wB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cAAc;QACdC,YAAY;QACZC,OAAO;QACPC,UAAU;IACZ;AACF;AA2BA;;;CAGC,GACD,OAAO,SAASC,4BAA4BlB,KAA8B;IACxE,OAAOW,mBAAmB;QACxB,wIAAwI;QACxIvC,iBAAiB;QACjBE,QAAQ0B,MAAMmB,MAAM,EAAEzB,SAAS;YAAC0B,SAAS;YAAiBD,QAAQnB,MAAMmB,MAAM;QAAA,IAAIlB;QAClFtB,aAAa;QACbE,MAAM;QACNG,gBAAgBgB,MAAMhB,cAAc;QACpCY,OAAO;IACT;AACF"}
1
+ {"version":3,"sources":["../src/defineApp.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\nimport {ConfigSchema, InterfaceDeclarationSchema, ServiceDeclarationSchema} from './contract.js'\n\n/** Allowed characters for an app `name`. */\nconst APP_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/\n\n/**\n * Dashboard visibility values. Mirrors `APP_VISIBILITIES` in `@sanity/cli-core`\n * (which can't be imported here — pulling the barrel into this lean module bloats\n * the config-load path). Kept in sync by a type test in `defineApp.test.ts`.\n */\nconst APP_VISIBILITIES = ['default', 'unlisted', 'disabled'] as const\n\n/**\n * Internal application discriminator. Sanity-owned singleton apps only;\n * validated by the schema but excluded from the public `DefineAppInput` type.\n */\nconst ApplicationType = z.enum(['coreApp', 'studio', 'canvas', 'dashboard', 'media-library'])\n\n/** Dock groups an app can place itself into. */\nconst DockGroupSchema = z.enum(['dock.system', 'dock.applications', 'dock.user'])\n\n/**\n * Dock group identifier. The API does not block a user app from declaring a\n * reserved group (e.g. `dock.system`); priority conventions keep Sanity-owned\n * apps ahead.\n * @public\n */\nexport type DockGroup = z.output<typeof DockGroupSchema>\n\n/**\n * Runtime-validation schema for `unstable_defineApp`. Validates the full shape\n * including the internal `applicationType`; the user-facing `DefineAppInput`\n * type below omits that field.\n * @internal\n */\nexport const DefineAppInputSchema = z\n .object({\n /**\n * Internal — Sanity-owned singleton apps only. Validated here but excluded\n * from the public `DefineAppInput` type.\n * @internal\n */\n applicationType: z.optional(ApplicationType),\n /**\n * Deployed as a versioned snapshot on the app's org installation, not the\n * application service. Singletons only. Internal, so excluded from the public\n * `DefineAppInput` and set via `@ts-expect-error` like `applicationType`.\n * @internal\n */\n config: z.optional(ConfigSchema),\n /**\n * App entrypoint module. Defaults to `./src/App.tsx` when omitted. The build\n * derives the app's navigable `app` view from it. SDK apps only — setting it\n * on a studio is rejected (studio app views are not yet implemented).\n */\n entry: z.optional(z.string()),\n /** Dock group to render in. Defaults to `dock.applications` when omitted. */\n group: z.optional(DockGroupSchema),\n /** Optional icon override (path to an SVG). Wins over manifest/studio icon. */\n icon: z.optional(z.string()),\n /**\n * Sanity-owned app deployed once, installed per org; excluded from the public `DefineAppInput`.\n * @internal\n */\n isSingleton: z.optional(z.boolean()),\n /** Unique app identifier — must match `APP_NAME_PATTERN`. */\n name: z.string().check(z.regex(APP_NAME_PATTERN, 'App `name` must match /^[a-zA-Z0-9_-]+$/')),\n /** Organization that owns the app — the workbench runs and deploys against it. */\n organizationId: z.string(\n \"App `organizationId` is required — pass the owning organization's ID to `unstable_defineApp`\",\n ),\n /** Sort position within the group, ascending. Defaults to `100` when omitted. */\n priority: z.optional(z.number()),\n /**\n * Background services the app runs (e.g. a `worker` emitting dock badges).\n * Metadata only — built into worker artifacts and persisted to the\n * application service on deploy, not into the app manifest. Service `name`s\n * must be unique within the app.\n */\n services: z.optional(\n z\n .array(ServiceDeclarationSchema)\n .check(\n z.refine(\n (services) => new Set(services.map((service) => service.name)).size === services.length,\n 'Service `name` must be unique within an app',\n ),\n ),\n ),\n slug: z.string('App `slug` is required — the hostname the application is created at on deploy'),\n /** User-facing app title. Wins over studio.config.ts title on merge. */\n title: z.string(),\n /**\n * Views the app exposes (e.g. dock panels). Metadata only — built into\n * render artifacts and persisted to the application service on deploy, not\n * into the app manifest. View `name`s must be unique within the app.\n */\n views: z.optional(\n z\n .array(InterfaceDeclarationSchema)\n .check(\n z.refine(\n (views) => new Set(views.map((view) => view.name)).size === views.length,\n 'View `name` must be unique within an app',\n ),\n ),\n ),\n /** Dashboard visibility of the app. Defaults to `default` when omitted. */\n visibility: z.optional(z.enum(APP_VISIBILITIES)),\n })\n .check(\n // Studio app views are not implemented yet. A studio that declares `entry`\n // (the SDK app-view entrypoint) is rejected here rather than silently\n // generating one; studios keep navigating via their existing render path.\n z.refine((input) => !(input.applicationType === 'studio' && input.entry !== undefined), {\n error: 'App views for studios are not implemented yet',\n path: ['entry'],\n }),\n )\n .check(\n // An config belongs to a Sanity-owned singleton (the Media\n // Library). A non-singleton declaring one is rejected — see\n // {@link readConfig} for the runtime guard.\n z.refine((input) => !(input.config && !input.isSingleton), {\n error: '`config` is only supported for singleton apps',\n path: ['config'],\n }),\n )\n\n/**\n * User-facing input for `unstable_defineApp`. Excludes the internal\n * `applicationType`, `isSingleton`, and `config` — validated by the\n * schema but not part of the public surface (Sanity-owned apps set them via\n * `@ts-expect-error`).\n * @public\n */\nexport type DefineAppInput = Omit<\n z.output<typeof DefineAppInputSchema>,\n 'applicationType' | 'config' | 'isSingleton'\n>\n\n/**\n * Nominal brand the CLI discriminates on to enable the workbench build/deploy\n * codepath. Registered via `Symbol.for` so the marker survives module-realm\n * boundaries — `@sanity/cli-core` re-derives the same global symbol with\n * `Symbol.for` rather than importing it, so it stays internal to this module.\n */\nconst WORKBENCH_APP: unique symbol = Symbol.for('sanity.workbench.defineApp')\n\n/**\n * The branded result of `unstable_defineApp`. Carries the same fields as the\n * input plus the internal brand — users only ever see `DefineAppInput`.\n * @public\n */\nexport interface DefineAppResult extends DefineAppInput {\n readonly [WORKBENCH_APP]: true\n}\n\n/**\n * A branded app as the CLI reads it — the full schema shape, including the\n * internal fields `DefineAppInput` omits. Schema-derived so the narrowing\n * can't drift from what the schema validates.\n * @public\n */\nexport type WorkbenchApp = DefineAppResult & z.output<typeof DefineAppInputSchema>\n\n/**\n * Whether `app` is a branded `unstable_defineApp(...)` result — the sole\n * workbench opt-in.\n * @public\n */\nexport function isWorkbenchApp(app: unknown): app is WorkbenchApp {\n return typeof app === 'object' && app !== null && WORKBENCH_APP in app\n}\n\n/**\n * The app's config, or `undefined` when it declares none. Throws\n * when a non-singleton declares one — configs belong to Sanity-owned singletons,\n * so build/dev/deploy all read it through here to reject the combination\n * consistently.\n * @internal\n */\nexport function readConfig(app: WorkbenchApp): WorkbenchApp['config'] | undefined {\n if (app.config && !app.isSingleton) {\n throw new Error('`config` is only supported for singleton apps')\n }\n return app.config\n}\n\n/**\n * Declare a Sanity Workbench application. Identity at runtime — returns the same\n * object reference, tagged with the workbench brand. Field validation (the\n * `name` pattern etc.) runs at build time in the CLI via `DefineAppInputSchema`;\n * this helper stays a thin, pure identity wrapper.\n * @public\n */\nexport function unstable_defineApp(input: DefineAppInput): DefineAppResult {\n return Object.defineProperty(input, WORKBENCH_APP, {\n configurable: false,\n enumerable: false,\n value: true,\n writable: false,\n }) as DefineAppResult\n}\n\n/**\n * One custom field a media library exposes. `src` default-exports a `defineField(...)` schema type.\n * @public\n */\nexport interface MediaLibraryField {\n /** Unique within the media library. */\n name: string\n src: string\n title: string\n\n /** Readable outside the owning organization. */\n public?: boolean\n}\n\n/**\n * Sanity-owned singleton, so authors don't name or title the app — only `organizationId` is required.\n * @public\n */\nexport interface DefineMediaLibraryInput {\n /** Organization that owns the media library — the CLI runs and deploys against it. */\n organizationId: string\n\n fields?: MediaLibraryField[]\n}\n\n/**\n * Declare the Sanity Media Library as a workbench app — a singleton whose `fields` become its config.\n * @public\n */\nexport function unstable_defineMediaLibrary(input: DefineMediaLibraryInput): DefineAppResult {\n return unstable_defineApp({\n // @ts-expect-error -- `applicationType`/`isSingleton`/`config` are internal, excluded from `DefineAppInput`; Sanity-owned apps set them\n applicationType: 'media-library',\n config: input.fields?.length ? {appType: 'media-library', fields: input.fields} : undefined,\n isSingleton: true,\n name: 'media-library',\n organizationId: input.organizationId,\n slug: 'media-library',\n title: 'Media Library',\n })\n}\n"],"names":["z","ConfigSchema","InterfaceDeclarationSchema","ServiceDeclarationSchema","APP_NAME_PATTERN","APP_VISIBILITIES","ApplicationType","enum","DockGroupSchema","DefineAppInputSchema","object","applicationType","optional","config","entry","string","group","icon","isSingleton","boolean","name","check","regex","organizationId","priority","number","services","array","refine","Set","map","service","size","length","slug","title","views","view","visibility","input","undefined","error","path","WORKBENCH_APP","Symbol","for","isWorkbenchApp","app","readConfig","Error","unstable_defineApp","Object","defineProperty","configurable","enumerable","value","writable","unstable_defineMediaLibrary","fields","appType"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B,SAAQC,YAAY,EAAEC,0BAA0B,EAAEC,wBAAwB,QAAO,gBAAe;AAEhG,0CAA0C,GAC1C,MAAMC,mBAAmB;AAEzB;;;;CAIC,GACD,MAAMC,mBAAmB;IAAC;IAAW;IAAY;CAAW;AAE5D;;;CAGC,GACD,MAAMC,kBAAkBN,EAAEO,IAAI,CAAC;IAAC;IAAW;IAAU;IAAU;IAAa;CAAgB;AAE5F,8CAA8C,GAC9C,MAAMC,kBAAkBR,EAAEO,IAAI,CAAC;IAAC;IAAe;IAAqB;CAAY;AAUhF;;;;;CAKC,GACD,OAAO,MAAME,uBAAuBT,EACjCU,MAAM,CAAC;IACN;;;;KAIC,GACDC,iBAAiBX,EAAEY,QAAQ,CAACN;IAC5B;;;;;KAKC,GACDO,QAAQb,EAAEY,QAAQ,CAACX;IACnB;;;;KAIC,GACDa,OAAOd,EAAEY,QAAQ,CAACZ,EAAEe,MAAM;IAC1B,2EAA2E,GAC3EC,OAAOhB,EAAEY,QAAQ,CAACJ;IAClB,6EAA6E,GAC7ES,MAAMjB,EAAEY,QAAQ,CAACZ,EAAEe,MAAM;IACzB;;;KAGC,GACDG,aAAalB,EAAEY,QAAQ,CAACZ,EAAEmB,OAAO;IACjC,2DAA2D,GAC3DC,MAAMpB,EAAEe,MAAM,GAAGM,KAAK,CAACrB,EAAEsB,KAAK,CAAClB,kBAAkB;IACjD,gFAAgF,GAChFmB,gBAAgBvB,EAAEe,MAA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Y;IACzC,OAAO,OAAOA,QAAQ,YAAYA,QAAQ,QAAQJ,iBAAiBI;AACrE;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,WAAWD,GAAiB;IAC1C,IAAIA,IAAIlC,MAAM,IAAI,CAACkC,IAAI7B,WAAW,EAAE;QAClC,MAAM,IAAI+B,MAAM;IAClB;IACA,OAAOF,IAAIlC,MAAM;AACnB;AAEA;;;;;;CAMC,GACD,OAAO,SAASqC,mBAAmBX,KAAqB;IACtD,OAAOY,OAAOC,cAAc,CAACb,OAAOI,eAAe;QACjDU,cAAc;QACdC,YAAY;QACZC,OAAO;QACPC,UAAU;IACZ;AACF;AA2BA;;;CAGC,GACD,OAAO,SAASC,4BAA4BlB,KAA8B;IACxE,OAAOW,mBAAmB;QACxB,wIAAwI;QACxIvC,iBAAiB;QACjBE,QAAQ0B,MAAMmB,MAAM,EAAEzB,SAAS;YAAC0B,SAAS;YAAiBD,QAAQnB,MAAMmB,MAAM;QAAA,IAAIlB;QAClFtB,aAAa;QACbE,MAAM;QACNG,gBAAgBgB,MAAMhB,cAAc;QACpCW,MAAM;QACNC,OAAO;IACT;AACF"}
@@ -14,6 +14,7 @@ import { isWorkbenchApp, readConfig } from './defineApp.js';
14
14
  applicationType: app.applicationType,
15
15
  config: readConfig(app),
16
16
  entry: app.entry,
17
+ icon: app.icon,
17
18
  isSingleton: app.isSingleton,
18
19
  name: app.name,
19
20
  services: app.services ?? [],
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/resolveWorkbenchApp.ts"],"sourcesContent":["// Package-internal shared resolver: turn a CLI config's branded\n// `unstable_defineApp` app into its declared interfaces, or `null` for a plain\n// project. The build and deploy accessors (actions/build, actions/deploy) each\n// build their command-specific view on top of this one brand-check +\n// extraction, so the discrimination lives in exactly one place.\n\nimport {type AppVisibility, type CliConfig} from '@sanity/cli-core'\n\nimport {type DefineAppInput, isWorkbenchApp, readConfig, type WorkbenchApp} from './defineApp.js'\n\n/**\n * Bundled so adding a declaration family touches this type and the artifact\n * expanders, not every hop of build/dev plumbing in between.\n * @internal\n */\nexport interface WorkbenchExposes {\n config?: WorkbenchApp['config']\n services?: DefineAppInput['services']\n views?: DefineAppInput['views']\n}\n\n/** @public */\nexport interface ResolvedWorkbenchApp {\n /** The app's unique `name` from `unstable_defineApp`. */\n readonly name: string\n /** Background worker services the app declares. */\n readonly services: NonNullable<DefineAppInput['services']>\n\n /** Dock panel views the app declares. */\n readonly views: NonNullable<DefineAppInput['views']>\n\n /** Resolved app kind — `studio` or one of the SDK app types. */\n readonly applicationType?: string\n /** Deploys on its own path, separate from the interfaces. */\n readonly config?: WorkbenchApp['config']\n /** SDK app-view entrypoint, when declared. */\n readonly entry?: string\n /** Explicit singleton flag (a Sanity-owned app); `undefined` when the app doesn't set it. */\n readonly isSingleton?: boolean\n /** Hostname the application is created at on first deploy. */\n readonly slug?: string\n /** Dashboard visibility declared by the app; `undefined` when unset. */\n readonly visibility?: AppVisibility\n}\n\n/**\n * Resolve the workbench app for a CLI config, or `null` for a plain project.\n * @public\n */\nexport function resolveWorkbenchApp(\n cliConfig: CliConfig | null | undefined,\n): ResolvedWorkbenchApp | null {\n const app = cliConfig?.app\n if (!isWorkbenchApp(app)) return null\n\n return {\n applicationType: app.applicationType,\n config: readConfig(app),\n entry: app.entry,\n isSingleton: app.isSingleton,\n name: app.name,\n services: app.services ?? [],\n slug: app.slug,\n views: app.views ?? [],\n visibility: app.visibility,\n }\n}\n"],"names":["isWorkbenchApp","readConfig","resolveWorkbenchApp","cliConfig","app","applicationType","config","entry","isSingleton","name","services","slug","views","visibility"],"mappings":"AAAA,gEAAgE;AAChE,+EAA+E;AAC/E,+EAA+E;AAC/E,qEAAqE;AACrE,gEAAgE;AAIhE,SAA6BA,cAAc,EAAEC,UAAU,QAA0B,iBAAgB;AAqCjG;;;CAGC,GACD,OAAO,SAASC,oBACdC,SAAuC;IAEvC,MAAMC,MAAMD,WAAWC;IACvB,IAAI,CAACJ,eAAeI,MAAM,OAAO;IAEjC,OAAO;QACLC,iBAAiBD,IAAIC,eAAe;QACpCC,QAAQL,WAAWG;QACnBG,OAAOH,IAAIG,KAAK;QAChBC,aAAaJ,IAAII,WAAW;QAC5BC,MAAML,IAAIK,IAAI;QACdC,UAAUN,IAAIM,QAAQ,IAAI,EAAE;QAC5BC,MAAMP,IAAIO,IAAI;QACdC,OAAOR,IAAIQ,KAAK,IAAI,EAAE;QACtBC,YAAYT,IAAIS,UAAU;IAC5B;AACF"}
1
+ {"version":3,"sources":["../src/resolveWorkbenchApp.ts"],"sourcesContent":["// Package-internal shared resolver: turn a CLI config's branded\n// `unstable_defineApp` app into its declared interfaces, or `null` for a plain\n// project. The build and deploy accessors (actions/build, actions/deploy) each\n// build their command-specific view on top of this one brand-check +\n// extraction, so the discrimination lives in exactly one place.\n\nimport {type AppVisibility, type CliConfig} from '@sanity/cli-core'\n\nimport {type DefineAppInput, isWorkbenchApp, readConfig, type WorkbenchApp} from './defineApp.js'\n\n/**\n * Bundled so adding a declaration family touches this type and the artifact\n * expanders, not every hop of build/dev plumbing in between.\n * @internal\n */\nexport interface WorkbenchExposes {\n config?: WorkbenchApp['config']\n services?: DefineAppInput['services']\n views?: DefineAppInput['views']\n}\n\n/** @public */\nexport interface ResolvedWorkbenchApp {\n /** The app's unique `name` from `unstable_defineApp`. */\n readonly name: string\n /** Background worker services the app declares. */\n readonly services: NonNullable<DefineAppInput['services']>\n\n /** Dock panel views the app declares. */\n readonly views: NonNullable<DefineAppInput['views']>\n\n /** Resolved app kind — `studio` or one of the SDK app types. */\n readonly applicationType?: string\n /** Deploys on its own path, separate from the interfaces. */\n readonly config?: WorkbenchApp['config']\n /** SDK app-view entrypoint, when declared. */\n readonly entry?: string\n /** Path to the app's icon SVG, resolved and shipped to Brett on deploy. */\n readonly icon?: string\n /** Explicit singleton flag (a Sanity-owned app); `undefined` when the app doesn't set it. */\n readonly isSingleton?: boolean\n /** Hostname the application is created at on first deploy. */\n readonly slug?: string\n /** Dashboard visibility declared by the app; `undefined` when unset. */\n readonly visibility?: AppVisibility\n}\n\n/**\n * Resolve the workbench app for a CLI config, or `null` for a plain project.\n * @public\n */\nexport function resolveWorkbenchApp(\n cliConfig: CliConfig | null | undefined,\n): ResolvedWorkbenchApp | null {\n const app = cliConfig?.app\n if (!isWorkbenchApp(app)) return null\n\n return {\n applicationType: app.applicationType,\n config: readConfig(app),\n entry: app.entry,\n icon: app.icon,\n isSingleton: app.isSingleton,\n name: app.name,\n services: app.services ?? [],\n slug: app.slug,\n views: app.views ?? [],\n visibility: app.visibility,\n }\n}\n"],"names":["isWorkbenchApp","readConfig","resolveWorkbenchApp","cliConfig","app","applicationType","config","entry","icon","isSingleton","name","services","slug","views","visibility"],"mappings":"AAAA,gEAAgE;AAChE,+EAA+E;AAC/E,+EAA+E;AAC/E,qEAAqE;AACrE,gEAAgE;AAIhE,SAA6BA,cAAc,EAAEC,UAAU,QAA0B,iBAAgB;AAuCjG;;;CAGC,GACD,OAAO,SAASC,oBACdC,SAAuC;IAEvC,MAAMC,MAAMD,WAAWC;IACvB,IAAI,CAACJ,eAAeI,MAAM,OAAO;IAEjC,OAAO;QACLC,iBAAiBD,IAAIC,eAAe;QACpCC,QAAQL,WAAWG;QACnBG,OAAOH,IAAIG,KAAK;QAChBC,MAAMJ,IAAII,IAAI;QACdC,aAAaL,IAAIK,WAAW;QAC5BC,MAAMN,IAAIM,IAAI;QACdC,UAAUP,IAAIO,QAAQ,IAAI,EAAE;QAC5BC,MAAMR,IAAIQ,IAAI;QACdC,OAAOT,IAAIS,KAAK,IAAI,EAAE;QACtBC,YAAYV,IAAIU,UAAU;IAC5B;AACF"}
@@ -28,7 +28,7 @@ export async function getApplication(applicationId) {
28
28
  }
29
29
  }
30
30
  /** Create an application and its first deployment in one call. */ export async function createApplication(options) {
31
- const { interfaces, isSingleton, organizationId, projectId, slug, tarball, title, type, version, visibility, workspaces } = options;
31
+ const { icon, interfaces, isSingleton, organizationId, projectId, slug, tarball, title, type, version, visibility, workspaces } = options;
32
32
  const formData = new FormData();
33
33
  formData.append('type', type);
34
34
  formData.append('title', title);
@@ -42,6 +42,8 @@ export async function getApplication(applicationId) {
42
42
  projectId
43
43
  }
44
44
  });
45
+ // Application-level JSON part, independent of the deployment.
46
+ if (icon) appendJson(formData, 'icon', icon);
45
47
  appendDeploymentParts(formData, {
46
48
  interfaces,
47
49
  tarball,
@@ -50,6 +52,17 @@ export async function getApplication(applicationId) {
50
52
  });
51
53
  return request(`/applications`, formData);
52
54
  }
55
+ /**
56
+ * Patch an application's mutable fields. The deploy endpoint ignores these, so a
57
+ * redeploy syncs the title (and icon) from config here alongside the new deployment.
58
+ */ export async function updateApplication(applicationId, update) {
59
+ const client = await getClient();
60
+ await client.request({
61
+ body: update,
62
+ method: 'PATCH',
63
+ uri: `/applications/${applicationId}`
64
+ });
65
+ }
53
66
  /** Deploy a new active version to an existing application. */ export async function createDeployment(options) {
54
67
  const { applicationId, interfaces, isAutoUpdating, tarball, version, workspaces } = options;
55
68
  const formData = new FormData();
@@ -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 {isStaging} from '@sanity/cli-core/util'\nimport FormData from 'form-data'\n\nimport {type AppInterfaceMetadata} 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\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: AppInterfaceMetadata | null; type: 'app'})\n | (BrettInterfaceBase & {metadata: null; type: 'panel'})\n | (BrettInterfaceBase & {metadata: null; type: 'worker'})\n\n/** A studio workspace as Brett stores it. */\nexport interface BrettWorkspace {\n dataset: string\n projectId: 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' | 'type'>,\n): string {\n const segment = application.type === 'studio' ? 'studio' : 'application'\n return `${getWorkbenchUrl(application.organizationId)}/${segment}/${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({uri: `/applications/${applicationId}`})\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode === 404) return null\n throw err\n }\n}\n\n/** Create an application and its first deployment in one call. */\nexport async function createApplication(options: {\n interfaces: readonly BrettInterface[]\n isSingleton?: boolean\n organizationId: string\n projectId?: string\n slug: string\n tarball: Gzip\n title: string\n type: ApplicationType\n version: string\n visibility?: AppVisibility\n workspaces?: readonly BrettWorkspace[]\n}): Promise<Application> {\n const {\n interfaces,\n isSingleton,\n organizationId,\n projectId,\n slug,\n tarball,\n title,\n type,\n version,\n visibility,\n workspaces,\n } = options\n const formData = new FormData()\n formData.append('type', type)\n formData.append('title', title)\n formData.append('organizationId', organizationId)\n formData.append('slug', slug)\n if (isSingleton !== undefined) formData.append('isSingleton', String(isSingleton))\n if (visibility) formData.append('visibility', visibility)\n // Studio config is set once, at create — it's immutable on redeploy.\n if (projectId) appendJson(formData, 'config', {studio: {projectId}})\n appendDeploymentParts(formData, {interfaces, tarball, version, workspaces})\n return request(`/applications`, formData)\n}\n\n/** Deploy a new active version to an existing application. */\nexport async function createDeployment(options: {\n applicationId: string\n interfaces: readonly BrettInterface[]\n isAutoUpdating: boolean\n tarball: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n}): Promise<{id: string}> {\n const {applicationId, interfaces, isAutoUpdating, tarball, version, workspaces} = options\n const formData = new FormData()\n formData.append('isAutoUpdating', isAutoUpdating.toString())\n appendDeploymentParts(formData, {interfaces, 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', uri: `/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 interfaces,\n tarball,\n version,\n workspaces,\n }: {\n interfaces: readonly BrettInterface[]\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 formData.append('tarball', tarball, {contentType: 'application/gzip', filename: 'app.tar.gz'})\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>(uri: 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 uri,\n })\n}\n"],"names":["PassThrough","getGlobalCliClient","isStaging","FormData","APP_WORKBENCH_API_VERSION","getWorkbenchUrl","organizationId","getApplicationUrl","application","segment","type","id","getClient","apiVersion","requireUser","getApplication","applicationId","client","request","uri","err","statusCode","createApplication","options","interfaces","isSingleton","projectId","slug","tarball","title","version","visibility","workspaces","formData","append","undefined","String","appendJson","studio","appendDeploymentParts","createDeployment","isAutoUpdating","toString","deleteApplication","method","length","contentType","fil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A,oEAAoE,GACpE,SAASV,WAAWJ,QAAkB,EAAEe,IAAY,EAAEC,KAAc;IAClEhB,SAASC,MAAM,CAACc,MAAME,KAAKC,SAAS,CAACF,QAAQ;QAACH,aAAa;IAAkB;AAC/E;AAEA,eAAe5B,QAAWC,GAAW,EAAEc,QAAkB;IACvD,MAAMhB,SAAS,MAAML;IACrB,OAAOK,OAAOC,OAAO,CAAC;QACpBkC,MAAMnB,SAASoB,IAAI,CAAC,IAAIrD;QACxBsD,SAASrB,SAASsB,UAAU;QAC5BX,QAAQ;QACRzB;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 {isStaging} from '@sanity/cli-core/util'\nimport FormData from 'form-data'\n\nimport {type AppInterfaceMetadata} 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\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: AppInterfaceMetadata | null; type: 'app'})\n | (BrettInterfaceBase & {metadata: null; type: 'panel'})\n | (BrettInterfaceBase & {metadata: null; type: 'worker'})\n\n/** A studio workspace as Brett stores it. */\nexport interface BrettWorkspace {\n dataset: string\n projectId: 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' | 'type'>,\n): string {\n const segment = application.type === 'studio' ? 'studio' : 'application'\n return `${getWorkbenchUrl(application.organizationId)}/${segment}/${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({uri: `/applications/${applicationId}`})\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode === 404) return null\n throw err\n }\n}\n\n/** Create an application and its first deployment in one call. */\nexport async function createApplication(options: {\n icon?: string\n interfaces: readonly BrettInterface[]\n isSingleton?: boolean\n organizationId: string\n projectId?: string\n slug: string\n tarball: Gzip\n title: string\n type: ApplicationType\n version: string\n visibility?: AppVisibility\n workspaces?: readonly BrettWorkspace[]\n}): Promise<Application> {\n const {\n icon,\n interfaces,\n isSingleton,\n organizationId,\n projectId,\n slug,\n tarball,\n title,\n type,\n version,\n visibility,\n workspaces,\n } = options\n const formData = new FormData()\n formData.append('type', type)\n formData.append('title', title)\n formData.append('organizationId', organizationId)\n formData.append('slug', slug)\n if (isSingleton !== undefined) formData.append('isSingleton', String(isSingleton))\n if (visibility) formData.append('visibility', visibility)\n // Studio config is set once, at create — it's immutable on redeploy.\n if (projectId) appendJson(formData, 'config', {studio: {projectId}})\n // Application-level JSON part, independent of the deployment.\n if (icon) appendJson(formData, 'icon', icon)\n appendDeploymentParts(formData, {interfaces, tarball, version, workspaces})\n return request(`/applications`, formData)\n}\n\n/** Mutable application fields the deploy flow patches after create. */\nexport interface ApplicationUpdate {\n icon?: string | null\n title?: string\n}\n\n/**\n * Patch an application's mutable fields. The deploy endpoint ignores these, so a\n * redeploy syncs the title (and icon) from config here alongside the new deployment.\n */\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', uri: `/applications/${applicationId}`})\n}\n\n/** Deploy a new active version to an existing application. */\nexport async function createDeployment(options: {\n applicationId: string\n interfaces: readonly BrettInterface[]\n isAutoUpdating: boolean\n tarball: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n}): Promise<{id: string}> {\n const {applicationId, interfaces, isAutoUpdating, tarball, version, workspaces} = options\n const formData = new FormData()\n formData.append('isAutoUpdating', isAutoUpdating.toString())\n appendDeploymentParts(formData, {interfaces, 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', uri: `/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 interfaces,\n tarball,\n version,\n workspaces,\n }: {\n interfaces: readonly BrettInterface[]\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 formData.append('tarball', tarball, {contentType: 'application/gzip', filename: 'app.tar.gz'})\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>(uri: 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 uri,\n })\n}\n"],"names":["PassThrough","getGlobalCliClient","isStaging","FormData","APP_WORKBENCH_API_VERSION","getWorkbenchUrl","organizationId","getApplicationUrl","application","segment","type","id","getClient","apiVersion","requireUser","getApplication","applicationId","client","request","uri","err","statusCode","createApplication","options","icon","interfaces","isSingleton","projectId","slug","tarball","title","version","visibility","workspaces","formData","append","undefined","String","appendJson","studio","appendDeploymentParts","updateApplication","update","body","method","createDeployment","isAutoUpdating","toString","deleteApplication","length","contentType","filename","name","value","JSON","stringify","pipe","headers","getHeaders"],"mappings":"AAAA,SAAQA,WAAW,QAAO,cAAa;AAGvC,SAA4BC,kBAAkB,QAAO,mBAAkB;AACvE,SAAQC,SAAS,QAAO,wBAAuB;AAC/C,OAAOC,cAAc,YAAW;AAGhC,SAAQC,yBAAyB,QAAO,kBAAiB;AAyCzD,OAAO,SAASC,gBAAgBC,cAAsB;IACpD,OAAO,CAAC,QAAQ,EAAEA,eAAe,CAAC,EAAEJ,cAAc,oBAAoB,cAAc;AACtF;AAEA,4EAA4E,GAC5E,OAAO,SAASK,kBACdC,WAAgE;IAEhE,MAAMC,UAAUD,YAAYE,IAAI,KAAK,WAAW,WAAW;IAC3D,OAAO,GAAGL,gBAAgBG,YAAYF,cAAc,EAAE,CAAC,EAAEG,QAAQ,CAAC,EAAED,YAAYG,EAAE,EAAE;AACtF;AAEA,eAAeC;IACb,OAAOX,mBAAmB;QAACY,YAAYT;QAA2BU,aAAa;IAAI;AACrF;AAEA,OAAO,eAAeC,eAAeC,aAAqB;IACxD,MAAMC,SAAS,MAAML;IACrB,IAAI;QACF,OAAO,MAAMK,OAAOC,OAAO,CAAC;YAACC,KAAK,CAAC,cAAc,EAAEH,eAAe;QAAA;IACpE,EAAE,OAAOI,KAAK;QACZ,IAAI,AAACA,KAA+BC,eAAe,KAAK,OAAO;QAC/D,MAAMD;IACR;AACF;AAEA,gEAAgE,GAChE,OAAO,eAAeE,kBAAkBC,OAavC;IACC,MAAM,EACJC,IAAI,EACJC,UAAU,EACVC,WAAW,EACXpB,cAAc,EACdqB,SAAS,EACTC,IAAI,EACJC,OAAO,EACPC,KAAK,EACLpB,IAAI,EACJqB,OAAO,EACPC,UAAU,EACVC,UAAU,EACX,GAAGV;IACJ,MAAMW,WAAW,IAAI/B;IACrB+B,SAASC,MAAM,CAAC,QAAQzB;IACxBwB,SAASC,MAAM,CAAC,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ACA,KAA+BC,eAAe,KAAK,MAAMD;IAChE;AACF;AAEA,SAASoB,sBACPN,QAAkB,EAClB,EACET,UAAU,EACVI,OAAO,EACPE,OAAO,EACPE,UAAU,EAMX;IAEDC,SAASC,MAAM,CAAC,WAAWJ;IAC3BO,WAAWJ,UAAU,cAAcT;IACnC,0EAA0E;IAC1E,IAAIQ,YAAYgB,QAAQX,WAAWJ,UAAU,cAAcD;IAC3DC,SAASC,MAAM,CAAC,WAAWN,SAAS;QAACqB,aAAa;QAAoBC,UAAU;IAAY;AAC9F;AAEA,oEAAoE,GACpE,SAASb,WAAWJ,QAAkB,EAAEkB,IAAY,EAAEC,KAAc;IAClEnB,SAASC,MAAM,CAACiB,MAAME,KAAKC,SAAS,CAACF,QAAQ;QAACH,aAAa;IAAkB;AAC/E;AAEA,eAAehC,QAAWC,GAAW,EAAEe,QAAkB;IACvD,MAAMjB,SAAS,MAAML;IACrB,OAAOK,OAAOC,OAAO,CAAC;QACpByB,MAAMT,SAASsB,IAAI,CAAC,IAAIxD;QACxByD,SAASvB,SAASwB,UAAU;QAC5Bd,QAAQ;QACRzB;IACF;AACF"}
@@ -0,0 +1,75 @@
1
+ /** How long teardown may run before we stop waiting and force the process to
2
+ * exit — long enough for Vite servers and watchers to close, short enough not to
3
+ * strand a backgrounded process. */ const SHUTDOWN_GRACE_MS = 5000;
4
+ /**
5
+ * Map a server's bind address to a host that's safe to show in a URL. Bind-only
6
+ * addresses ('0.0.0.0', '::') aren't routable in every browser (notably on
7
+ * Windows), so fall back to localhost for display. The bind address itself is
8
+ * untouched — this only affects the URL printed to the user.
9
+ */ export function toDisplayHost(host) {
10
+ if (!host || host === '0.0.0.0' || host === '::' || host === '[::]') {
11
+ return 'localhost';
12
+ }
13
+ return host;
14
+ }
15
+ /**
16
+ * Shuts down a command that runs several long-lived servers at once. Both
17
+ * `sanity dev` and `sanity start` start a workbench shell, an app remote, and a
18
+ * registry entry, and every one of them has to be stopped again — on a clean
19
+ * exit, on a startup error, or when the user presses Ctrl-C.
20
+ *
21
+ * How it works:
22
+ * - Each server adds its own shutdown function to `closers` as it starts.
23
+ * - `close()` runs them in reverse (last started, first stopped), and only
24
+ * runs them once no matter how many times it's called.
25
+ * - `installSignalHandlers()` makes Ctrl-C / kill trigger that same `close()`.
26
+ *
27
+ * Signals need care: Node would normally exit the instant one arrives, but our
28
+ * shutdown is async. So we catch the signal, run `close()`, and only then send
29
+ * the signal on again so the process exits with its usual code. A timer is the
30
+ * escape hatch — if shutdown ever hangs, it forces the exit rather than leaving
31
+ * the process stuck.
32
+ */ export function createServerLifecycle() {
33
+ const closers = [];
34
+ const runClosers = async ()=>{
35
+ // Reverse order, so each server is stopped before the one it was started on
36
+ // top of. A closer that throws is ignored so one failure can't block the rest.
37
+ for (const closeResource of closers.splice(0).toReversed()){
38
+ await closeResource().catch(()=>{});
39
+ }
40
+ };
41
+ // `close` can be called more than once — a startup error and then a Ctrl-C, or
42
+ // two signals racing. Keep the first call's promise and hand it back to the
43
+ // rest, so everything is torn down exactly once.
44
+ let teardown;
45
+ const close = ()=>{
46
+ teardown ??= (async ()=>{
47
+ process.off('SIGINT', onSignal);
48
+ process.off('SIGTERM', onSignal);
49
+ await runClosers();
50
+ })();
51
+ return teardown;
52
+ };
53
+ function onSignal(signal) {
54
+ // Force the exit if shutdown doesn't finish in time, so a wedged server
55
+ // can't hang the process forever.
56
+ const graceTimer = setTimeout(()=>process.kill(process.pid, signal), SHUTDOWN_GRACE_MS);
57
+ graceTimer.unref();
58
+ // Tear down first, then re-send the signal so the process exits with the
59
+ // code it normally would for this signal.
60
+ void close().finally(()=>{
61
+ clearTimeout(graceTimer);
62
+ process.kill(process.pid, signal);
63
+ });
64
+ }
65
+ return {
66
+ close,
67
+ closers,
68
+ installSignalHandlers () {
69
+ process.once('SIGINT', onSignal);
70
+ process.once('SIGTERM', onSignal);
71
+ }
72
+ };
73
+ }
74
+
75
+ //# sourceMappingURL=serverOrchestration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/serverOrchestration.ts"],"sourcesContent":["/** How long teardown may run before we stop waiting and force the process to\n * exit — long enough for Vite servers and watchers to close, short enough not to\n * strand a backgrounded process. */\nconst SHUTDOWN_GRACE_MS = 5000\n\n/**\n * Map a server's bind address to a host that's safe to show in a URL. Bind-only\n * addresses ('0.0.0.0', '::') aren't routable in every browser (notably on\n * Windows), so fall back to localhost for display. The bind address itself is\n * untouched — this only affects the URL printed to the user.\n */\nexport function toDisplayHost(host: string | undefined): string {\n if (!host || host === '0.0.0.0' || host === '::' || host === '[::]') {\n return 'localhost'\n }\n return host\n}\n\nexport interface ServerLifecycle {\n /** Tear everything down exactly once and stop listening for signals. Safe to call more than once. */\n close: () => Promise<void>\n /**\n * Shutdown functions, one per server/resource. Push one as each resource\n * starts; `close` unwinds them in reverse. A throwing closer is swallowed so\n * one bad teardown can't strand the rest.\n */\n closers: Array<() => Promise<void>>\n /** Begin handling Ctrl-C / kill by tearing down, then re-raising the signal so the process still exits. */\n installSignalHandlers: () => void\n}\n\n/**\n * Shuts down a command that runs several long-lived servers at once. Both\n * `sanity dev` and `sanity start` start a workbench shell, an app remote, and a\n * registry entry, and every one of them has to be stopped again — on a clean\n * exit, on a startup error, or when the user presses Ctrl-C.\n *\n * How it works:\n * - Each server adds its own shutdown function to `closers` as it starts.\n * - `close()` runs them in reverse (last started, first stopped), and only\n * runs them once no matter how many times it's called.\n * - `installSignalHandlers()` makes Ctrl-C / kill trigger that same `close()`.\n *\n * Signals need care: Node would normally exit the instant one arrives, but our\n * shutdown is async. So we catch the signal, run `close()`, and only then send\n * the signal on again so the process exits with its usual code. A timer is the\n * escape hatch — if shutdown ever hangs, it forces the exit rather than leaving\n * the process stuck.\n */\nexport function createServerLifecycle(): ServerLifecycle {\n const closers: ServerLifecycle['closers'] = []\n\n const runClosers = async () => {\n // Reverse order, so each server is stopped before the one it was started on\n // top of. A closer that throws is ignored so one failure can't block the rest.\n for (const closeResource of closers.splice(0).toReversed()) {\n await closeResource().catch(() => {})\n }\n }\n\n // `close` can be called more than once — a startup error and then a Ctrl-C, or\n // two signals racing. Keep the first call's promise and hand it back to the\n // rest, so everything is torn down exactly once.\n let teardown: Promise<void> | undefined\n const close = () => {\n teardown ??= (async () => {\n process.off('SIGINT', onSignal)\n process.off('SIGTERM', onSignal)\n await runClosers()\n })()\n return teardown\n }\n\n function onSignal(signal: NodeJS.Signals) {\n // Force the exit if shutdown doesn't finish in time, so a wedged server\n // can't hang the process forever.\n const graceTimer = setTimeout(() => process.kill(process.pid, signal), SHUTDOWN_GRACE_MS)\n graceTimer.unref()\n // Tear down first, then re-send the signal so the process exits with the\n // code it normally would for this signal.\n void close().finally(() => {\n clearTimeout(graceTimer)\n process.kill(process.pid, signal)\n })\n }\n\n return {\n close,\n closers,\n installSignalHandlers() {\n process.once('SIGINT', onSignal)\n process.once('SIGTERM', onSignal)\n },\n }\n}\n"],"names":["SHUTDOWN_GRACE_MS","toDisplayHost","host","createServerLifecycle","closers","runClosers","closeResource","splice","toReversed","catch","teardown","close","process","off","onSignal","signal","graceTimer","setTimeout","kill","pid","unref","finally","clearTimeout","installSignalHandlers","once"],"mappings":"AAAA;;kCAEkC,GAClC,MAAMA,oBAAoB;AAE1B;;;;;CAKC,GACD,OAAO,SAASC,cAAcC,IAAwB;IACpD,IAAI,CAACA,QAAQA,SAAS,aAAaA,SAAS,QAAQA,SAAS,QAAQ;QACnE,OAAO;IACT;IACA,OAAOA;AACT;AAeA;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASC;IACd,MAAMC,UAAsC,EAAE;IAE9C,MAAMC,aAAa;QACjB,4EAA4E;QAC5E,+EAA+E;QAC/E,KAAK,MAAMC,iBAAiBF,QAAQG,MAAM,CAAC,GAAGC,UAAU,GAAI;YAC1D,MAAMF,gBAAgBG,KAAK,CAAC,KAAO;QACrC;IACF;IAEA,+EAA+E;IAC/E,4EAA4E;IAC5E,iDAAiD;IACjD,IAAIC;IACJ,MAAMC,QAAQ;QACZD,aAAa,AAAC,CAAA;YACZE,QAAQC,GAAG,CAAC,UAAUC;YACtBF,QAAQC,GAAG,CAAC,WAAWC;YACvB,MAAMT;QACR,CAAA;QACA,OAAOK;IACT;IAEA,SAASI,SAASC,MAAsB;QACtC,wEAAwE;QACxE,kCAAkC;QAClC,MAAMC,aAAaC,WAAW,IAAML,QAAQM,IAAI,CAACN,QAAQO,GAAG,EAAEJ,SAASf;QACvEgB,WAAWI,KAAK;QAChB,yEAAyE;QACzE,0CAA0C;QAC1C,KAAKT,QAAQU,OAAO,CAAC;YACnBC,aAAaN;YACbJ,QAAQM,IAAI,CAACN,QAAQO,GAAG,EAAEJ;QAC5B;IACF;IAEA,OAAO;QACLJ;QACAP;QACAmB;YACEX,QAAQY,IAAI,CAAC,UAAUV;YACvBF,QAAQY,IAAI,CAAC,WAAWV;QAC1B;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/workbench-cli",
3
- "version": "1.5.0",
3
+ "version": "1.6.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",
@@ -39,6 +39,10 @@
39
39
  "source": "./src/_exports/init.ts",
40
40
  "default": "./dist/_exports/init.js"
41
41
  },
42
+ "./preview": {
43
+ "source": "./src/_exports/preview.ts",
44
+ "default": "./dist/_exports/preview.js"
45
+ },
42
46
  "./undeploy": {
43
47
  "source": "./src/_exports/undeploy.ts",
44
48
  "default": "./dist/_exports/undeploy.js"
@@ -49,13 +53,13 @@
49
53
  "access": "public"
50
54
  },
51
55
  "dependencies": {
52
- "@module-federation/vite": "1.17.1",
56
+ "@module-federation/vite": "1.18.1",
53
57
  "@vitejs/plugin-react": "^6.0.3",
54
58
  "form-data": "^4.0.5",
55
59
  "tar-fs": "^3.1.2",
56
60
  "vite": "^8.1.5",
57
61
  "zod": "^4.4.3",
58
- "@sanity/cli-core": "^2.5.0"
62
+ "@sanity/cli-core": "^2.5.1"
59
63
  },
60
64
  "devDependencies": {
61
65
  "@eslint/compat": "^2.1.0",