@sanity/workbench-cli 2.17.0 → 2.19.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 (47) hide show
  1. package/dist/_exports/_internal_worker_bus.d.ts +2 -2
  2. package/dist/_exports/deploy.d.ts +38 -6
  3. package/dist/_exports/deploy.js +2 -0
  4. package/dist/_exports/deploy.js.map +1 -1
  5. package/dist/_exports/dev.d.ts +4 -1
  6. package/dist/_exports/index.d.ts +67 -2
  7. package/dist/_exports/preview.d.ts +2 -0
  8. package/dist/_exports/{summarizeInterfaces-CpCUSMrz.d.ts → summarizeInterfaces-DGh6ARce.d.ts} +2 -2
  9. package/dist/_exports/undeploy.d.ts +1 -1
  10. package/dist/actions/build/webWorkers/workerBus.js.map +1 -1
  11. package/dist/actions/deploy/deploySummary.js +36 -0
  12. package/dist/actions/deploy/deploySummary.js.map +1 -0
  13. package/dist/actions/deploy/deployWorkbenchApp.js +21 -7
  14. package/dist/actions/deploy/deployWorkbenchApp.js.map +1 -1
  15. package/dist/actions/dev/appServerSupervisor.js +3 -1
  16. package/dist/actions/dev/appServerSupervisor.js.map +1 -1
  17. package/dist/actions/dev/bindDevShortcuts.js +33 -0
  18. package/dist/actions/dev/bindDevShortcuts.js.map +1 -0
  19. package/dist/actions/dev/deriveConfigs.js +1 -1
  20. package/dist/actions/dev/deriveConfigs.js.map +1 -1
  21. package/dist/actions/dev/devSummary.js +49 -0
  22. package/dist/actions/dev/devSummary.js.map +1 -0
  23. package/dist/actions/dev/startDevServerRegistration.js +16 -1
  24. package/dist/actions/dev/startDevServerRegistration.js.map +1 -1
  25. package/dist/actions/dev/startWorkbenchDev.js +46 -11
  26. package/dist/actions/dev/startWorkbenchDev.js.map +1 -1
  27. package/dist/actions/preview/serveBuiltApplication.js +12 -1
  28. package/dist/actions/preview/serveBuiltApplication.js.map +1 -1
  29. package/dist/actions/preview/startWorkbenchPreview.js +11 -0
  30. package/dist/actions/preview/startWorkbenchPreview.js.map +1 -1
  31. package/dist/actions/summary.js +19 -0
  32. package/dist/actions/summary.js.map +1 -0
  33. package/dist/appId.js +1 -1
  34. package/dist/appId.js.map +1 -1
  35. package/dist/defineApp.js +4 -3
  36. package/dist/defineApp.js.map +1 -1
  37. package/dist/readAppIcon.js +31 -0
  38. package/dist/readAppIcon.js.map +1 -0
  39. package/dist/services/applications.js +40 -0
  40. package/dist/services/applications.js.map +1 -1
  41. package/dist/services/organizations.js +14 -0
  42. package/dist/services/organizations.js.map +1 -0
  43. package/dist/services/users.js +24 -0
  44. package/dist/services/users.js.map +1 -0
  45. package/dist/webWorker.js.map +1 -1
  46. package/package.json +13 -13
  47. package/dist/_exports/webWorker-TWUbh0uo.d.ts +0 -123
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defineApp.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\nimport {APP_SLUG_PATTERN} from './appSlug.js'\nimport {DockSchema, InterfaceDeclarationSchema, WebWorkerDeclarationSchema} from './contract.js'\n\n/**\n * Dashboard visibility values. Mirrors `APP_VISIBILITIES` in `@sanity/cli-core`\n * (which can't be imported here — pulling the barrel into this lean module bloats\n * the config-load path). Kept in sync by a type test in `defineApp.test.ts`.\n */\nconst APP_VISIBILITIES = ['default', 'unlisted', 'disabled'] as const\n\n/**\n * Internal application discriminator. Sanity-owned singleton apps only;\n * validated by the schema but excluded from the public `DefineAppInput` type.\n */\nconst ApplicationType = z.enum(['coreApp', 'studio', 'canvas', 'dashboard'])\n\n/**\n * Runtime-validation schema for `defineApplication`.\n * @internal\n */\nexport const DefineAppInputSchema = z\n .object({\n /**\n * Internal — Sanity-owned singleton apps only. Validated here but excluded\n * from the public `DefineAppInput` type.\n * @internal\n */\n applicationType: z.optional(ApplicationType),\n /** Default placement inherited by window views. */\n dock: z.optional(DockSchema),\n /**\n * App entrypoint module. Defaults to `./src/App.tsx` when omitted. The build\n * derives the app's navigable `app` view from it. SDK apps only — setting it\n * on a studio is rejected (studio app views are not yet implemented).\n */\n entry: z.optional(z.string(\"must be a path to the app's entry file\")),\n /**\n * Path to an `.svg` file, relative to the project root. Other file types are\n * rejected. Wins over manifest/studio icon.\n */\n icon: z.optional(\n z.string().check(z.regex(/\\.svg$/i, 'App `icon` must be a path to an .svg file')),\n ),\n /** Sanity-owned app deployed once and installed per org. @internal */\n isSingleton: z.optional(z.boolean()),\n /**\n * Stable identity, distinct from the `slug` address. Defaults to `slug` when\n * omitted. Identity keys — the build id and derived interface ids — are built\n * from this, so renaming the slug no longer changes identity.\n */\n name: z.optional(\n z\n .string()\n .check(\n z.regex(\n APP_SLUG_PATTERN,\n 'App `name` must be lowercase alphanumerics and hyphens, starting with a letter and ending with an alphanumeric',\n ),\n ),\n ),\n /** Organization that owns the app — it runs in and deploys to this organization's Dashboard. */\n organizationId: z.string(\n \"App `organizationId` is required — pass the owning organization's ID to `defineApplication`\",\n ),\n slug: z\n .string('App `slug` is required — the hostname the application is created at on deploy')\n .check(\n z.regex(\n APP_SLUG_PATTERN,\n 'App `slug` must be lowercase alphanumerics and hyphens, starting with a letter and ending with an alphanumeric',\n ),\n ),\n /** User-facing app title. Wins over studio.config.ts title on merge. */\n title: z.string(),\n /** Views the app exposes (e.g. a window, dock panels, and tiles). */\n views: z.optional(z.array(InterfaceDeclarationSchema, 'must be an array of views')),\n /** Dashboard visibility of the app. Defaults to `default` when omitted. */\n visibility: z.optional(z.enum(APP_VISIBILITIES)),\n /** Background web workers the app runs. */\n webWorkers: z.optional(z.array(WebWorkerDeclarationSchema, 'must be an array of web workers')),\n })\n .check(\n z.refine((input) => {\n const names = [\n ...(input.entry === undefined ? [] : [input.name ?? input.slug]),\n ...(input.views ?? []).map((view) => view.name),\n ...(input.webWorkers ?? []).map((webWorker) => webWorker.name),\n ]\n return new Set(names).size === names.length\n }, '`name` must be unique across views and web workers. Rename one of the duplicates.'),\n // Studio app views are not implemented yet. A studio that declares `entry`\n // (the SDK app-view entrypoint) is rejected here rather than silently\n // generating one; studios keep navigating via their existing render path.\n z.refine((input) => !(input.applicationType === 'studio' && input.entry !== undefined), {\n error: 'App views for studios are not implemented yet',\n path: ['entry'],\n }),\n )\n\n/**\n * User-facing input for `defineApplication`. Excludes the internal\n * `applicationType` and `isSingleton`.\n * @public\n */\nexport type DefineAppInput = Omit<\n z.output<typeof DefineAppInputSchema>,\n 'applicationType' | 'isSingleton'\n>\n\n/**\n * Nominal brand the CLI discriminates on to enable the workbench build/deploy\n * codepath. Registered via `Symbol.for` so the marker survives module-realm\n * boundaries — `@sanity/cli-core` re-derives the same global symbol with\n * `Symbol.for` rather than importing it, so it stays internal to this module.\n */\nconst WORKBENCH_APP: unique symbol = Symbol.for('sanity.workbench.defineApp')\n\n/**\n * The branded result of `defineApplication`. Carries the same fields as the\n * input plus the internal brand — users only ever see `DefineAppInput`.\n * @public\n */\nexport type DefineAppResult = DefineAppInput & {readonly [WORKBENCH_APP]: true}\n\n/**\n * A branded app as the CLI reads it — the full schema shape, including the\n * internal fields `DefineAppInput` omits. Schema-derived so the narrowing\n * can't drift from what the schema validates.\n * @public\n */\nexport type WorkbenchApp = DefineAppResult & z.output<typeof DefineAppInputSchema>\n\n/**\n * Whether `app` is a branded `defineApplication(...)` result — the sole\n * workbench opt-in.\n * @public\n */\nexport function isWorkbenchApp(app: unknown): app is WorkbenchApp {\n return typeof app === 'object' && app !== null && WORKBENCH_APP in app\n}\n\n/**\n * Declare a Sanity Dashboard application. Identity at runtime — returns the same\n * object reference, tagged with the Dashboard brand. Field validation (the\n * `slug` pattern etc.) runs at build time in the CLI via `DefineAppInputSchema`;\n * this helper stays a thin, pure identity wrapper.\n * @public\n */\nexport function defineApplication(input: DefineAppInput): DefineAppResult {\n return Object.defineProperty(input, WORKBENCH_APP, {\n configurable: false,\n enumerable: false,\n value: true,\n writable: false,\n }) as DefineAppResult\n}\n\n/**\n * One custom field a media library exposes. `src` default-exports a `defineField(...)` schema type.\n * @public\n */\nexport interface MediaLibraryField {\n /** Unique within the media library. */\n name: string\n src: string\n title: string\n\n /** Readable outside the owning organization. */\n public?: boolean\n}\n\n/**\n * Sanity-owned singleton, so authors don't name or title the app — only `organizationId` is required.\n * @public\n */\nexport interface DefineMediaLibraryInput {\n /** Organization that owns the media library — the CLI runs and deploys against it. */\n organizationId: string\n\n fields?: MediaLibraryField[]\n}\n\n/**\n * Nominal brand the CLI discriminates a config on. A config is *not* an app: it\n * carries no `slug`/`title`/application identity, only a target `appType`, its\n * owning `organizationId`, and its `fields`. Registered via `Symbol.for` so the\n * marker survives module-realm boundaries — `@sanity/cli-core` re-derives the\n * same global symbol rather than importing it.\n */\nconst WORKBENCH_CONFIG: unique symbol = Symbol.for('sanity.workbench.defineConfig')\n\n/**\n * A branded workbench config as the CLI reads it: bound to its target app by\n * `appType`, not carrying its own app identity. The deploy/undeploy/build paths\n * discriminate it via {@link isWorkbenchConfig}.\n * @public\n */\nexport interface WorkbenchConfig {\n appType: 'media-library'\n fields: MediaLibraryField[]\n organizationId: string\n readonly [WORKBENCH_CONFIG]: true\n}\n\n/**\n * Whether `app` is a branded `unstable_defineMediaLibrary(...)` config — a\n * config-carrier rather than an app. Configs live in `cliConfig.app` alongside\n * apps but resolve through `resolveWorkbenchConfig`, not `resolveWorkbenchApp`.\n * @public\n */\nexport function isWorkbenchConfig(app: unknown): app is WorkbenchConfig {\n return typeof app === 'object' && app !== null && WORKBENCH_CONFIG in app\n}\n\n/**\n * Declare the Sanity Media Library config. The Media Library is a Sanity-owned\n * singleton, so this is not an app — it carries no slug or title, only the\n * target `appType`, its owning organization, and the `fields` it contributes to\n * the installation's config.\n * @public\n */\nexport function unstable_defineMediaLibrary(input: DefineMediaLibraryInput): WorkbenchConfig {\n return Object.defineProperty(\n {appType: 'media-library', fields: input.fields ?? [], organizationId: input.organizationId},\n WORKBENCH_CONFIG,\n {configurable: false, enumerable: false, value: true, writable: false},\n ) as WorkbenchConfig\n}\n"],"names":["z","APP_SLUG_PATTERN","DockSchema","InterfaceDeclarationSchema","WebWorkerDeclarationSchema","APP_VISIBILITIES","ApplicationType","enum","DefineAppInputSchema","object","applicationType","optional","dock","entry","string","icon","check","regex","isSingleton","boolean","name","organizationId","slug","title","views","array","visibility","webWorkers","refine","input","names","undefined","map","view","webWorker","Set","size","length","error","path","WORKBENCH_APP","Symbol","for","isWorkbenchApp","app","defineApplication","Object","defineProperty","configurable","enumerable","value","writable","WORKBENCH_CONFIG","isWorkbenchConfig","unstable_defineMediaLibrary","appType","fields"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B,SAAQC,gBAAgB,QAAO,eAAc;AAC7C,SAAQC,UAAU,EAAEC,0BAA0B,EAAEC,0BAA0B,QAAO,gBAAe;AAEhG;;;;CAIC,GACD,MAAMC,mBAAmB;IAAC;IAAW;IAAY;CAAW;AAE5D;;;CAGC,GACD,MAAMC,kBAAkBN,EAAEO,IAAI,CAAC;IAAC;IAAW;IAAU;IAAU;CAAY;AAE3E;;;CAGC,GACD,OAAO,MAAMC,uBAAuBR,EACjCS,MAAM,CAAC;IACN;;;;KAIC,GACDC,iBAAiBV,EAAEW,QAAQ,CAACL;IAC5B,iDAAiD,GACjDM,MAAMZ,EAAEW,QAAQ,CAACT;IACjB;;;;KAIC,GACDW,OAAOb,EAAEW,QAAQ,CAACX,EAAEc,MAAM,CAAC;IAC3B;;;KAGC,GACDC,MAAMf,EAAEW,QAAQ,CACdX,EAAEc,MAAM,GAAGE,KAAK,CAAChB,EAAEiB,KAAK,CAAC,WAAW;IAEtC,oEAAoE,GACpEC,aAAalB,EAAEW,QAAQ,CAACX,EAAEmB,OAAO;IACjC;;;;KAIC,GACDC,MAAMpB,EAAEW,QAAQ,CACdX,EACGc,MAAM,GACNE,KAAK,CACJhB,EAAEiB,KAAK,CACLhB,kBACA;IAIR,8FAA8F,GAC9FoB,gBAAgBrB,EAAEc,MAAM,CACtB;IAEFQ,MAAMtB,EACHc,MAAM,CAAC,iFACPE,KAAK,CACJhB,EAAEiB,KAAK,CACLhB,kBACA;IAGN,sEAAsE,GACt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AU;IACZ;AACF;AA2BA;;;;;;CAMC,GACD,MAAMC,mBAAkCX,OAAOC,GAAG,CAAC;AAenD;;;;;CAKC,GACD,OAAO,SAASW,kBAAkBT,GAAY;IAC5C,OAAO,OAAOA,QAAQ,YAAYA,QAAQ,QAAQQ,oBAAoBR;AACxE;AAEA;;;;;;CAMC,GACD,OAAO,SAASU,4BAA4BzB,KAA8B;IACxE,OAAOiB,OAAOC,cAAc,CAC1B;QAACQ,SAAS;QAAiBC,QAAQ3B,MAAM2B,MAAM,IAAI,EAAE;QAAEnC,gBAAgBQ,MAAMR,cAAc;IAAA,GAC3F+B,kBACA;QAACJ,cAAc;QAAOC,YAAY;QAAOC,OAAO;QAAMC,UAAU;IAAK;AAEzE"}
1
+ {"version":3,"sources":["../src/defineApp.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\nimport {APP_SLUG_PATTERN} from './appSlug.js'\nimport {DockSchema, InterfaceDeclarationSchema, WebWorkerDeclarationSchema} from './contract.js'\n\n/**\n * Dashboard visibility values. Mirrors `APP_VISIBILITIES` in `@sanity/cli-core`\n * (which can't be imported here — pulling the barrel into this lean module bloats\n * the config-load path). Kept in sync by a type test in `defineApp.test.ts`.\n */\nconst APP_VISIBILITIES = ['default', 'unlisted', 'disabled'] as const\n\n/**\n * Internal application discriminator. Sanity-owned singleton apps only;\n * validated by the schema but excluded from the public `DefineAppInput` type.\n */\nconst ApplicationType = z.enum(['coreApp', 'studio', 'canvas', 'dashboard'])\n\n/**\n * Runtime-validation schema for `defineApplication`.\n * @internal\n */\nexport const DefineAppInputSchema = z\n .object({\n /**\n * Internal — Sanity-owned singleton apps only. Validated here but excluded\n * from the public `DefineAppInput` type.\n * @internal\n */\n applicationType: z.optional(ApplicationType),\n /** Default placement inherited by window views. */\n dock: z.optional(DockSchema),\n /**\n * App entrypoint module. Defaults to `./src/App.tsx` when omitted. The build\n * derives the app's navigable `app` view from it. SDK apps only — setting it\n * on a studio is rejected (studio app views are not yet implemented).\n */\n entry: z.optional(z.string(\"must be a path to the app's entry file\")),\n /**\n * Path to the app's icon, relative to the project root: a PNG, JPEG, GIF,\n * WebP, SVG, BMP, TIFF, HEIF or AVIF image of at most 5 MB. Wins over\n * manifest/studio icon.\n */\n icon: z.optional(z.string()),\n /** Sanity-owned app deployed once and installed per org. @internal */\n isSingleton: z.optional(z.boolean()),\n /**\n * Stable identity, distinct from the `slug` address. Defaults to `slug` when\n * omitted. Identity keys — the build id and derived interface ids — are built\n * from this, so renaming the slug no longer changes identity.\n */\n name: z.optional(\n z\n .string()\n .check(\n z.regex(\n APP_SLUG_PATTERN,\n 'App `name` must be lowercase alphanumerics and hyphens, starting with a letter and ending with an alphanumeric',\n ),\n ),\n ),\n /** Organization that owns the app — it runs in and deploys to this organization's Dashboard. */\n organizationId: z.string(\n \"App `organizationId` is required — pass the owning organization's ID to `defineApplication`\",\n ),\n slug: z\n .string('App `slug` is required — the hostname the application is created at on deploy')\n .check(\n z.regex(\n APP_SLUG_PATTERN,\n 'App `slug` must be lowercase alphanumerics and hyphens, starting with a letter and ending with an alphanumeric',\n ),\n ),\n /** User-facing app title. Wins over studio.config.ts title on merge. */\n title: z.string(),\n /** Views the app exposes (e.g. a window, dock panels, and tiles). */\n views: z.optional(z.array(InterfaceDeclarationSchema, 'must be an array of views')),\n /** Dashboard visibility of the app. Defaults to `default` when omitted. */\n visibility: z.optional(z.enum(APP_VISIBILITIES)),\n /** Background web workers the app runs. */\n webWorkers: z.optional(z.array(WebWorkerDeclarationSchema, 'must be an array of web workers')),\n })\n .check(\n z.refine((input) => {\n const names = [\n ...(input.entry === undefined ? [] : [input.name ?? input.slug]),\n ...(input.views ?? []).map((view) => view.name),\n ...(input.webWorkers ?? []).map((webWorker) => webWorker.name),\n ]\n return new Set(names).size === names.length\n }, '`name` must be unique across views and web workers. Rename one of the duplicates.'),\n // Studio app views are not implemented yet. A studio that declares `entry`\n // (the SDK app-view entrypoint) is rejected here rather than silently\n // generating one; studios keep navigating via their existing render path.\n z.refine((input) => !(input.applicationType === 'studio' && input.entry !== undefined), {\n error: 'App views for studios are not implemented yet',\n path: ['entry'],\n }),\n )\n\n/**\n * User-facing input for `defineApplication`. Excludes the internal\n * `applicationType` and `isSingleton`.\n * @public\n */\nexport type DefineAppInput = Omit<\n z.output<typeof DefineAppInputSchema>,\n 'applicationType' | 'isSingleton'\n>\n\n/**\n * Nominal brand the CLI discriminates on to enable the workbench build/deploy\n * codepath. Registered via `Symbol.for` so the marker survives module-realm\n * boundaries — `@sanity/cli-core` re-derives the same global symbol with\n * `Symbol.for` rather than importing it, so it stays internal to this module.\n */\nconst WORKBENCH_APP: unique symbol = Symbol.for('sanity.workbench.defineApp')\n\n/**\n * The branded result of `defineApplication`. Carries the same fields as the\n * input plus the internal brand — users only ever see `DefineAppInput`.\n * @public\n */\nexport type DefineAppResult = DefineAppInput & {readonly [WORKBENCH_APP]: true}\n\n/**\n * A branded app as the CLI reads it — the full schema shape, including the\n * internal fields `DefineAppInput` omits. Schema-derived so the narrowing\n * can't drift from what the schema validates.\n * @public\n */\nexport type WorkbenchApp = DefineAppResult & z.output<typeof DefineAppInputSchema>\n\n/**\n * Whether `app` is a branded `defineApplication(...)` result — the sole\n * workbench opt-in.\n * @public\n */\nexport function isWorkbenchApp(app: unknown): app is WorkbenchApp {\n return typeof app === 'object' && app !== null && WORKBENCH_APP in app\n}\n\n/**\n * Declare a Sanity Dashboard application. Identity at runtime — returns the same\n * object reference, tagged with the Dashboard brand. Field validation (the\n * `slug` pattern etc.) runs at build time in the CLI via `DefineAppInputSchema`;\n * this helper stays a thin, pure identity wrapper.\n * @public\n */\nexport function defineApplication(input: DefineAppInput): DefineAppResult {\n return Object.defineProperty(input, WORKBENCH_APP, {\n configurable: false,\n enumerable: false,\n value: true,\n writable: false,\n }) as DefineAppResult\n}\n\n/**\n * One custom field a media library exposes. `src` default-exports a `defineField(...)` schema type.\n * @public\n */\nexport interface MediaLibraryField {\n /** Unique within the media library. */\n name: string\n src: string\n title: string\n\n /** Readable outside the owning organization. */\n public?: boolean\n}\n\n/**\n * Sanity-owned singleton, so authors don't name or title the app — only `organizationId` is required.\n * @public\n */\nexport interface DefineMediaLibraryInput {\n /** Organization that owns the media library — the CLI runs and deploys against it. */\n organizationId: string\n\n fields?: MediaLibraryField[]\n}\n\n/**\n * Nominal brand the CLI discriminates a config on. A config is *not* an app: it\n * carries no `slug`/`title`/application identity, only a target `appType`, its\n * owning `organizationId`, and its `fields`. Registered via `Symbol.for` so the\n * marker survives module-realm boundaries — `@sanity/cli-core` re-derives the\n * same global symbol rather than importing it.\n */\nconst WORKBENCH_CONFIG: unique symbol = Symbol.for('sanity.workbench.defineConfig')\n\n/**\n * A branded workbench config as the CLI reads it: bound to its target app by\n * `appType`, not carrying its own app identity. The deploy/undeploy/build paths\n * discriminate it via {@link isWorkbenchConfig}.\n * @public\n */\nexport interface WorkbenchConfig {\n appType: 'media-library'\n fields: MediaLibraryField[]\n organizationId: string\n readonly [WORKBENCH_CONFIG]: true\n}\n\n/**\n * Whether `app` is a branded `unstable_defineMediaLibrary(...)` config — a\n * config-carrier rather than an app. Configs live in `cliConfig.app` alongside\n * apps but resolve through `resolveWorkbenchConfig`, not `resolveWorkbenchApp`.\n * @public\n */\nexport function isWorkbenchConfig(app: unknown): app is WorkbenchConfig {\n return typeof app === 'object' && app !== null && WORKBENCH_CONFIG in app\n}\n\n/**\n * Declare the Sanity Media Library config. The Media Library is a Sanity-owned\n * singleton, so this is not an app — it carries no slug or title, only the\n * target `appType`, its owning organization, and the `fields` it contributes to\n * the installation's config.\n * @public\n */\nexport function unstable_defineMediaLibrary(input: DefineMediaLibraryInput): WorkbenchConfig {\n return Object.defineProperty(\n {appType: 'media-library', fields: input.fields ?? [], organizationId: input.organizationId},\n WORKBENCH_CONFIG,\n {configurable: false, enumerable: false, value: true, writable: false},\n ) as WorkbenchConfig\n}\n"],"names":["z","APP_SLUG_PATTERN","DockSchema","InterfaceDeclarationSchema","WebWorkerDeclarationSchema","APP_VISIBILITIES","ApplicationType","enum","DefineAppInputSchema","object","applicationType","optional","dock","entry","string","icon","isSingleton","boolean","name","check","regex","organizationId","slug","title","views","array","visibility","webWorkers","refine","input","names","undefined","map","view","webWorker","Set","size","length","error","path","WORKBENCH_APP","Symbol","for","isWorkbenchApp","app","defineApplication","Object","defineProperty","configurable","enumerable","value","writable","WORKBENCH_CONFIG","isWorkbenchConfig","unstable_defineMediaLibrary","appType","fields"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B,SAAQC,gBAAgB,QAAO,eAAc;AAC7C,SAAQC,UAAU,EAAEC,0BAA0B,EAAEC,0BAA0B,QAAO,gBAAe;AAEhG;;;;CAIC,GACD,MAAMC,mBAAmB;IAAC;IAAW;IAAY;CAAW;AAE5D;;;CAGC,GACD,MAAMC,kBAAkBN,EAAEO,IAAI,CAAC;IAAC;IAAW;IAAU;IAAU;CAAY;AAE3E;;;CAGC,GACD,OAAO,MAAMC,uBAAuBR,EACjCS,MAAM,CAAC;IACN;;;;KAIC,GACDC,iBAAiBV,EAAEW,QAAQ,CAACL;IAC5B,iDAAiD,GACjDM,MAAMZ,EAAEW,QAAQ,CAACT;IACjB;;;;KAIC,GACDW,OAAOb,EAAEW,QAAQ,CAACX,EAAEc,MAAM,CAAC;IAC3B;;;;KAIC,GACDC,MAAMf,EAAEW,QAAQ,CAACX,EAAEc,MAAM;IACzB,oEAAoE,GACpEE,aAAahB,EAAEW,QAAQ,CAACX,EAAEiB,OAAO;IACjC;;;;KAIC,GACDC,MAAMlB,EAAEW,QAAQ,CACdX,EACGc,MAAM,GACNK,KAAK,CACJnB,EAAEoB,KAAK,CACLnB,kBACA;IAIR,8FAA8F,GAC9FoB,gBAAgBrB,EAAEc,MAAM,CACtB;IAEFQ,MAAMtB,EACHc,MAAM,CAAC,iFACPK,KAAK,CACJnB,EAAEoB,KAAK,CACLnB,kBACA;IAGN,sEAAsE,GACtEsB,OAAOvB,EAAEc,MAAM;IACf,mEAAmE,GACnEU,OAAOxB,EA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OAAOC,GAAG,CAAC;AAenD;;;;;CAKC,GACD,OAAO,SAASW,kBAAkBT,GAAY;IAC5C,OAAO,OAAOA,QAAQ,YAAYA,QAAQ,QAAQQ,oBAAoBR;AACxE;AAEA;;;;;;CAMC,GACD,OAAO,SAASU,4BAA4BzB,KAA8B;IACxE,OAAOiB,OAAOC,cAAc,CAC1B;QAACQ,SAAS;QAAiBC,QAAQ3B,MAAM2B,MAAM,IAAI,EAAE;QAAEnC,gBAAgBQ,MAAMR,cAAc;IAAA,GAC3F+B,kBACA;QAACJ,cAAc;QAAOC,YAAY;QAAOC,OAAO;QAAMC,UAAU;IAAK;AAEzE"}
@@ -0,0 +1,31 @@
1
+ import { relative, resolve, sep } from 'node:path';
2
+ import { getErrorMessage } from '@sanity/cli-core/errors';
3
+ import { readImageFile } from '@sanity/cli-core/images';
4
+ /**
5
+ * Read the image `app.icon` points at. The path is relative to the project
6
+ * root and must stay inside it.
7
+ * @internal
8
+ */ export async function readAppIcon(workDir, iconPath) {
9
+ const file = resolve(workDir, iconPath);
10
+ if (relative(workDir, file).startsWith('..')) {
11
+ throw new Error(`App icon "${iconPath}" is outside the project directory. Move the image into the project and update \`app.icon\` in sanity.cli.ts.`);
12
+ }
13
+ try {
14
+ return {
15
+ ...await readImageFile(file),
16
+ file
17
+ };
18
+ } catch (err) {
19
+ throw new Error(`Can't use app icon "${iconPath}": ${getErrorMessage(err)}`, {
20
+ cause: err
21
+ });
22
+ }
23
+ }
24
+ /**
25
+ * The URL path a server rooted at `dir` serves `file` at, without a leading slash.
26
+ * @internal
27
+ */ export function toUrlPath(dir, file) {
28
+ return relative(dir, file).split(sep).map((segment)=>encodeURIComponent(segment)).join('/');
29
+ }
30
+
31
+ //# sourceMappingURL=readAppIcon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/readAppIcon.ts"],"sourcesContent":["import {relative, resolve, sep} from 'node:path'\n\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {type ImageFile, readImageFile} from '@sanity/cli-core/images'\n\n/**\n * An app's `icon` image, read from its project.\n * @internal\n */\nexport interface AppIcon extends ImageFile {\n /** Absolute path to the file. */\n file: string\n}\n\n/**\n * Read the image `app.icon` points at. The path is relative to the project\n * root and must stay inside it.\n * @internal\n */\nexport async function readAppIcon(workDir: string, iconPath: string): Promise<AppIcon> {\n const file = resolve(workDir, iconPath)\n if (relative(workDir, file).startsWith('..')) {\n throw new Error(\n `App icon \"${iconPath}\" is outside the project directory. Move the image into the project and update \\`app.icon\\` in sanity.cli.ts.`,\n )\n }\n\n try {\n return {...(await readImageFile(file)), file}\n } catch (err) {\n throw new Error(`Can't use app icon \"${iconPath}\": ${getErrorMessage(err)}`, {cause: err})\n }\n}\n\n/**\n * The URL path a server rooted at `dir` serves `file` at, without a leading slash.\n * @internal\n */\nexport function toUrlPath(dir: string, file: string): string {\n return relative(dir, file)\n .split(sep)\n .map((segment) => encodeURIComponent(segment))\n .join('/')\n}\n"],"names":["relative","resolve","sep","getErrorMessage","readImageFile","readAppIcon","workDir","iconPath","file","startsWith","Error","err","cause","toUrlPath","dir","split","map","segment","encodeURIComponent","join"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,EAAEC,GAAG,QAAO,YAAW;AAEhD,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAwBC,aAAa,QAAO,0BAAyB;AAWrE;;;;CAIC,GACD,OAAO,eAAeC,YAAYC,OAAe,EAAEC,QAAgB;IACjE,MAAMC,OAAOP,QAAQK,SAASC;IAC9B,IAAIP,SAASM,SAASE,MAAMC,UAAU,CAAC,OAAO;QAC5C,MAAM,IAAIC,MACR,CAAC,UAAU,EAAEH,SAAS,6GAA6G,CAAC;IAExI;IAEA,IAAI;QACF,OAAO;YAAC,GAAI,MAAMH,cAAcI,KAAK;YAAGA;QAAI;IAC9C,EAAE,OAAOG,KAAK;QACZ,MAAM,IAAID,MAAM,CAAC,oBAAoB,EAAEH,SAAS,GAAG,EAAEJ,gBAAgBQ,MAAM,EAAE;YAACC,OAAOD;QAAG;IAC1F;AACF;AAEA;;;CAGC,GACD,OAAO,SAASE,UAAUC,GAAW,EAAEN,IAAY;IACjD,OAAOR,SAASc,KAAKN,MAClBO,KAAK,CAACb,KACNc,GAAG,CAAC,CAACC,UAAYC,mBAAmBD,UACpCE,IAAI,CAAC;AACV"}
@@ -27,6 +27,28 @@ export async function getApplication(applicationId) {
27
27
  throw err;
28
28
  }
29
29
  }
30
+ export async function getOrganizationApplication(organizationId, idOrSlug, signal) {
31
+ const client = await getGlobalCliClient({
32
+ apiVersion: APP_WORKBENCH_API_VERSION,
33
+ ignoreWarnings: [
34
+ 'This is an experimental API version',
35
+ 'which will change without warning'
36
+ ],
37
+ requireUser: true
38
+ });
39
+ try {
40
+ return await client.request({
41
+ query: {
42
+ include: 'activeDeployment'
43
+ },
44
+ signal,
45
+ url: `/organizations/${organizationId}/applications/${idOrSlug}`
46
+ });
47
+ } catch (err) {
48
+ if (err?.statusCode === 404) return null;
49
+ throw err;
50
+ }
51
+ }
30
52
  /** Every application in an organization, in one page (`limit=none`). */ export async function listApplications(organizationId) {
31
53
  const client = await getClient();
32
54
  const { data } = await client.request({
@@ -87,6 +109,24 @@ export async function updateApplication(applicationId, update) {
87
109
  url: `/applications/${applicationId}`
88
110
  });
89
111
  }
112
+ /** Upload the application's icon, replacing any it has. */ export async function setApplicationIcon(applicationId, icon) {
113
+ const client = await getClient();
114
+ await client.request({
115
+ body: icon.image,
116
+ headers: {
117
+ 'Content-Type': icon.contentType
118
+ },
119
+ method: 'PUT',
120
+ url: `/applications/${applicationId}/icon`
121
+ });
122
+ }
123
+ /** Remove the application's icon; removing one that isn't set changes nothing. */ export async function removeApplicationIcon(applicationId) {
124
+ const client = await getClient();
125
+ await client.request({
126
+ method: 'DELETE',
127
+ url: `/applications/${applicationId}/icon`
128
+ });
129
+ }
90
130
  /**
91
131
  * Deploy a new active version to an existing application. `mfManifest` is the
92
132
  * build's federation manifest; `tarball` is omitted for an external application,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/services/applications.ts"],"sourcesContent":["import {PassThrough} from 'node:stream'\nimport {type Gzip} from 'node:zlib'\n\nimport {type AppVisibility, getGlobalCliClient} from '@sanity/cli-core'\nimport {isStaging} from '@sanity/cli-core/util'\nimport FormData from 'form-data'\n\nimport {type TileInterfaceMetadata, type ViewPlacementMetadata} from '../contract.js'\nimport {APP_WORKBENCH_API_VERSION} from './apiVersion.js'\n\nexport type ApplicationType = 'coreApp' | 'studio'\n\nexport interface Application {\n id: string\n organizationId: string\n slug: string | null\n title: string\n type: ApplicationType\n\n /** Set when the customer serves the build; such an application never receives a tarball. */\n externalUrl?: string\n}\n\ninterface BrettInterfaceBase {\n moduleId: string\n name: string\n title: string\n version: string\n}\n\n/**\n * An interface as Brett stores it, discriminated on `type`. `moduleId` is\n * remote-relative — the host prepends the app's id. Brett assigns the id.\n * @internal\n */\nexport type BrettInterface =\n | (BrettInterfaceBase & {metadata: null; type: 'asset_source'})\n | (BrettInterfaceBase & {metadata: null; type: 'worker'})\n | (BrettInterfaceBase & {metadata: TileInterfaceMetadata; type: 'tile'})\n | (BrettInterfaceBase & {metadata: ViewPlacementMetadata | null; type: 'app'})\n | (BrettInterfaceBase & {metadata: ViewPlacementMetadata | null; type: 'panel'})\n\n/**\n * A resource a deployment may interact with, as Brett stores it. Per-deployment\n * and forbidden for singletons (the server 400s).\n */\nexport interface BrettAccess {\n resourceId: string\n resourceType: 'canvas' | 'dashboard' | 'dataset' | 'media-library'\n}\n\n/** A studio workspace as Brett stores it. */\nexport interface BrettWorkspace {\n dataset: string\n projectId: string\n /** Lexicon schema descriptor id; Brett requires one per workspace. */\n schemaDescriptorId: string\n\n basePath?: string\n icon?: string\n name?: string\n subtitle?: string\n title?: string\n}\n\nexport function getWorkbenchUrl(organizationId: string): string {\n return `https://${organizationId}.${isStaging() ? 'run.sanity.work' : 'sanity.run'}`\n}\n\n/** Where a deployed application is served on its organization's workbench. */\nexport function getApplicationUrl(\n application: Pick<Application, 'id' | 'organizationId' | 'slug' | 'type'>,\n): string {\n const segment = application.type === 'studio' ? 'studios' : 'applications'\n return `${getWorkbenchUrl(application.organizationId)}/${segment}/${application.slug ?? application.id}`\n}\n\nasync function getClient() {\n return getGlobalCliClient({apiVersion: APP_WORKBENCH_API_VERSION, requireUser: true})\n}\n\nexport async function getApplication(applicationId: string): Promise<Application | null> {\n const client = await getClient()\n try {\n return await client.request({url: `/applications/${applicationId}`})\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode === 404) return null\n throw err\n }\n}\n\n/** Every application in an organization, in one page (`limit=none`). */\nexport async function listApplications(organizationId: string): Promise<Application[]> {\n const client = await getClient()\n const {data}: {data: Application[]} = await client.request({\n query: {limit: 'none', organizationId},\n url: '/applications',\n })\n return data\n}\n\n/**\n * Create an application record (no deployment), so the CLI can build with the\n * returned id, then ship it via {@link createDeployment}.\n */\nexport async function createApplication(options: {\n /** The origin a customer serves the build from; Brett then never hosts a bundle for it. */\n externalUrl?: string\n isSingleton?: boolean\n name?: string\n organizationId: string\n projectId?: string\n slug: string\n title: string\n type: ApplicationType\n visibility?: AppVisibility\n}): Promise<Application> {\n const {externalUrl, isSingleton, name, organizationId, projectId, slug, title, type, visibility} =\n options\n const client = await getClient()\n return client.request({\n body: {\n organizationId,\n slug,\n title,\n type,\n // Identity, distinct from the slug address. Omitted → Brett defaults it to slug.\n ...(name ? {name} : {}),\n // Brett requires `isSingleton` on `POST /applications`, so the request\n // builder keeps forwarding it even though the CLI itself never sets it.\n ...(isSingleton === undefined ? {} : {isSingleton}),\n ...(visibility ? {visibility} : {}),\n ...(externalUrl ? {externalUrl} : {}),\n // Studio config is set once, at create — it's immutable on redeploy.\n ...(projectId ? {config: {studio: {projectId}}} : {}),\n },\n method: 'POST',\n url: `/applications`,\n })\n}\n\n/** Mutable application fields the deploy flow patches after create. */\nexport interface ApplicationUpdate {\n icon?: string | null\n /** The address the application is served at; renaming moves it. */\n slug?: string\n title?: string\n visibility?: AppVisibility\n}\n\n// Patch an application's mutable fields.\nexport async function updateApplication(\n applicationId: string,\n update: ApplicationUpdate,\n): Promise<void> {\n const client = await getClient()\n await client.request({body: update, method: 'PATCH', url: `/applications/${applicationId}`})\n}\n\n/**\n * Deploy a new active version to an existing application. `mfManifest` is the\n * build's federation manifest; `tarball` is omitted for an external application,\n * whose build the customer serves themselves.\n */\nexport async function createDeployment(options: {\n access?: readonly BrettAccess[]\n applicationId: string\n interfaces: readonly BrettInterface[]\n isAutoUpdating: boolean\n mfManifest: Record<string, unknown>\n tarball?: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n}): Promise<{id: string}> {\n const {\n access,\n applicationId,\n interfaces,\n isAutoUpdating,\n mfManifest,\n tarball,\n version,\n workspaces,\n } = options\n const formData = new FormData()\n formData.append('isAutoUpdating', isAutoUpdating.toString())\n appendDeploymentParts(formData, {access, interfaces, mfManifest, tarball, version, workspaces})\n return request(`/applications/${applicationId}/deployments`, formData)\n}\n\n/** Soft-deletes the application and all its deployments; already deleted counts as done. */\nexport async function deleteApplication(applicationId: string): Promise<void> {\n const client = await getClient()\n try {\n await client.request({method: 'DELETE', url: `/applications/${applicationId}`})\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode !== 404) throw err\n }\n}\n\nfunction appendDeploymentParts(\n formData: FormData,\n {\n access,\n interfaces,\n mfManifest,\n tarball,\n version,\n workspaces,\n }: {\n access?: readonly BrettAccess[]\n interfaces: readonly BrettInterface[]\n mfManifest: Record<string, unknown>\n tarball?: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n },\n): void {\n formData.append('version', version)\n appendJson(formData, 'interfaces', interfaces)\n // Studio-only — the server rejects a workspaces part on non-studio types.\n if (workspaces?.length) appendJson(formData, 'workspaces', workspaces)\n // Per-deployment; forbidden for singletons, so callers omit it there.\n if (access?.length) appendJson(formData, 'access', access)\n appendJson(formData, 'mfManifest', mfManifest)\n // Last: the server requires every field part to precede the tarball.\n if (tarball) {\n formData.append('tarball', tarball, {contentType: 'application/gzip', filename: 'app.tar.gz'})\n }\n}\n\n/** Structured parts must arrive as JSON so the server parses them. */\nfunction appendJson(formData: FormData, name: string, value: unknown): void {\n formData.append(name, JSON.stringify(value), {contentType: 'application/json'})\n}\n\nasync function request<T>(url: string, formData: FormData): Promise<T> {\n const client = await getClient()\n return client.request({\n body: formData.pipe(new PassThrough()),\n headers: formData.getHeaders(),\n method: 'POST',\n url,\n })\n}\n"],"names":["PassThrough","getGlobalCliClient","isStaging","FormData","APP_WORKBENCH_API_VERSION","getWorkbenchUrl","organizationId","getApplicationUrl","application","segment","type","slug","id","getClient","apiVersion","requireUser","getApplication","applicationId","client","request","url","err","statusCode","listApplications","data","query","limit","createApplication","options","externalUrl","isSingleton","name","projectId","title","visibility","body","undefined","config","studio","method","updateApplication","update","createDeployment","access","interfaces","isAutoUpdating","mfManifest","tarball","version","workspaces","formData","append","toString","appendDeploymentParts","deleteApplication","appendJson","length","contentType","filename","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;AAyDzD,OAAO,SAASC,gBAAgBC,cAAsB;IACpD,OAAO,CAAC,QAAQ,EAAEA,eAAe,CAAC,EAAEJ,cAAc,oBAAoB,cAAc;AACtF;AAEA,4EAA4E,GAC5E,OAAO,SAASK,kBACdC,WAAyE;IAEzE,MAAMC,UAAUD,YAAYE,IAAI,KAAK,WAAW,YAAY;IAC5D,OAAO,GAAGL,gBAAgBG,YAAYF,cAAc,EAAE,CAAC,EAAEG,QAAQ,CAAC,EAAED,YAAYG,IAAI,IAAIH,YAAYI,EAAE,EAAE;AAC1G;AAEA,eAAeC;IACb,OAAOZ,mBAAmB;QAACa,YAAYV;QAA2BW,aAAa;IAAI;AACrF;AAEA,OAAO,eAA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U;QAAY;IAC9F;AACF;AAEA,oEAAoE,GACpE,SAASH,WAAWL,QAAkB,EAAEnB,IAAY,EAAE4B,KAAc;IAClET,SAASC,MAAM,CAACpB,MAAM6B,KAAKC,SAAS,CAACF,QAAQ;QAACF,aAAa;IAAkB;AAC/E;AAEA,eAAetC,QAAWC,GAAW,EAAE8B,QAAkB;IACvD,MAAMhC,SAAS,MAAML;IACrB,OAAOK,OAAOC,OAAO,CAAC;QACpBgB,MAAMe,SAASY,IAAI,CAAC,IAAI9D;QACxB+D,SAASb,SAASc,UAAU;QAC5BzB,QAAQ;QACRnB;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/services/applications.ts"],"sourcesContent":["import {PassThrough} from 'node:stream'\nimport {type Gzip} from 'node:zlib'\n\nimport {type AppVisibility, getGlobalCliClient} from '@sanity/cli-core'\nimport {type ImageFile} from '@sanity/cli-core/images'\nimport {isStaging} from '@sanity/cli-core/util'\nimport FormData from 'form-data'\n\nimport {type TileInterfaceMetadata, type ViewPlacementMetadata} from '../contract.js'\nimport {APP_WORKBENCH_API_VERSION} from './apiVersion.js'\n\nexport type ApplicationType = 'coreApp' | 'studio'\n\nexport interface Application {\n id: string\n organizationId: string\n slug: string | null\n title: string\n type: ApplicationType\n\n /** Set when the customer serves the build; such an application never receives a tarball. */\n externalUrl?: string\n}\n\ninterface BrettInterfaceBase {\n moduleId: string\n name: string\n title: string\n version: string\n}\n\n/**\n * An interface as Brett stores it, discriminated on `type`. `moduleId` is\n * remote-relative — the host prepends the app's id. Brett assigns the id.\n * @internal\n */\nexport type BrettInterface =\n | (BrettInterfaceBase & {metadata: null; type: 'asset_source'})\n | (BrettInterfaceBase & {metadata: null; type: 'worker'})\n | (BrettInterfaceBase & {metadata: TileInterfaceMetadata; type: 'tile'})\n | (BrettInterfaceBase & {metadata: ViewPlacementMetadata | null; type: 'app'})\n | (BrettInterfaceBase & {metadata: ViewPlacementMetadata | null; type: 'panel'})\n\n/**\n * A resource a deployment may interact with, as Brett stores it. Per-deployment\n * and forbidden for singletons (the server 400s).\n */\nexport interface BrettAccess {\n resourceId: string\n resourceType: 'canvas' | 'dashboard' | 'dataset' | 'media-library'\n}\n\n/** A studio workspace as Brett stores it. */\nexport interface BrettWorkspace {\n dataset: string\n projectId: string\n /** Lexicon schema descriptor id; Brett requires one per workspace. */\n schemaDescriptorId: string\n\n basePath?: string\n icon?: string\n name?: string\n subtitle?: string\n title?: string\n}\n\nexport function getWorkbenchUrl(organizationId: string): string {\n return `https://${organizationId}.${isStaging() ? 'run.sanity.work' : 'sanity.run'}`\n}\n\n/** Where a deployed application is served on its organization's workbench. */\nexport function getApplicationUrl(\n application: Pick<Application, 'id' | 'organizationId' | 'slug' | 'type'>,\n): string {\n const segment = application.type === 'studio' ? 'studios' : 'applications'\n return `${getWorkbenchUrl(application.organizationId)}/${segment}/${application.slug ?? application.id}`\n}\n\nasync function getClient() {\n return getGlobalCliClient({apiVersion: APP_WORKBENCH_API_VERSION, requireUser: true})\n}\n\nexport async function getApplication(applicationId: string): Promise<Application | null> {\n const client = await getClient()\n try {\n return await client.request({url: `/applications/${applicationId}`})\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode === 404) return null\n throw err\n }\n}\n\nexport async function getOrganizationApplication(\n organizationId: string,\n idOrSlug: string,\n signal?: AbortSignal,\n): Promise<\n (Application & {activeDeployment: {createdAt: string; deployedBy: string} | null}) | null\n> {\n const client = await getGlobalCliClient({\n apiVersion: APP_WORKBENCH_API_VERSION,\n ignoreWarnings: ['This is an experimental API version', 'which will change without warning'],\n requireUser: true,\n })\n try {\n return await client.request({\n query: {include: 'activeDeployment'},\n signal,\n url: `/organizations/${organizationId}/applications/${idOrSlug}`,\n })\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode === 404) return null\n throw err\n }\n}\n\n/** Every application in an organization, in one page (`limit=none`). */\nexport async function listApplications(organizationId: string): Promise<Application[]> {\n const client = await getClient()\n const {data}: {data: Application[]} = await client.request({\n query: {limit: 'none', organizationId},\n url: '/applications',\n })\n return data\n}\n\n/**\n * Create an application record (no deployment), so the CLI can build with the\n * returned id, then ship it via {@link createDeployment}.\n */\nexport async function createApplication(options: {\n /** The origin a customer serves the build from; Brett then never hosts a bundle for it. */\n externalUrl?: string\n isSingleton?: boolean\n name?: string\n organizationId: string\n projectId?: string\n slug: string\n title: string\n type: ApplicationType\n visibility?: AppVisibility\n}): Promise<Application> {\n const {externalUrl, isSingleton, name, organizationId, projectId, slug, title, type, visibility} =\n options\n const client = await getClient()\n return client.request({\n body: {\n organizationId,\n slug,\n title,\n type,\n // Identity, distinct from the slug address. Omitted → Brett defaults it to slug.\n ...(name ? {name} : {}),\n // Brett requires `isSingleton` on `POST /applications`, so the request\n // builder keeps forwarding it even though the CLI itself never sets it.\n ...(isSingleton === undefined ? {} : {isSingleton}),\n ...(visibility ? {visibility} : {}),\n ...(externalUrl ? {externalUrl} : {}),\n // Studio config is set once, at create — it's immutable on redeploy.\n ...(projectId ? {config: {studio: {projectId}}} : {}),\n },\n method: 'POST',\n url: `/applications`,\n })\n}\n\n/** Mutable application fields the deploy flow patches after create. */\nexport interface ApplicationUpdate {\n /** The address the application is served at; renaming moves it. */\n slug?: string\n title?: string\n visibility?: AppVisibility\n}\n\n// Patch an application's mutable fields.\nexport async function updateApplication(\n applicationId: string,\n update: ApplicationUpdate,\n): Promise<void> {\n const client = await getClient()\n await client.request({body: update, method: 'PATCH', url: `/applications/${applicationId}`})\n}\n\n/** Upload the application's icon, replacing any it has. */\nexport async function setApplicationIcon(applicationId: string, icon: ImageFile): Promise<void> {\n const client = await getClient()\n await client.request({\n body: icon.image,\n headers: {'Content-Type': icon.contentType},\n method: 'PUT',\n url: `/applications/${applicationId}/icon`,\n })\n}\n\n/** Remove the application's icon; removing one that isn't set changes nothing. */\nexport async function removeApplicationIcon(applicationId: string): Promise<void> {\n const client = await getClient()\n await client.request({method: 'DELETE', url: `/applications/${applicationId}/icon`})\n}\n\n/**\n * Deploy a new active version to an existing application. `mfManifest` is the\n * build's federation manifest; `tarball` is omitted for an external application,\n * whose build the customer serves themselves.\n */\nexport async function createDeployment(options: {\n access?: readonly BrettAccess[]\n applicationId: string\n interfaces: readonly BrettInterface[]\n isAutoUpdating: boolean\n mfManifest: Record<string, unknown>\n tarball?: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n}): Promise<{id: string}> {\n const {\n access,\n applicationId,\n interfaces,\n isAutoUpdating,\n mfManifest,\n tarball,\n version,\n workspaces,\n } = options\n const formData = new FormData()\n formData.append('isAutoUpdating', isAutoUpdating.toString())\n appendDeploymentParts(formData, {access, interfaces, mfManifest, tarball, version, workspaces})\n return request(`/applications/${applicationId}/deployments`, formData)\n}\n\n/** Soft-deletes the application and all its deployments; already deleted counts as done. */\nexport async function deleteApplication(applicationId: string): Promise<void> {\n const client = await getClient()\n try {\n await client.request({method: 'DELETE', url: `/applications/${applicationId}`})\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode !== 404) throw err\n }\n}\n\nfunction appendDeploymentParts(\n formData: FormData,\n {\n access,\n interfaces,\n mfManifest,\n tarball,\n version,\n workspaces,\n }: {\n access?: readonly BrettAccess[]\n interfaces: readonly BrettInterface[]\n mfManifest: Record<string, unknown>\n tarball?: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n },\n): void {\n formData.append('version', version)\n appendJson(formData, 'interfaces', interfaces)\n // Studio-only — the server rejects a workspaces part on non-studio types.\n if (workspaces?.length) appendJson(formData, 'workspaces', workspaces)\n // Per-deployment; forbidden for singletons, so callers omit it there.\n if (access?.length) appendJson(formData, 'access', access)\n appendJson(formData, 'mfManifest', mfManifest)\n // Last: the server requires every field part to precede the tarball.\n if (tarball) {\n formData.append('tarball', tarball, {contentType: 'application/gzip', filename: 'app.tar.gz'})\n }\n}\n\n/** Structured parts must arrive as JSON so the server parses them. */\nfunction appendJson(formData: FormData, name: string, value: unknown): void {\n formData.append(name, JSON.stringify(value), {contentType: 'application/json'})\n}\n\nasync function request<T>(url: string, formData: FormData): Promise<T> {\n const client = await getClient()\n return client.request({\n body: formData.pipe(new PassThrough()),\n headers: formData.getHeaders(),\n method: 'POST',\n url,\n })\n}\n"],"names":["PassThrough","getGlobalCliClient","isStaging","FormData","APP_WORKBENCH_API_VERSION","getWorkbenchUrl","organizationId","getApplicationUrl","application","segment","type","slug","id","getClient","apiVersion","requireUser","getApplication","applicationId","client","request","url","err","statusCode","getOrganizationApplication","idOrSlug","signal","ignoreWarnings","query","include","listApplications","data","limit","createApplication","options","externalUrl","isSingleton","name","projectId","title","visibility","body","undefined","config","studio","method","updateApplication","update","setApplicationIcon","icon","image","headers","contentType","removeApplicationIcon","createDeployment","access","interfaces","isAutoUpdating","mfManifest","tarball","version","workspaces","formData","append","toString","appendDeploymentParts","deleteApplication","appendJson","length","filename","value","JSON","stringify","pipe","getHeaders"],"mappings":"AAAA,SAAQA,WAAW,QAAO,cAAa;AAGvC,SAA4BC,kBAAkB,QAAO,mBAAkB;AAEvE,SAAQC,SAAS,QAAO,wBAAuB;AAC/C,OAAOC,cAAc,YAAW;AAGhC,SAAQC,yBAAyB,QAAO,kBAAiB;AAyDzD,OAAO,SAASC,gBAAgBC,cAAsB;IACpD,OAAO,CAAC,QAAQ,EAAEA,eAAe,CAAC,EAAEJ,cAAc,oBAAoB,cAAc;AACtF;AAEA,4EAA4E,GAC5E,OAAO,SAASK,kBACdC,WAAyE;IAEzE,MAAMC,UAAUD,YAAYE,IAAI,KAAK,WAAW,YAAY;IAC5D,OAAO,GAAGL,gBAAgBG,YAAYF,cAAc,EAAE,CAAC,EAAEG,QAAQ,CAAC,EAAED,YAAYG,IAAI,IAAIH,YAAYI,EAAE,EAAE;AAC1G;AAEA,eAAeC;IACb,OAAOZ,mBAAmB;QAACa,YAAYV;QAA2BW,aAAa;IAAI;AACrF;AAEA,OAAO,eAAeC,eAAeC,aAAqB;IACxD,MAAMC,SAAS,MAAML;IACrB,IAAI;QACF,OAAO,MAAMK,OAAOC,OAAO,CAAC;YAACC,KAAK,CAAC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';
2
+ const ORGANIZATIONS_API_VERSION = 'v2025-05-14';
3
+ export async function getOrganization(organizationId, signal) {
4
+ const client = await getGlobalCliClient({
5
+ apiVersion: ORGANIZATIONS_API_VERSION,
6
+ requireUser: true
7
+ });
8
+ return client.request({
9
+ signal,
10
+ url: `/organizations/${organizationId}`
11
+ });
12
+ }
13
+
14
+ //# sourceMappingURL=organizations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/services/organizations.ts"],"sourcesContent":["import {getGlobalCliClient} from '@sanity/cli-core'\n\nconst ORGANIZATIONS_API_VERSION = 'v2025-05-14'\n\nexport async function getOrganization(\n organizationId: string,\n signal?: AbortSignal,\n): Promise<{name: string}> {\n const client = await getGlobalCliClient({\n apiVersion: ORGANIZATIONS_API_VERSION,\n requireUser: true,\n })\n\n return client.request({signal, url: `/organizations/${organizationId}`})\n}\n"],"names":["getGlobalCliClient","ORGANIZATIONS_API_VERSION","getOrganization","organizationId","signal","client","apiVersion","requireUser","request","url"],"mappings":"AAAA,SAAQA,kBAAkB,QAAO,mBAAkB;AAEnD,MAAMC,4BAA4B;AAElC,OAAO,eAAeC,gBACpBC,cAAsB,EACtBC,MAAoB;IAEpB,MAAMC,SAAS,MAAML,mBAAmB;QACtCM,YAAYL;QACZM,aAAa;IACf;IAEA,OAAOF,OAAOG,OAAO,CAAC;QAACJ;QAAQK,KAAK,CAAC,eAAe,EAAEN,gBAAgB;IAAA;AACxE"}
@@ -0,0 +1,24 @@
1
+ import { getGlobalCliClient } from '@sanity/cli-core';
2
+ const USERS_API_VERSION = 'v2025-05-14';
3
+ export async function getUser(userId, signal) {
4
+ const client = await getGlobalCliClient({
5
+ apiVersion: USERS_API_VERSION,
6
+ requireUser: true
7
+ });
8
+ return client.request({
9
+ signal,
10
+ url: `/users/${userId}`
11
+ });
12
+ }
13
+ export async function getCurrentUser(signal) {
14
+ const client = await getGlobalCliClient({
15
+ apiVersion: USERS_API_VERSION,
16
+ requireUser: true
17
+ });
18
+ return client.request({
19
+ signal,
20
+ url: '/users/me'
21
+ });
22
+ }
23
+
24
+ //# sourceMappingURL=users.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/services/users.ts"],"sourcesContent":["import {getGlobalCliClient} from '@sanity/cli-core'\n\nconst USERS_API_VERSION = 'v2025-05-14'\n\nexport async function getUser(\n userId: string,\n signal?: AbortSignal,\n): Promise<{displayName: string}> {\n const client = await getGlobalCliClient({apiVersion: USERS_API_VERSION, requireUser: true})\n\n return client.request({signal, url: `/users/${userId}`})\n}\n\nexport async function getCurrentUser(signal?: AbortSignal): Promise<{name: string}> {\n const client = await getGlobalCliClient({apiVersion: USERS_API_VERSION, requireUser: true})\n\n return client.request({signal, url: '/users/me'})\n}\n"],"names":["getGlobalCliClient","USERS_API_VERSION","getUser","userId","signal","client","apiVersion","requireUser","request","url","getCurrentUser"],"mappings":"AAAA,SAAQA,kBAAkB,QAAO,mBAAkB;AAEnD,MAAMC,oBAAoB;AAE1B,OAAO,eAAeC,QACpBC,MAAc,EACdC,MAAoB;IAEpB,MAAMC,SAAS,MAAML,mBAAmB;QAACM,YAAYL;QAAmBM,aAAa;IAAI;IAEzF,OAAOF,OAAOG,OAAO,CAAC;QAACJ;QAAQK,KAAK,CAAC,OAAO,EAAEN,QAAQ;IAAA;AACxD;AAEA,OAAO,eAAeO,eAAeN,MAAoB;IACvD,MAAMC,SAAS,MAAML,mBAAmB;QAACM,YAAYL;QAAmBM,aAAa;IAAI;IAEzF,OAAOF,OAAOG,OAAO,CAAC;QAACJ;QAAQK,KAAK;IAAW;AACjD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/webWorker.ts"],"sourcesContent":["import {\n type EventTopic,\n type MessageBus,\n type MessageBusAbortOptions,\n type MessageBusMessage,\n type PayloadOf,\n type ReplyOf,\n type StateTopic,\n type ValueOf,\n} from '@sanity/sdk/dashboard'\n\nimport {WEB_WORKER_CONTRACT_VERSION, type WebWorkerType} from './contract.js'\n\n/**\n * The web worker's own declaration.\n * @public\n */\nexport interface WebWorkerInfo {\n readonly name: string\n readonly type: string\n}\n\n/**\n * The message bus as a web worker sees it: the SDK's `MessageBus` without the\n * `subscribe` forms that return observables, which would make the web worker's\n * project install rxjs. There is no `disconnect`: Dashboard owns the connection\n * and ends it when it stops the worker.\n * @public\n */\nexport interface WebWorkerBus extends Omit<MessageBus, 'subscribe'> {\n /** Runs a responder for each event until its signal aborts. */\n subscribe<K extends EventTopic>(\n type: K,\n handler: (message: MessageBusMessage<PayloadOf<K>, ReplyOf<K>, K>) => void,\n options?: MessageBusAbortOptions,\n ): void\n /** Runs a handler for each state value until its signal aborts. */\n subscribe<K extends StateTopic>(\n type: K,\n handler: (value: ValueOf<K>) => void,\n options?: MessageBusAbortOptions,\n ): void\n}\n\n/**\n * Context every service callback receives when its worker starts. Mirrors how a\n * view component receives its `view` — the service receives its own `service`.\n * @deprecated Use {@link WebWorkerProps}.\n * @public\n */\nexport interface ServiceContext {\n readonly bus: WebWorkerBus\n readonly service: WebWorkerInfo\n}\n\n/**\n * Props a web worker function receives when its worker starts. The default\n * export of a web worker's `src` file runs once inside the worker.\n *\n * `bus` is its connection to the Dashboard message bus:\n * `bus.emit` sends an event (such as a dock-badge update), `bus.query` reads the\n * current value of a state topic, and `bus.subscribe` runs a handler on each\n * new value of a state topic, or on each event of an event topic, until its\n * `signal` aborts. A refused, unanswered or timed-out `emit` or `query` rejects\n * with an `Error` named `MessageBusError` whose `code` says why; it is not an\n * instance of the SDK's `MessageBusError` class. When the Dashboard's refusal\n * says how to fix it, the error also carries `fix` and `docsUrl`. A refused\n * `subscribe` has no error: its handler never runs, and the Dashboard reports\n * the refusal in the browser console.\n *\n * An event handler answers the sender with `message.reply(value)` or refuses\n * with `message.reject(reason)`; one that throws refuses with code\n * `HANDLER_THREW`. For example, a worker that keeps a snapshot for its app's\n * views, which listen with `useWorker` first and then post to it. A view's post\n * arrives on `workers.post` as `{name, payload}`, and `workers.message` reaches\n * only this app's views:\n *\n * ```ts\n * export default ({bus}: WebWorkerProps) => {\n * const controller = new AbortController()\n * bus.subscribe('workers.post', (message) => message.reply(snapshot), {\n * signal: controller.signal,\n * })\n * // Views that are already listening post again.\n * bus.emit('workers.message', {type: 'welcome'})\n * return () => controller.abort()\n * }\n * ```\n *\n * The function can return a disposer, which runs when Dashboard stops the\n * worker. By then the bus is closed: subscriptions have ended, `emit` and\n * `query` reject with code `ABORTED`, and `subscribe` throws that error.\n * @public\n */\nexport interface WebWorkerProps {\n readonly bus: WebWorkerBus\n readonly worker: WebWorkerInfo\n}\n\n/**\n * A service callback. Runs once inside the worker on start; returns an optional\n * disposer the host calls before terminating the worker.\n * @deprecated Default-export a plain function that receives {@link WebWorkerProps} instead.\n * @public\n */\nexport type ServiceCallback = (context: ServiceContext) => (() => void) | void\n\n/** The callback shape each service type defines, keyed by type. */\ninterface ServiceCallbacksByType {\n worker: ServiceCallback\n}\n\n/**\n * The result of `unstable_defineService`: the author's callback, the service\n * type, and the internal contract version the worker artifact targets.\n * @deprecated Default-export a plain function that receives {@link WebWorkerProps} instead.\n * @public\n */\nexport interface DefinedService<TType extends WebWorkerType = WebWorkerType> {\n readonly run: ServiceCallbacksByType[TType]\n readonly type: TType\n /** @internal */\n readonly version: typeof WEB_WORKER_CONTRACT_VERSION\n}\n\n/**\n * Define a Sanity Dashboard background service. The first argument narrows the\n * callback shape — `\"worker\"` runs the callback inside a Web Worker with the\n * bus described on {@link WebWorkerProps}.\n *\n * Identity at runtime: returns the callback tagged with its type and the contract\n * version, for the CLI build to generate a worker artifact from. Used as the\n * default export of a service's `src` file.\n * @deprecated Default-export a plain function that receives {@link WebWorkerProps} from the web worker's `src` file instead.\n * @public\n */\nexport function unstable_defineService<TType extends WebWorkerType>(\n type: TType,\n run: ServiceCallbacksByType[TType],\n): DefinedService<TType> {\n return {run, type, version: WEB_WORKER_CONTRACT_VERSION}\n}\n\n/**\n * @deprecated Use `WebWorkerBus`.\n * @public\n */\nexport type ServiceBus = WebWorkerBus\n\n/**\n * @deprecated Use `WebWorkerInfo`.\n * @public\n */\nexport type ServiceInfo = WebWorkerInfo\n"],"names":["WEB_WORKER_CONTRACT_VERSION","unstable_defineService","type","run","version"],"mappings":"AAWA,SAAQA,2BAA2B,QAA2B,gBAAe;AAkH7E;;;;;;;;;;CAUC,GACD,OAAO,SAASC,uBACdC,IAAW,EACXC,GAAkC;IAElC,OAAO;QAACA;QAAKD;QAAME,SAASJ;IAA2B;AACzD"}
1
+ {"version":3,"sources":["../src/webWorker.ts"],"sourcesContent":["import {type WebWorkerProps} from '@sanity/sdk/dashboard'\n\nimport {WEB_WORKER_CONTRACT_VERSION, type WebWorkerType} from './contract.js'\n\nexport type {WebWorkerProps} from '@sanity/sdk/dashboard'\n\n/**\n * @deprecated Use `WebWorkerProps['worker']`.\n * @public\n */\nexport type WebWorkerInfo = WebWorkerProps['worker']\n\n/**\n * @deprecated Use `WebWorkerProps['bus']`.\n * @public\n */\nexport type WebWorkerBus = WebWorkerProps['bus']\n\n/**\n * Context every service callback receives when its worker starts. Mirrors how a\n * view component receives its `view` — the service receives its own `service`.\n * @deprecated Use {@link WebWorkerProps}.\n * @public\n */\nexport interface ServiceContext {\n readonly bus: WebWorkerProps['bus']\n readonly service: WebWorkerProps['worker']\n}\n\n/**\n * A service callback. Runs once inside the worker on start; returns an optional\n * disposer the host calls before terminating the worker.\n * @deprecated Default-export a plain function that receives {@link WebWorkerProps} instead.\n * @public\n */\nexport type ServiceCallback = (context: ServiceContext) => (() => void) | void\n\n/** The callback shape each service type defines, keyed by type. */\ninterface ServiceCallbacksByType {\n worker: ServiceCallback\n}\n\n/**\n * The result of `unstable_defineService`: the author's callback, the service\n * type, and the internal contract version the worker artifact targets.\n * @deprecated Default-export a plain function that receives {@link WebWorkerProps} instead.\n * @public\n */\nexport interface DefinedService<TType extends WebWorkerType = WebWorkerType> {\n readonly run: ServiceCallbacksByType[TType]\n readonly type: TType\n /** @internal */\n readonly version: typeof WEB_WORKER_CONTRACT_VERSION\n}\n\n/**\n * Define a Sanity Dashboard background service. The first argument narrows the\n * callback shape — `\"worker\"` runs the callback inside a Web Worker with the\n * bus described on {@link WebWorkerProps}.\n *\n * Identity at runtime: returns the callback tagged with its type and the contract\n * version, for the CLI build to generate a worker artifact from. Used as the\n * default export of a service's `src` file.\n * @deprecated Default-export a plain function that receives {@link WebWorkerProps} from the web worker's `src` file instead.\n * @public\n */\nexport function unstable_defineService<TType extends WebWorkerType>(\n type: TType,\n run: ServiceCallbacksByType[TType],\n): DefinedService<TType> {\n return {run, type, version: WEB_WORKER_CONTRACT_VERSION}\n}\n\n/**\n * @deprecated Use `WebWorkerProps['bus']`.\n * @public\n */\nexport type ServiceBus = WebWorkerProps['bus']\n\n/**\n * @deprecated Use `WebWorkerProps['worker']`.\n * @public\n */\nexport type ServiceInfo = WebWorkerProps['worker']\n"],"names":["WEB_WORKER_CONTRACT_VERSION","unstable_defineService","type","run","version"],"mappings":"AAEA,SAAQA,2BAA2B,QAA2B,gBAAe;AAqD7E;;;;;;;;;;CAUC,GACD,OAAO,SAASC,uBACdC,IAAW,EACXC,GAAkC;IAElC,OAAO;QAACA;QAAKD;QAAME,SAASJ;IAA2B;AACzD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/workbench-cli",
3
- "version": "2.17.0",
3
+ "version": "2.19.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",
@@ -67,11 +67,12 @@
67
67
  "dependencies": {
68
68
  "@module-federation/runtime": "2.9.3",
69
69
  "@module-federation/vite": "1.24.0",
70
- "@sanity/cli-core": "^3.15.1",
71
- "@sanity/sdk": "^3.12.0",
72
- "@sanity/types": "^6.22.0",
70
+ "@sanity/cli-core": "^3.16.0",
71
+ "@sanity/sdk": "^3.15.0",
72
+ "@sanity/types": "^6.24.0",
73
73
  "@vitejs/plugin-react": "^6.3.0",
74
74
  "form-data": "^4.0.6",
75
+ "open": "^11.0.4",
75
76
  "rxjs": "^7.8.2",
76
77
  "semver": "^7.8.6",
77
78
  "tar": "^7.5.23",
@@ -79,25 +80,24 @@
79
80
  "zod": "^4.6.7"
80
81
  },
81
82
  "devDependencies": {
82
- "@eslint/compat": "^2.1.0",
83
+ "@repo/oxc-config": "0.0.0",
83
84
  "@repo/package.config": "0.0.1",
84
85
  "@repo/tsconfig": "3.70.0",
85
- "@sanity/cli-test": "25.0.1",
86
- "@sanity/eslint-config-cli": "^1.1.3",
86
+ "@sanity/cli-test": "26.0.0",
87
87
  "@sanity/pkg-utils": "^12.3.4",
88
88
  "@swc/cli": "^0.8.2",
89
89
  "@swc/core": "^1.16.22",
90
90
  "@types/node": "^22.20.5",
91
91
  "@types/react": "^19.3.0",
92
92
  "@types/semver": "^7.8.0",
93
- "@vitest/coverage-istanbul": "^5.1.0",
94
- "eslint": "^10.7.0",
93
+ "@vitest/coverage-istanbul": "^5.1.1",
95
94
  "jsdom": "^29.1.1",
96
- "publint": "^0.3.21",
95
+ "oxlint": "^1.94.0",
96
+ "publint": "^0.3.25",
97
97
  "react": "^19.3.1",
98
98
  "react-dom": "^19.3.1",
99
99
  "typescript": "^6.0.3",
100
- "vitest": "^5.1.0"
100
+ "vitest": "^5.1.1"
101
101
  },
102
102
  "engines": {
103
103
  "node": ">=22.12"
@@ -106,12 +106,12 @@
106
106
  "build": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ src",
107
107
  "build:types": "pkg-utils build --emitDeclarationOnly",
108
108
  "check:types": "tsc --noEmit",
109
- "lint": "eslint .",
110
109
  "publint": "publint",
111
110
  "test": "vitest run",
112
111
  "posttest": "pnpm run lint",
113
112
  "test:coverage": "vitest run --coverage",
114
113
  "test:watch": "vitest",
115
- "watch": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ --watch src"
114
+ "watch": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ --watch src",
115
+ "lint": "oxlint -c oxlint.config.ts"
116
116
  }
117
117
  }
@@ -1,123 +0,0 @@
1
- import { g as WEB_WORKER_CONTRACT_VERSION, v as WebWorkerType } from "./contract-WrU3aOYd.js";
2
- import { EventTopic, MessageBus, MessageBusAbortOptions, MessageBusMessage, PayloadOf, ReplyOf, StateTopic, ValueOf } from "@sanity/sdk/dashboard";
3
- /**
4
- * The web worker's own declaration.
5
- * @public
6
- */
7
- interface WebWorkerInfo {
8
- readonly name: string;
9
- readonly type: string;
10
- }
11
- /**
12
- * The message bus as a web worker sees it: the SDK's `MessageBus` without the
13
- * `subscribe` forms that return observables, which would make the web worker's
14
- * project install rxjs. There is no `disconnect`: Dashboard owns the connection
15
- * and ends it when it stops the worker.
16
- * @public
17
- */
18
- interface WebWorkerBus extends Omit<MessageBus, 'subscribe'> {
19
- /** Runs a responder for each event until its signal aborts. */
20
- subscribe<K extends EventTopic>(type: K, handler: (message: MessageBusMessage<PayloadOf<K>, ReplyOf<K>, K>) => void, options?: MessageBusAbortOptions): void;
21
- /** Runs a handler for each state value until its signal aborts. */
22
- subscribe<K extends StateTopic>(type: K, handler: (value: ValueOf<K>) => void, options?: MessageBusAbortOptions): void;
23
- }
24
- /**
25
- * Context every service callback receives when its worker starts. Mirrors how a
26
- * view component receives its `view` — the service receives its own `service`.
27
- * @deprecated Use {@link WebWorkerProps}.
28
- * @public
29
- */
30
- interface ServiceContext {
31
- readonly bus: WebWorkerBus;
32
- readonly service: WebWorkerInfo;
33
- }
34
- /**
35
- * Props a web worker function receives when its worker starts. The default
36
- * export of a web worker's `src` file runs once inside the worker.
37
- *
38
- * `bus` is its connection to the Dashboard message bus:
39
- * `bus.emit` sends an event (such as a dock-badge update), `bus.query` reads the
40
- * current value of a state topic, and `bus.subscribe` runs a handler on each
41
- * new value of a state topic, or on each event of an event topic, until its
42
- * `signal` aborts. A refused, unanswered or timed-out `emit` or `query` rejects
43
- * with an `Error` named `MessageBusError` whose `code` says why; it is not an
44
- * instance of the SDK's `MessageBusError` class. When the Dashboard's refusal
45
- * says how to fix it, the error also carries `fix` and `docsUrl`. A refused
46
- * `subscribe` has no error: its handler never runs, and the Dashboard reports
47
- * the refusal in the browser console.
48
- *
49
- * An event handler answers the sender with `message.reply(value)` or refuses
50
- * with `message.reject(reason)`; one that throws refuses with code
51
- * `HANDLER_THREW`. For example, a worker that keeps a snapshot for its app's
52
- * views, which listen with `useWorker` first and then post to it. A view's post
53
- * arrives on `workers.post` as `{name, payload}`, and `workers.message` reaches
54
- * only this app's views:
55
- *
56
- * ```ts
57
- * export default ({bus}: WebWorkerProps) => {
58
- * const controller = new AbortController()
59
- * bus.subscribe('workers.post', (message) => message.reply(snapshot), {
60
- * signal: controller.signal,
61
- * })
62
- * // Views that are already listening post again.
63
- * bus.emit('workers.message', {type: 'welcome'})
64
- * return () => controller.abort()
65
- * }
66
- * ```
67
- *
68
- * The function can return a disposer, which runs when Dashboard stops the
69
- * worker. By then the bus is closed: subscriptions have ended, `emit` and
70
- * `query` reject with code `ABORTED`, and `subscribe` throws that error.
71
- * @public
72
- */
73
- interface WebWorkerProps {
74
- readonly bus: WebWorkerBus;
75
- readonly worker: WebWorkerInfo;
76
- }
77
- /**
78
- * A service callback. Runs once inside the worker on start; returns an optional
79
- * disposer the host calls before terminating the worker.
80
- * @deprecated Default-export a plain function that receives {@link WebWorkerProps} instead.
81
- * @public
82
- */
83
- type ServiceCallback = (context: ServiceContext) => (() => void) | void;
84
- /** The callback shape each service type defines, keyed by type. */
85
- interface ServiceCallbacksByType {
86
- worker: ServiceCallback;
87
- }
88
- /**
89
- * The result of `unstable_defineService`: the author's callback, the service
90
- * type, and the internal contract version the worker artifact targets.
91
- * @deprecated Default-export a plain function that receives {@link WebWorkerProps} instead.
92
- * @public
93
- */
94
- interface DefinedService<TType extends WebWorkerType = WebWorkerType> {
95
- readonly run: ServiceCallbacksByType[TType];
96
- readonly type: TType;
97
- /** @internal */
98
- readonly version: typeof WEB_WORKER_CONTRACT_VERSION;
99
- }
100
- /**
101
- * Define a Sanity Dashboard background service. The first argument narrows the
102
- * callback shape — `"worker"` runs the callback inside a Web Worker with the
103
- * bus described on {@link WebWorkerProps}.
104
- *
105
- * Identity at runtime: returns the callback tagged with its type and the contract
106
- * version, for the CLI build to generate a worker artifact from. Used as the
107
- * default export of a service's `src` file.
108
- * @deprecated Default-export a plain function that receives {@link WebWorkerProps} from the web worker's `src` file instead.
109
- * @public
110
- */
111
- declare function unstable_defineService<TType extends WebWorkerType>(type: TType, run: ServiceCallbacksByType[TType]): DefinedService<TType>;
112
- /**
113
- * @deprecated Use `WebWorkerBus`.
114
- * @public
115
- */
116
- type ServiceBus = WebWorkerBus;
117
- /**
118
- * @deprecated Use `WebWorkerInfo`.
119
- * @public
120
- */
121
- type ServiceInfo = WebWorkerInfo;
122
- export { ServiceInfo as a, WebWorkerProps as c, ServiceContext as i, unstable_defineService as l, ServiceBus as n, WebWorkerBus as o, ServiceCallback as r, WebWorkerInfo as s, DefinedService as t };
123
- //# sourceMappingURL=webWorker-TWUbh0uo.d.ts.map