@sanity/workbench-cli 1.5.0 → 1.7.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 (48) hide show
  1. package/dist/_exports/build.d.ts +47 -3
  2. package/dist/_exports/build.js +2 -0
  3. package/dist/_exports/build.js.map +1 -1
  4. package/dist/_exports/deploy.d.ts +60 -37
  5. package/dist/_exports/deploy.js +1 -1
  6. package/dist/_exports/deploy.js.map +1 -1
  7. package/dist/_exports/dev.d.ts +0 -2
  8. package/dist/_exports/index.d.ts +39 -1
  9. package/dist/_exports/index.js +1 -0
  10. package/dist/_exports/index.js.map +1 -1
  11. package/dist/_exports/init.d.ts +2 -2
  12. package/dist/_exports/preview.d.ts +169 -0
  13. package/dist/_exports/preview.js +3 -0
  14. package/dist/_exports/preview.js.map +1 -0
  15. package/dist/_exports/undeploy.d.ts +7 -3
  16. package/dist/actions/build/vite/optimize-deps.js +84 -0
  17. package/dist/actions/build/vite/optimize-deps.js.map +1 -0
  18. package/dist/actions/build/vite/plugins/plugin-sanity-app-id.js +15 -1
  19. package/dist/actions/build/vite/plugins/plugin-sanity-app-id.js.map +1 -1
  20. package/dist/actions/deploy/checkBuiltOutput.js +16 -2
  21. package/dist/actions/deploy/checkBuiltOutput.js.map +1 -1
  22. package/dist/actions/deploy/deployWorkbenchApp.js +55 -73
  23. package/dist/actions/deploy/deployWorkbenchApp.js.map +1 -1
  24. package/dist/actions/dev/registry.js +69 -1
  25. package/dist/actions/dev/registry.js.map +1 -1
  26. package/dist/actions/dev/startDevServerRegistration.js +9 -2
  27. package/dist/actions/dev/startDevServerRegistration.js.map +1 -1
  28. package/dist/actions/dev/startWorkbenchDev.js +7 -43
  29. package/dist/actions/dev/startWorkbenchDev.js.map +1 -1
  30. package/dist/actions/dev/startWorkbenchDevServer.js +7 -3
  31. package/dist/actions/dev/startWorkbenchDevServer.js.map +1 -1
  32. package/dist/actions/init/cliConfig.js +2 -0
  33. package/dist/actions/init/cliConfig.js.map +1 -1
  34. package/dist/actions/preview/serveBuiltApplication.js +53 -0
  35. package/dist/actions/preview/serveBuiltApplication.js.map +1 -0
  36. package/dist/actions/preview/startWorkbenchPreview.js +107 -0
  37. package/dist/actions/preview/startWorkbenchPreview.js.map +1 -0
  38. package/dist/appId.js +52 -0
  39. package/dist/appId.js.map +1 -0
  40. package/dist/defineApp.js +2 -5
  41. package/dist/defineApp.js.map +1 -1
  42. package/dist/resolveWorkbenchApp.js +2 -0
  43. package/dist/resolveWorkbenchApp.js.map +1 -1
  44. package/dist/services/applications.js +37 -20
  45. package/dist/services/applications.js.map +1 -1
  46. package/dist/util/serverOrchestration.js +75 -0
  47. package/dist/util/serverOrchestration.js.map +1 -0
  48. package/package.json +7 -3
package/dist/appId.js ADDED
@@ -0,0 +1,52 @@
1
+ import { hash } from 'node:crypto';
2
+ /**
3
+ * File the build writes into its output, carrying the id compiled into the
4
+ * bundle. `sanity start` serves a build without recompiling, so it reads this
5
+ * instead of recomputing — a deploy inlines the API id, not the shape hash.
6
+ */ export const SANITY_APP_ID_FILE = 'sanity-app-id.txt';
7
+ /**
8
+ * Mints the id the workbench keys everything on (React keys, panel ownership, the
9
+ * message bus, and the bundle's `__SANITY_APP_ID__`). Each run mode derives it
10
+ * differently so a running dev app, a local build, and a deployed twin can't
11
+ * share one: `sanity dev` uses the bound address, `sanity build`/`start` a hash
12
+ * of the declared shape. `sanity deploy` resolves its own id from the
13
+ * applications API, so it isn't handled here.
14
+ */ export function resolveAppId(source) {
15
+ if ('app' in source) {
16
+ const { app } = source;
17
+ const canonical = (interfaces)=>(interfaces ?? []).map((i)=>[
18
+ i.type,
19
+ i.name,
20
+ i.src
21
+ ]).toSorted();
22
+ return hash('sha1', JSON.stringify({
23
+ config: app.exposes?.config ?? null,
24
+ entry: app.entry ?? null,
25
+ name: app.name,
26
+ organizationId: app.organizationId,
27
+ services: canonical(app.exposes?.services),
28
+ views: canonical(app.exposes?.views)
29
+ }), 'hex');
30
+ }
31
+ return `${source.host}-${source.port}`;
32
+ }
33
+ /**
34
+ * The `build`/`start` id for a workbench app — a hash of its declared shape.
35
+ * Shared so the bundle inlined by `sanity build` and the registry entry advertised
36
+ * by `sanity start` resolve to the same id.
37
+ */ export function buildAppId(app) {
38
+ return resolveAppId({
39
+ app: {
40
+ entry: app.entry,
41
+ exposes: {
42
+ config: app.config,
43
+ services: app.services,
44
+ views: app.views
45
+ },
46
+ name: app.name,
47
+ organizationId: app.organizationId
48
+ }
49
+ });
50
+ }
51
+
52
+ //# sourceMappingURL=appId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/appId.ts"],"sourcesContent":["import {hash} from 'node:crypto'\n\nimport {type ResolvedWorkbenchApp, type WorkbenchExposes} from './resolveWorkbenchApp.js'\n\n/**\n * File the build writes into its output, carrying the id compiled into the\n * bundle. `sanity start` serves a build without recompiling, so it reads this\n * instead of recomputing — a deploy inlines the API id, not the shape hash.\n */\nexport const SANITY_APP_ID_FILE = 'sanity-app-id.txt'\n\n/** The declared shape hashed into a build id — the app's identity, not its code. */\nexport interface BuildAppIdentity {\n name: string\n organizationId: string\n\n entry?: string\n exposes?: WorkbenchExposes\n}\n\n/**\n * Mints the id the workbench keys everything on (React keys, panel ownership, the\n * message bus, and the bundle's `__SANITY_APP_ID__`). Each run mode derives it\n * differently so a running dev app, a local build, and a deployed twin can't\n * share one: `sanity dev` uses the bound address, `sanity build`/`start` a hash\n * of the declared shape. `sanity deploy` resolves its own id from the\n * applications API, so it isn't handled here.\n */\nexport function resolveAppId(\n source: {app: BuildAppIdentity} | {host: string; port: number},\n): string {\n if ('app' in source) {\n const {app} = source\n const canonical = (\n interfaces: ReadonlyArray<{name: string; src: string; type: string}> | undefined,\n ): Array<[string, string, string]> =>\n (interfaces ?? []).map((i): [string, string, string] => [i.type, i.name, i.src]).toSorted()\n return hash(\n 'sha1',\n JSON.stringify({\n config: app.exposes?.config ?? null,\n entry: app.entry ?? null,\n name: app.name,\n organizationId: app.organizationId,\n services: canonical(app.exposes?.services),\n views: canonical(app.exposes?.views),\n }),\n 'hex',\n )\n }\n return `${source.host}-${source.port}`\n}\n\n/**\n * The `build`/`start` id for a workbench app — a hash of its declared shape.\n * Shared so the bundle inlined by `sanity build` and the registry entry advertised\n * by `sanity start` resolve to the same id.\n */\nexport function buildAppId(app: ResolvedWorkbenchApp): string {\n return resolveAppId({\n app: {\n entry: app.entry,\n exposes: {config: app.config, services: app.services, views: app.views},\n name: app.name,\n organizationId: app.organizationId,\n },\n })\n}\n"],"names":["hash","SANITY_APP_ID_FILE","resolveAppId","source","app","canonical","interfaces","map","i","type","name","src","toSorted","JSON","stringify","config","exposes","entry","organizationId","services","views","host","port","buildAppId"],"mappings":"AAAA,SAAQA,IAAI,QAAO,cAAa;AAIhC;;;;CAIC,GACD,OAAO,MAAMC,qBAAqB,oBAAmB;AAWrD;;;;;;;CAOC,GACD,OAAO,SAASC,aACdC,MAA8D;IAE9D,IAAI,SAASA,QAAQ;QACnB,MAAM,EAACC,GAAG,EAAC,GAAGD;QACd,MAAME,YAAY,CAChBC,aAEA,AAACA,CAAAA,cAAc,EAAE,AAAD,EAAGC,GAAG,CAAC,CAACC,IAAgC;oBAACA,EAAEC,IAAI;oBAAED,EAAEE,IAAI;oBAAEF,EAAEG,GAAG;iBAAC,EAAEC,QAAQ;QAC3F,OAAOZ,KACL,QACAa,KAAKC,SAAS,CAAC;YACbC,QAAQX,IAAIY,OAAO,EAAED,UAAU;YAC/BE,OAAOb,IAAIa,KAAK,IAAI;YACpBP,MAAMN,IAAIM,IAAI;YACdQ,gBAAgBd,IAAIc,cAAc;YAClCC,UAAUd,UAAUD,IAAIY,OAAO,EAAEG;YACjCC,OAAOf,UAAUD,IAAIY,OAAO,EAAEI;QAChC,IACA;IAEJ;IACA,OAAO,GAAGjB,OAAOkB,IAAI,CAAC,CAAC,EAAElB,OAAOmB,IAAI,EAAE;AACxC;AAEA;;;;CAIC,GACD,OAAO,SAASC,WAAWnB,GAAyB;IAClD,OAAOF,aAAa;QAClBE,KAAK;YACHa,OAAOb,IAAIa,KAAK;YAChBD,SAAS;gBAACD,QAAQX,IAAIW,MAAM;gBAAEI,UAAUf,IAAIe,QAAQ;gBAAEC,OAAOhB,IAAIgB,KAAK;YAAA;YACtEV,MAAMN,IAAIM,IAAI;YACdQ,gBAAgBd,IAAIc,cAAc;QACpC;IACF;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,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;CA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B,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,MAAM,CACtB;IAEF,+EAA+E,GAC/ES,UAAUxB,EAAEY,QAAQ,CAACZ,EAAEyB,MAAM;IAC7B;;;;;KAKC,GACDC,UAAU1B,EAAEY,QAAQ,CAClBZ,EACG2B,KAAK,CAACxB,0BACNkB,KAAK,CACJrB,EAAE4B,MAAM,CACN,CAACF,WAAa,IAA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ClB;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,8 +14,10 @@ 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,
20
+ organizationId: app.organizationId,
19
21
  services: app.services ?? [],
20
22
  slug: app.slug,
21
23
  views: app.views ?? [],
@@ -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 /** Organization that owns the app — part of its build-id identity. */\n readonly organizationId: string\n /** Background worker services the app declares. */\n readonly services: NonNullable<DefineAppInput['services']>\n\n /** Hostname the application is created at on first deploy. */\n readonly slug: string\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 /** 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 organizationId: app.organizationId,\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","organizationId","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;AA0CjG;;;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,gBAAgBP,IAAIO,cAAc;QAClCC,UAAUR,IAAIQ,QAAQ,IAAI,EAAE;QAC5BC,MAAMT,IAAIS,IAAI;QACdC,OAAOV,IAAIU,KAAK,IAAI,EAAE;QACtBC,YAAYX,IAAIW,UAAU;IAC5B;AACF"}
@@ -27,28 +27,45 @@ export async function getApplication(applicationId) {
27
27
  throw err;
28
28
  }
29
29
  }
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;
32
- const formData = new FormData();
33
- formData.append('type', type);
34
- formData.append('title', title);
35
- formData.append('organizationId', organizationId);
36
- formData.append('slug', slug);
37
- if (isSingleton !== undefined) formData.append('isSingleton', String(isSingleton));
38
- if (visibility) formData.append('visibility', visibility);
39
- // Studio config is set once, at create — it's immutable on redeploy.
40
- if (projectId) appendJson(formData, 'config', {
41
- studio: {
42
- projectId
43
- }
30
+ /**
31
+ * Create an application record (no deployment), so the CLI can build with the
32
+ * returned id, then ship it via {@link createDeployment}.
33
+ */ export async function createApplication(options) {
34
+ const { isSingleton, organizationId, projectId, slug, title, type, visibility } = options;
35
+ const client = await getClient();
36
+ return client.request({
37
+ body: {
38
+ organizationId,
39
+ slug,
40
+ title,
41
+ type,
42
+ ...isSingleton === undefined ? {} : {
43
+ isSingleton
44
+ },
45
+ ...visibility ? {
46
+ visibility
47
+ } : {},
48
+ // Studio config is set once, at create — it's immutable on redeploy.
49
+ ...projectId ? {
50
+ config: {
51
+ studio: {
52
+ projectId
53
+ }
54
+ }
55
+ } : {}
56
+ },
57
+ method: 'POST',
58
+ uri: `/applications`
44
59
  });
45
- appendDeploymentParts(formData, {
46
- interfaces,
47
- tarball,
48
- version,
49
- workspaces
60
+ }
61
+ // Patch an application's mutable fields.
62
+ export async function updateApplication(applicationId, update) {
63
+ const client = await getClient();
64
+ await client.request({
65
+ body: update,
66
+ method: 'PATCH',
67
+ uri: `/applications/${applicationId}`
50
68
  });
51
- return request(`/applications`, formData);
52
69
  }
53
70
  /** Deploy a new active version to an existing application. */ export async function createDeployment(options) {
54
71
  const { applicationId, interfaces, isAutoUpdating, tarball, version, workspaces } = options;
@@ -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","filename","name","value","JSON","stringify","body","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,OAYvC;IACC,MAAM,EACJC,UAAU,EACVC,WAAW,EACXnB,cAAc,EACdoB,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AClB,EACET,UAAU,EACVI,OAAO,EACPE,OAAO,EACPE,UAAU,EAMX;IAEDC,SAASC,MAAM,CAAC,WAAWJ;IAC3BO,WAAWJ,UAAU,cAAcT;IACnC,0EAA0E;IAC1E,IAAIQ,YAAYa,QAAQR,WAAWJ,UAAU,cAAcD;IAC3DC,SAASC,MAAM,CAAC,WAAWN,SAAS;QAACkB,aAAa;QAAoBC,UAAU;IAAY;AAC9F;AAEA,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 /** 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' | '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/**\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 isSingleton?: boolean\n organizationId: string\n projectId?: string\n slug: string\n title: string\n type: ApplicationType\n visibility?: AppVisibility\n}): Promise<Application> {\n const {isSingleton, organizationId, projectId, slug, title, type, visibility} = options\n const client = await getClient()\n return client.request({\n body: {\n organizationId,\n slug,\n title,\n type,\n ...(isSingleton === undefined ? {} : {isSingleton}),\n ...(visibility ? {visibility} : {}),\n // Studio config is set once, at create — it's immutable on redeploy.\n ...(projectId ? {config: {studio: {projectId}}} : {}),\n },\n method: 'POST',\n uri: `/applications`,\n })\n}\n\n/** Mutable application fields the deploy flow patches after create. */\nexport interface ApplicationUpdate {\n icon?: string | null\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', 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","isSingleton","projectId","slug","title","visibility","body","undefined","config","studio","method","updateApplication","update","createDeployment","interfaces","isAutoUpdating","tarball","version","workspaces","formData","append","toString","appendDeploymentParts","deleteApplication","appendJson","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;AA2CzD,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;;;CAGC,GACD,OAAO,eAAeE,kBAAkBC,OAQvC;IACC,MAAM,EAACC,WAAW,EAAElB,cAAc,EAAEmB,SAAS,EAAEC,IAAI,EAAEC,KAAK,EAAEjB,IAAI,EAAEkB,UAAU,EAAC,GAAGL;IAChF,MAAMN,SAAS,MAAML;IACrB,OAAOK,OAAOC,OAAO,CAAC;QACpBW,MAAM;Y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AASC,MAAM,CAAC,WAAWH;IAC3BO,WAAWL,UAAU,cAAcL;IACnC,0EAA0E;IAC1E,IAAII,YAAYO,QAAQD,WAAWL,UAAU,cAAcD;IAC3DC,SAASC,MAAM,CAAC,WAAWJ,SAAS;QAACU,aAAa;QAAoBC,UAAU;IAAY;AAC9F;AAEA,oEAAoE,GACpE,SAASH,WAAWL,QAAkB,EAAES,IAAY,EAAEC,KAAc;IAClEV,SAASC,MAAM,CAACQ,MAAME,KAAKC,SAAS,CAACF,QAAQ;QAACH,aAAa;IAAkB;AAC/E;AAEA,eAAe/B,QAAWC,GAAW,EAAEuB,QAAkB;IACvD,MAAMzB,SAAS,MAAML;IACrB,OAAOK,OAAOC,OAAO,CAAC;QACpBW,MAAMa,SAASa,IAAI,CAAC,IAAIvD;QACxBwD,SAASd,SAASe,UAAU;QAC5BxB,QAAQ;QACRd;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.7.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",