@sanity/workbench 0.1.0-alpha.5 → 0.1.0-alpha.7

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 (43) hide show
  1. package/dist/{log.js → _chunks-es/index.js} +1 -1
  2. package/dist/_chunks-es/index.js.map +1 -0
  3. package/dist/_internal.d.ts +13 -6
  4. package/dist/_internal.js +21 -5
  5. package/dist/_internal.js.map +1 -1
  6. package/dist/core.d.ts +906 -0
  7. package/dist/core.js +642 -0
  8. package/dist/core.js.map +1 -0
  9. package/package.json +11 -5
  10. package/src/_exports/core.ts +1 -0
  11. package/src/_internal/index.ts +2 -1
  12. package/src/_internal/render.test.ts +56 -1
  13. package/src/_internal/render.ts +52 -28
  14. package/src/core/__tests__/__fixtures__.ts +248 -0
  15. package/src/core/applications/application-list.test.ts +222 -0
  16. package/src/core/applications/application-list.ts +103 -0
  17. package/src/core/applications/application.ts +78 -0
  18. package/src/core/applications/local-application.test.ts +93 -0
  19. package/src/core/applications/local-application.ts +52 -0
  20. package/src/core/canvases.test.ts +38 -0
  21. package/src/core/canvases.ts +81 -0
  22. package/src/core/config.ts +34 -0
  23. package/src/core/index.ts +12 -0
  24. package/src/core/media-libraries.test.ts +38 -0
  25. package/src/core/media-libraries.ts +83 -0
  26. package/src/core/organizations.test.ts +134 -0
  27. package/src/core/organizations.ts +115 -0
  28. package/src/core/projects.test.ts +248 -0
  29. package/src/core/projects.ts +114 -0
  30. package/src/core/shared/urls.test.ts +182 -0
  31. package/src/core/shared/urls.ts +128 -0
  32. package/src/core/user-applications/core-app.test.ts +151 -0
  33. package/src/core/user-applications/core-app.ts +57 -0
  34. package/src/core/user-applications/studio.test.ts +928 -0
  35. package/src/core/user-applications/studio.ts +656 -0
  36. package/src/core/user-applications/user-application.test.ts +126 -0
  37. package/src/core/user-applications/user-application.ts +76 -0
  38. package/src/vite-env.d.ts +8 -0
  39. package/dist/log.d.ts +0 -48
  40. package/dist/log.js.map +0 -1
  41. package/src/_exports/log.ts +0 -1
  42. /package/src/{log → core/log}/index.test.ts +0 -0
  43. /package/src/{log → core/log}/index.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sources":["../src/core/applications/application.ts","../src/core/applications/local-application.ts","../src/core/applications/application-list.ts","../src/core/organizations.ts","../src/core/canvases.ts","../src/core/media-libraries.ts","../src/core/projects.ts","../src/core/user-applications/user-application.ts","../src/core/user-applications/core-app.ts","../src/core/shared/urls.ts","../src/core/user-applications/studio.ts"],"sourcesContent":["import type { Resource as ProtocolResource } from \"@sanity/message-protocol\";\n\n/**\n * @public\n */\nexport type AbstractApplicationType =\n | \"studio\"\n | \"coreApp\"\n | \"canvas\"\n | \"media-library\"\n | \"workspace\";\n\n/**\n * @public\n */\nexport abstract class AbstractApplication<\n TType extends AbstractApplicationType,\n TProtocolResource extends ProtocolResource = Extract<\n ProtocolResource,\n { type: TType }\n >,\n> {\n readonly type: TType;\n\n constructor(type: TType) {\n this.type = type;\n }\n\n abstract get href(): string;\n\n abstract get title(): string;\n\n abstract get id(): string;\n\n get initials(): string {\n const SYMBOLS = /[^\\p{Alpha}\\p{N}\\p{White_Space}]/gu;\n const WHITESPACE = /\\p{White_Space}+/u;\n const ALPHANUMERIC_SEGMENTS = /(\\p{N}+|\\p{Alpha}+)/gu;\n const IS_NUMERIC = /^\\p{N}+$/u;\n\n if (!this.title) return \"\";\n\n const namesArray = this.title\n .replace(SYMBOLS, \"\")\n .split(WHITESPACE)\n .filter(Boolean);\n\n if (namesArray.length === 0) return \"\";\n\n if (namesArray.length === 1) {\n const word = namesArray[0];\n const segments = word.match(ALPHANUMERIC_SEGMENTS) || [];\n\n if (segments.length === 0) return \"\";\n if (segments.length === 1) {\n if (word.length === 1) {\n return word.toUpperCase();\n }\n\n if (IS_NUMERIC.test(word)) {\n return `${word.charAt(0)}${word.charAt(1)}`.toUpperCase();\n }\n\n return word.charAt(0).toUpperCase();\n }\n\n return `${segments[0]!.charAt(0)}${segments[1].charAt(0)}`.toUpperCase();\n }\n\n return `${namesArray[0].charAt(0)}${namesArray[namesArray.length - 1].charAt(0)}`.toUpperCase();\n }\n\n /**\n * Converts the resource to a protocol resource that comlink expects\n * for backwards compatibility with the old API format.\n */\n abstract toProtocolResource(): TProtocolResource;\n}\n","import { AbstractApplication } from \"./application\";\n\n/**\n * Raw data for a local application discovered by the CLI dev server.\n *\n * @experimental\n * @public\n */\nexport interface LocalApplicationData {\n host: string;\n port: number;\n type: \"studio\" | \"coreApp\";\n}\n\n/**\n * An Application wrapping a locally-discovered CLI application.\n * Provides a deterministic id, title and href suitable for use in navigation.\n *\n * @internal\n */\nexport class LocalApplication extends AbstractApplication<\n \"studio\" | \"coreApp\",\n never\n> {\n readonly localApplication: LocalApplicationData;\n\n constructor(localApplication: LocalApplicationData) {\n super(localApplication.type);\n this.localApplication = localApplication;\n }\n\n get id(): string {\n const { host, port } = this.localApplication;\n return `local-${host}-${port}`;\n }\n\n get title(): string {\n const { host, port } = this.localApplication;\n return `${host}:${port}`;\n }\n\n get href(): string {\n const { host, port } = this.localApplication;\n return `/local/${host}:${port}`;\n }\n\n toProtocolResource(): never {\n throw new Error(\n \"LocalApplication cannot be serialized to a protocol resource\",\n );\n }\n}\n","import type { Resource as ProtocolResource } from \"@sanity/message-protocol\";\n\nimport type { CanvasApplication } from \"../canvases\";\nimport type { MediaLibraryApplication } from \"../media-libraries\";\nimport type { CoreAppApplication } from \"../user-applications/core-app\";\nimport type {\n StudioApplication,\n StudioWorkspace,\n} from \"../user-applications/studio\";\nimport type { UserApplicationId } from \"../user-applications/user-application\";\nimport { LocalApplication } from \"./local-application\";\n\ntype Application =\n | CoreAppApplication\n | StudioApplication\n | StudioWorkspace\n | CanvasApplication\n | MediaLibraryApplication\n | LocalApplication;\n\n/**\n * @public\n */\nexport class ApplicationList<TApplication extends Application = Application> {\n readonly applications: TApplication[];\n\n /**\n * @param applications - The applications to initialize the list with.\n */\n constructor(applications: TApplication[]) {\n this.applications = [...applications];\n }\n\n findApplicationsByType<T extends TApplication[\"type\"]>(\n type: T,\n ): Extract<TApplication, { type: T }>[];\n findApplicationsByType<T extends TApplication[\"type\"][]>(\n types: T,\n ): Extract<TApplication, { type: T[number] }>[];\n findApplicationsByType(\n _type: TApplication[\"type\"] | TApplication[\"type\"][],\n ): TApplication[] {\n const types = Array.isArray(_type) ? _type : [_type];\n\n return this.applications.filter((r) => types.includes(r.type));\n }\n\n findApplication(\n type: \"media-library\",\n ): Extract<TApplication, { type: \"media-library\" }> | undefined;\n findApplication(\n type: \"canvas\",\n ): Extract<TApplication, { type: \"canvas\" }> | undefined;\n findApplication(\n type: \"coreApp\",\n id: UserApplicationId,\n ): Extract<TApplication, { type: \"coreApp\" }> | undefined;\n findApplication(\n type: \"studio\",\n id: UserApplicationId,\n ): Extract<TApplication, { type: \"studio\" }> | undefined;\n findApplication(\n type: \"workspace\",\n id: string,\n ): Extract<TApplication, { type: \"workspace\" }> | undefined;\n findApplication(\n type: TApplication[\"type\"],\n id?: UserApplicationId | string,\n ): TApplication | undefined {\n switch (type) {\n case \"media-library\":\n case \"canvas\":\n return this.applications.find((r) => r.type === type);\n case \"coreApp\":\n case \"studio\":\n case \"workspace\": {\n return this.applications.find((r) => r.type === type && r.id === id);\n }\n }\n }\n\n toProtocolResources() {\n return this.applications.reduce<ProtocolResource[]>((acc, r) => {\n if (r.type === \"studio\" || r instanceof LocalApplication) return acc;\n return [...acc, r.toProtocolResource()];\n }, []);\n }\n\n static areApplicationsEqual(\n application1?: Application,\n application2?: Application,\n ): boolean {\n if (\n !application1 ||\n !application2 ||\n application1.type !== application2.type\n ) {\n return false;\n }\n\n return application1.id === application2.id;\n }\n}\n","import { z } from \"zod\";\n\n/**\n * Organization ID schema, branded for type safety.\n * @public\n */\nexport const OrganizationId = z.string().nonempty().brand(\"OrganizationId\");\n\n/**\n * Organization ID type, branded for type safety.\n * @public\n */\nexport type OrganizationId = z.output<typeof OrganizationId>;\n\n/**\n * Validates and brands a string as an OrganizationId.\n * @public\n */\nexport function brandOrganizationId(id: string): OrganizationId {\n return OrganizationId.parse(id);\n}\n\nconst OrganizationMember = z.object({\n sanityUserId: z.string(),\n isCurrentUser: z.boolean(),\n user: z.object({\n id: z.string(),\n displayName: z.string(),\n familyName: z.string(),\n givenName: z.string(),\n middleName: z.string().nullable(),\n imageUrl: z.string().nullable(),\n email: z.string(),\n loginProvider: z.string(),\n }),\n roles: z.array(\n z.object({\n name: z.string(),\n title: z.string(),\n description: z.string().optional(),\n }),\n ),\n});\n\n/**\n * @public\n */\nexport type OrganizationMember = z.output<typeof OrganizationMember>;\n\n/**\n * Organization schema — validates and brands API responses\n * from the `/organizations/:id` endpoint.\n * @public\n */\nexport const Organization = z.object({\n id: OrganizationId,\n name: z.string(),\n slug: z.string().nullable(),\n createdAt: z.string(),\n updatedAt: z.string(),\n dashboardStatus: z.enum([\"enabled\", \"disabled\"]),\n aiFeaturesStatus: z.enum([\"enabled\", \"disabled\"]),\n defaultRoleName: z.string(),\n});\n\n/**\n * Represents an organization with optional members and\n * features arrays depending on the generic parameters.\n * - `Organization` — base fields only (default)\n * - `Organization<true>` — includes `members`\n * - `Organization<true, true>` — includes both\n * @public\n */\nexport type Organization<\n IncludeMembers extends boolean = true,\n IncludeFeatures extends boolean = true,\n> = z.output<typeof Organization> &\n (IncludeMembers extends true ? { members: OrganizationMember[] } : unknown) &\n (IncludeFeatures extends true ? { features: string[] } : unknown);\n\n/**\n * Validates and parses a raw API response into a branded\n * Organization. The options control which schema is used —\n * matching what the API returns based on query params.\n * @public\n */\nexport function parseOrganization<\n IncludeMembers extends boolean = true,\n IncludeFeatures extends boolean = true,\n>(\n data: unknown,\n options?: {\n includeMembers?: IncludeMembers;\n includeFeatures?: IncludeFeatures;\n },\n): Organization<IncludeMembers, IncludeFeatures> {\n const includeMembers = options?.includeMembers ?? true;\n const includeFeatures = options?.includeFeatures ?? true;\n\n const extensions = {\n ...(includeMembers && {\n members: z.array(OrganizationMember),\n }),\n ...(includeFeatures && {\n features: z.array(z.string()),\n }),\n };\n\n const schema =\n Object.keys(extensions).length > 0\n ? Organization.extend(extensions)\n : Organization;\n\n return schema.parse(data) as Organization<IncludeMembers, IncludeFeatures>;\n}\n","import type { CanvasResource as ProtocolCanvasResource } from \"@sanity/message-protocol\";\nimport { z } from \"zod\";\n\nimport { AbstractApplication } from \"./applications/application\";\nimport { OrganizationId } from \"./organizations\";\n\n/**\n * Canvas ID schema, branded for type safety.\n * @public\n */\nconst CanvasId = z.string().nonempty().brand(\"CanvasId\");\n\n/**\n * Canvas ID type, branded for type safety.\n * @public\n */\nexport type CanvasId = z.output<typeof CanvasId>;\n\n/**\n * Validates and brands a string as a CanvasId.\n * @public\n */\nexport function brandCanvasId(id: string): CanvasId {\n return CanvasId.parse(id);\n}\n\nconst Canvas = z.object({\n id: CanvasId,\n organizationId: OrganizationId,\n status: z.enum([\"active\", \"provisioning\"]),\n});\n\n/**\n * Represents a Canvas resource as returned from the API.\n * @public\n */\nexport type Canvas = z.output<typeof Canvas>;\n\n/**\n * Validates and parses a raw API response into a branded\n * Canvas.\n * @public\n */\nexport function parseCanvas(data: unknown): Canvas {\n return Canvas.parse(data);\n}\n\n/**\n * Whilst the constructor takes an organization's canvas resource the existance\n * therefore implies the organization has access to the canvas application which\n * is what workbench most importantly wants to know.\n * @public\n */\nexport class CanvasApplication extends AbstractApplication<\"canvas\"> {\n private readonly canvas: Canvas;\n\n constructor(canvas: Canvas) {\n super(\"canvas\");\n\n this.canvas = canvas;\n }\n\n get id(): CanvasId {\n return this.canvas.id;\n }\n\n get href(): string {\n return \"canvas\";\n }\n\n get title(): string {\n return \"Canvas\";\n }\n\n toProtocolResource(): ProtocolCanvasResource {\n return {\n type: \"canvas\",\n id: this.id,\n } satisfies ProtocolCanvasResource;\n }\n}\n","import type { MediaResource as ProtocolMediaResource } from \"@sanity/message-protocol\";\nimport { z } from \"zod\";\n\nimport { AbstractApplication } from \"./applications/application\";\nimport { OrganizationId } from \"./organizations\";\n\n/**\n * Canvas ID schema, branded for type safety.\n * @public\n */\nconst MediaLibraryId = z.string().nonempty().brand(\"MediaLibraryId\");\n\n/**\n * MediaLibrary ID type, branded for type safety.\n * @public\n */\nexport type MediaLibraryId = z.output<typeof MediaLibraryId>;\n\n/**\n * Validates and brands a string as a MediaLibraryId.\n * @public\n */\nexport function brandMediaLibraryId(id: string): MediaLibraryId {\n return MediaLibraryId.parse(id);\n}\n\nconst MediaLibrary = z.object({\n id: MediaLibraryId,\n organizationId: OrganizationId,\n status: z.enum([\"active\", \"provisioning\"]),\n aclMode: z.enum([\"private\", \"public\"]),\n});\n\n/**\n * Represents a MediaLibrary resource as returned from the API.\n * @public\n */\nexport type MediaLibrary = z.output<typeof MediaLibrary>;\n\n/**\n * Validates and parses a raw API response into a branded\n * MediaLibrary.\n * @public\n */\nexport function parseMediaLibrary(data: unknown): MediaLibrary {\n return MediaLibrary.parse(data);\n}\n\n/**\n * Whilst the constructor takes an organization's media library resource the existance\n * therefore implies the organization has access to the media library application which\n * is what workbench most importantly wants to know.\n * @public\n */\n\nexport class MediaLibraryApplication extends AbstractApplication<\"media-library\"> {\n private readonly library: MediaLibrary;\n\n constructor(library: MediaLibrary) {\n super(\"media-library\");\n\n this.library = library;\n }\n\n get id(): string {\n return this.library.id;\n }\n\n get href(): string {\n return \"media\";\n }\n\n get title(): string {\n return \"Media Library\";\n }\n\n toProtocolResource(): ProtocolMediaResource {\n return {\n type: \"media-library\",\n id: this.id,\n } satisfies ProtocolMediaResource;\n }\n}\n","import { z } from \"zod\";\n\nimport { OrganizationId } from \"./organizations\";\n\n/**\n * Project ID schema, branded for type safety.\n * @public\n */\nexport const ProjectId = z.string().nonempty().brand(\"ProjectId\");\n\n/**\n * Project ID type, branded for type safety.\n * @public\n */\nexport type ProjectId = z.output<typeof ProjectId>;\n\n/**\n * Validates and brands a string as a ProjectId.\n * @public\n */\nexport function brandProjectId(id: string): ProjectId {\n return ProjectId.parse(id);\n}\n\nconst ProjectMember = z.object({\n id: z.string(),\n createdAt: z.string(),\n updatedAt: z.string(),\n isCurrentUser: z.boolean(),\n isRobot: z.boolean(),\n roles: z.array(\n z.object({\n name: z.string(),\n title: z.string(),\n description: z.string(),\n }),\n ),\n});\n\n/**\n * @public\n */\nexport type ProjectMember = z.output<typeof ProjectMember>;\n\n/**\n * Project schema — validates and brands API responses\n * from the `/projects/:id` endpoint.\n * @public\n */\nexport const Project = z.object({\n id: ProjectId,\n displayName: z.string(),\n studioHost: z.string().nullable(),\n organizationId: OrganizationId,\n metadata: z.object({\n color: z.string().optional(),\n externalStudioHost: z.string().optional(),\n initialTemplate: z.string().optional(),\n cliInitializedAt: z.string().optional(),\n integration: z.literal([\"manage\", \"cli\"]),\n }),\n isBlocked: z.boolean(),\n isDisabled: z.boolean(),\n isDisabledByUser: z.boolean(),\n activityFeedEnabled: z.boolean(),\n createdAt: z.string(),\n updatedAt: z.string(),\n});\n\n/**\n * Represents a Sanity project with optional members and\n * features arrays depending on the generic parameters.\n * By default, neither members nor features are included.\n * - `Project` — base fields only (default)\n * - `Project<true>` — includes `members`\n * - `Project<true, true>` — includes both\n * @public\n */\nexport type Project<\n IncludeMembers extends boolean = true,\n IncludeFeatures extends boolean = true,\n> = z.output<typeof Project> &\n (IncludeMembers extends true ? { members: ProjectMember[] } : unknown) &\n (IncludeFeatures extends true ? { features: string[] } : unknown);\n\n/**\n * Validates and parses a raw API response into a branded\n * Project. The options control which schema is used —\n * matching what the API returns based on query params.\n * @public\n */\nexport function parseProject<\n IncludeMembers extends boolean = true,\n IncludeFeatures extends boolean = true,\n>(\n data: unknown,\n options?: {\n includeMembers?: IncludeMembers;\n includeFeatures?: IncludeFeatures;\n },\n): Project<IncludeMembers, IncludeFeatures> {\n const includeMembers = options?.includeMembers ?? true;\n const includeFeatures = options?.includeFeatures ?? true;\n\n const extensions = {\n ...(includeMembers && { members: z.array(ProjectMember) }),\n ...(includeFeatures && { features: z.array(z.string()) }),\n };\n\n const schema =\n Object.keys(extensions).length > 0 ? Project.extend(extensions) : Project;\n\n return schema.parse(data) as Project<IncludeMembers, IncludeFeatures>;\n}\n","import type {\n Resource as ProtocolResource,\n UserApplication as UserApplicationData,\n} from \"@sanity/message-protocol\";\nimport { z } from \"zod\";\n\nimport {\n AbstractApplication,\n type AbstractApplicationType,\n} from \"../applications/application\";\n\n/**\n * User application ID schema, branded for type safety.\n * @public\n */\nexport const UserApplicationId = z\n .string()\n .nonempty()\n .brand(\"UserApplicationId\");\n\n/**\n * User application ID type, branded for type safety.\n * @public\n */\nexport type UserApplicationId = z.output<typeof UserApplicationId>;\n\n/**\n * Validates and brands a string as a UserApplicationId.\n * @public\n */\nexport function brandUserApplicationId(id: string): UserApplicationId {\n return UserApplicationId.parse(id);\n}\n\n/**\n * @internal\n */\nexport abstract class UserApplication<\n TUserApplication extends UserApplicationData,\n TType extends Extract<AbstractApplicationType, \"coreApp\" | \"studio\">,\n TProtocolResource extends ProtocolResource = Extract<\n ProtocolResource,\n { type: TType }\n >,\n> extends AbstractApplication<TType, TProtocolResource> {\n readonly application: TUserApplication;\n\n readonly id: UserApplicationId;\n\n constructor(application: TUserApplication, type: TType) {\n super(type);\n this.application = application;\n this.id = brandUserApplicationId(application.id);\n }\n\n abstract get subtitle(): string | undefined;\n\n /**\n * @returns A fully resolved URL instance for the application.\n * For internal applications, constructs a URL using the Sanity studio domain\n * pattern resolved from the environment at the consuming app's build time.\n * For external applications, returns the provided app host as a URL.\n */\n get url(): URL {\n if (this.application.urlType === \"internal\") {\n if (import.meta.env.VITE_SANITY_ENV === \"production\") {\n return new URL(`https://${this.application.appHost}.sanity.studio`);\n }\n return new URL(\n `https://${this.application.appHost}.studio.${import.meta.env.VITE_SANITY_DOMAIN}`,\n );\n }\n\n return new URL(this.application.appHost);\n }\n}\n","import type {\n ApplicationResource as ProtocolApplicationResource,\n CoreApplication,\n} from \"@sanity/message-protocol\";\n\nimport { UserApplication } from \"./user-application\";\n\n/**\n * @internal\n */\nexport class CoreAppApplication extends UserApplication<\n CoreApplication,\n \"coreApp\",\n ProtocolApplicationResource\n> {\n readonly activeDeployment: CoreApplication[\"activeDeployment\"];\n\n constructor(application: CoreApplication) {\n super(application, \"coreApp\");\n\n this.activeDeployment = application.activeDeployment;\n }\n\n get href() {\n return `/application/${this.application.id}`;\n }\n\n get title() {\n return this.activeDeployment?.manifest?.title ?? this.application.title;\n }\n\n get subtitle() {\n return undefined;\n }\n\n get updatedAt() {\n return this.application.updatedAt;\n }\n\n get<TKey extends keyof CoreApplication>(attr: TKey): CoreApplication[TKey] {\n if (!(attr in this.application)) {\n throw new Error(\n `Attribute ${attr.toString()} does not exist on application ${this.application.id}`,\n );\n }\n\n return this.application[attr];\n }\n\n toProtocolResource(): ProtocolApplicationResource {\n return {\n ...this.application,\n type: \"application\",\n url: this.url.toString(),\n } satisfies ProtocolApplicationResource;\n }\n}\n","/**\n * Joins multiple path segments into a single path string.\n * Handles null, undefined, and URL objects gracefully.\n *\n * @param paths - An array of path segments to join.\n * @returns A single joined path string.\n */\nexport const joinUrlPaths = (\n ...paths: Array<string | URL | null | undefined>\n): string => {\n let nextPath = null;\n\n const safeJoinSegments = (\n segment1: string | null | undefined,\n segment2: string | null | undefined,\n ): string => {\n if (!segment1) {\n if (!segment2) {\n return \"\";\n }\n\n return segment2;\n }\n\n if (!segment2) {\n return segment1;\n }\n\n if (segment1.endsWith(\"/\") && segment2.startsWith(\"/\")) {\n return segment1 + segment2.slice(1);\n }\n\n if (segment1.endsWith(\"/\") || segment2.startsWith(\"/\")) {\n return segment1 + segment2;\n }\n\n return `${segment1}/${segment2}`;\n };\n\n const validPaths = paths.filter(\n (path) => path !== null && path !== undefined,\n );\n\n for (const path of validPaths) {\n nextPath = safeJoinSegments(\n nextPath,\n path instanceof URL ? path.pathname : path,\n );\n }\n\n return nextPath ?? \"\";\n};\n\n/**\n * Returns a normalized path by ensuring it starts with a single leading slash\n * and does not end with a trailing slash (unless it's the root path).\n */\nexport function normalizePath(pathname: string): string {\n if (!pathname.startsWith(\"/\")) {\n pathname = `/${pathname}`;\n }\n\n if (pathname !== \"/\" && pathname.endsWith(\"/\")) {\n pathname = pathname.slice(0, -1);\n }\n\n return pathname;\n}\n\n/**\n * The pathname, search, and hash values of a URL.\n */\ninterface Path {\n /**\n * A URL pathname, beginning with a /.\n */\n pathname: string;\n /**\n * A URL search string, beginning with a ?.\n */\n search: string;\n /**\n * A URL fragment identifier, beginning with a #.\n */\n hash: string;\n}\n\n/**\n * Parses a string URL path into its separate pathname, search, and hash components.\n */\nexport function parsePath(path: string): Partial<Path> {\n let parsedPath: Partial<Path> = {};\n\n if (path) {\n let hashIndex = path.indexOf(\"#\");\n if (hashIndex >= 0) {\n parsedPath.hash = path.substring(hashIndex);\n path = path.substring(0, hashIndex);\n }\n\n let searchIndex = path.indexOf(\"?\");\n if (searchIndex >= 0) {\n parsedPath.search = path.substring(searchIndex);\n path = path.substring(0, searchIndex);\n }\n\n if (path) {\n parsedPath.pathname = path;\n }\n }\n\n return parsedPath;\n}\n\n/**\n * Creates a string URL path from the given pathname, search, and hash components.\n */\nexport function createPath({\n pathname = \"/\",\n search = \"\",\n hash = \"\",\n}: Partial<Path>) {\n if (search && search !== \"?\")\n pathname += search.charAt(0) === \"?\" ? search : `?${search}`;\n if (hash && hash !== \"#\")\n pathname += hash.charAt(0) === \"#\" ? hash : `#${hash}`;\n return pathname;\n}\n","import type {\n StudioApplication as StudioApplicationData,\n // eslint-disable-next-line no-restricted-imports\n StudioResource as ProtocolStudioResource,\n WorkspaceManifest,\n} from \"@sanity/message-protocol\";\nimport type { SemVer } from \"semver\";\nimport { coerce, gt, gte, lt, rsort, valid } from \"semver\";\nimport { z } from \"zod\";\n\nimport { AbstractApplication } from \"../applications/application\";\nimport {\n brandProjectId,\n ProjectId as ProjectIdSchema,\n type Project,\n type ProjectId,\n} from \"../projects\";\nimport { joinUrlPaths, normalizePath } from \"../shared/urls\";\nimport { type UserApplicationId } from \"./user-application\";\nimport { UserApplication } from \"./user-application\";\n\nconst WORKSPACE_MANIFEST_SCHEMA = z.object({\n name: z.string(),\n title: z.string(),\n subtitle: z.string().nullable().optional(),\n basePath: z.string(),\n projectId: ProjectIdSchema,\n dataset: z.string(),\n icon: z.string().optional().nullable(),\n schema: z.string(),\n tools: z.string().optional(),\n});\n\nconst STUDIO_MANIFEST_SCHEMA = z\n .object({\n // data from manifest\n version: z.number(),\n createdAt: z.string(),\n studioVersion: z.string().nullable().optional(),\n // data from workspace object\n workspaces: z.array(WORKSPACE_MANIFEST_SCHEMA),\n })\n .superRefine((data, ctx) => {\n if (!data.version) {\n ctx.addIssue({\n code: \"invalid_type\",\n message: \"Manifest version is too old\",\n expected: \"number\",\n });\n }\n\n if (data.version < 2) {\n ctx.addIssue({\n code: \"invalid_value\",\n message: \"Manifest version is too old\",\n values: [2, 3],\n });\n }\n\n if (data.version >= 3 && !data.studioVersion) {\n ctx.addIssue({\n code: \"invalid_type\",\n message: \"Manifest version 3 or higher requires a `studioVersion`\",\n expected: \"string\",\n });\n }\n });\n\nconst DEFAULT_WORKSPACE_DATA = {\n name: \"default\",\n title: \"Default\",\n basePath: \"/\",\n} as const satisfies Partial<Workspace>;\n\n/**\n * @internal\n */\nexport class StudioApplication extends UserApplication<\n StudioApplicationData,\n \"studio\",\n never\n> {\n /**\n * Returns a list of studio workspaces based on the application manifest.\n * If there is no manifest, or alternatively it is not valid, then we create a default workspace.\n */\n readonly workspaces: readonly StudioWorkspace[] = [];\n\n readonly project: Project<false, false>;\n\n /**\n * @param application - The studio application to create a list of workspaces for\n * @param projects - The projects available in the organization. It's not enough to just pass\n * the project that associates with the application because that is the project the app is deployed in relation to.\n * The workspaces may have different projects completely.\n */\n constructor(\n application: StudioApplicationData,\n projects: Project<false, false>[],\n ) {\n super(application, \"studio\");\n\n /**\n * If the application has a manifest, then we validate it and create\n * a workspace for each manifest entry. Otherwise, we will create a \"default\"\n * workspace which is pretty much identical to when a user has a single workspace\n * studio application using the term \"default\" in places.\n */\n let workspaces: Workspace[] = [];\n if (this.hasManifest) {\n /**\n * If the workspaces fail to parse we dont want to throw an error because\n * this could potentially crash the app. Instead we log a warning and return an empty array.\n */\n try {\n workspaces = STUDIO_MANIFEST_SCHEMA.parse(\n application.manifestData?.value,\n ).workspaces;\n } catch (error) {\n console.warn(\n `Failed to parse manifest for application ${application.id}`,\n error,\n );\n }\n }\n\n if (workspaces.length === 0) {\n /**\n * If the user application does not have a valid manifest or no workspaces,\n * we attempt to get the manifest from the server-side maninfest first and then\n * fall back to the live-manifest.\n *\n * In the future this should happen even before checking the traditional manifest,\n * but for now we keep the current order to not introduce breaking changes.\n *\n * The live manifest is inherintly less reliable as it depends on which user has\n * uploaded it, which is why this is wrapped in a feature flag for now.\n */\n const deploymentManifest = application.activeDeployment?.manifest;\n // const liveManifest = growthbook.isOn('dashboard-use-live-manifest')\n // ? application.config['live-manifest']?.value\n // : null\n\n const serverManifest = deploymentManifest; /*?? liveManifest*/\n const serverManifestWorkspaces = serverManifest?.workspaces;\n\n if (\n Array.isArray(serverManifestWorkspaces) &&\n serverManifestWorkspaces.length\n ) {\n workspaces = serverManifestWorkspaces.map((w) => ({\n ...w,\n projectId: brandProjectId(w.projectId),\n }));\n }\n }\n\n /**\n * Filter all the workspaces that have a project the user does not have access to\n */\n const workspacesWithProjectsMap = workspaces.reduce((acc, workspace) => {\n const project = projects.find((p) => p.id === workspace.projectId);\n\n if (project) {\n acc.set(workspace, project);\n } else {\n console.warn(\n `Project not found for application ${application.id} and workspace ${workspace.name}. This workspace has been omitted.`,\n );\n }\n\n return acc;\n }, new Map<Workspace, Project<false, false>>());\n\n const brandedProjectId = brandProjectId(application.projectId);\n const project = projects.find((p) => p.id === brandedProjectId);\n\n if (!project) {\n throw new Error(`Project not found for application ${application.id}`);\n }\n\n if (workspacesWithProjectsMap.size === 0) {\n /**\n * If there are still no workspaces, we create a default workspace.\n */\n workspacesWithProjectsMap.set(\n {\n ...DEFAULT_WORKSPACE_DATA,\n projectId: brandedProjectId,\n } satisfies Workspace,\n project,\n );\n }\n\n this.workspaces = Object.freeze(\n Array.from(workspacesWithProjectsMap.entries()).map(([workspace, p]) => {\n /**\n * A workspace is considered the default if the dashboard generated it OR because\n * the properties match that of the default workspace generated by the studio.\n * Which is why these values will match because dashboard generates an identical\n * workspace to the default studio one.\n */\n const isDefaultWorkspace =\n workspace.name === DEFAULT_WORKSPACE_DATA.name &&\n workspace.basePath === DEFAULT_WORKSPACE_DATA.basePath &&\n workspace.title === DEFAULT_WORKSPACE_DATA.title;\n\n return new StudioWorkspace(this, workspace, p, isDefaultWorkspace);\n }),\n );\n\n this.project = project;\n }\n\n get href() {\n return `/studio/${this.application.id}`;\n }\n\n get title() {\n // Get the title from the user application, this has the highest precedence\n const title = this.get(\"title\");\n if (title) {\n return title;\n }\n\n // If there are multiple workspaces and the studio is internal, use the project display name\n if (this.workspaces.length > 1 && this.get(\"urlType\") === \"internal\") {\n return this.project.displayName;\n }\n\n // Otherwise use the title of the first workspace\n return this.workspaces[0].title;\n }\n\n get subtitle() {\n return new URL(this.url).hostname;\n }\n\n get<TKey extends keyof StudioApplicationData>(\n attr: TKey,\n ): StudioApplicationData[TKey] {\n if (!(attr in this.application)) {\n throw new Error(\n `Attribute ${attr.toString()} does not exist on studio ${this.application.id}`,\n );\n }\n\n return this.application[attr];\n }\n\n get hasManifest(): boolean {\n return (\n typeof this.application.manifestData?.value?.version === \"number\" &&\n this.application.manifestData?.value?.version >= 2\n );\n }\n\n get hasSchema(): boolean {\n // In this case we can not look at `this.workspaces` because it won't contain workspaces the user does\n // not have access to. The application has a schema, even if the user can't access any of the workspaces,\n // otherwise it would be displayed as not having a manifest in the setup guide and therefore considered\n // partially compatible.\n const workspaces = this.get(\"manifestData\")?.value?.workspaces ?? [];\n\n if (workspaces.length === 0) {\n return false;\n }\n\n return workspaces.every((w) => Boolean(w.schema));\n }\n\n private resolveVersion() {\n // const growthbook = getGrowthbook()\n\n let version: string | undefined;\n\n if (this.get(\"urlType\") === \"internal\") {\n version = this.get(\"activeDeployment\")?.version;\n } else {\n const manifest = this.get(\"manifestData\")?.value;\n // The property 'studioVersion' exists only on external studios,\n // starting from manifest.version 3\n version =\n manifest && \"studioVersion\" in manifest\n ? manifest.studioVersion\n : undefined;\n }\n\n /**\n * Self-hosted studios are often not publicly accessible, which means that\n * Brett often times cannot fetch the manifest to read the version. In this case\n * we try to read the version from the deployment manifest or 'live-manifest', if it exists, to do\n * everything we can to determine the version.\n *\n * Since the data of the live-maninfest can not be trusted, we also must validate\n * that the version is a valid semver version before returning it. It always represents\n * the last known version from when the studio was connected to Sanity's infrastructure,\n * which might not be the version this studio is currently running (e.g. because the version\n * has been downgraded).\n */\n const deploymentManifest = this.get(\"activeDeployment\")?.manifest;\n // const liveManifest = growthbook.isOn('dashboard-use-live-manifest')\n // ? this.get('config')?.['live-manifest']?.value\n // : null\n\n const serverManifest = deploymentManifest; /*?? liveManifest*/\n const bundleVersion = serverManifest?.bundleVersion;\n\n if (bundleVersion && valid(coerce(bundleVersion))) {\n if (!version || (version && gt(bundleVersion, version))) {\n version = bundleVersion;\n }\n }\n\n if (!version || !valid(coerce(version))) {\n return null;\n }\n\n return coerce(version);\n }\n\n get version() {\n const version = this.resolveVersion();\n return version ? version.toString() : null;\n }\n\n get compatibilityStatus(): CompatibilityStatus {\n return StudioApplication.resolveCompatibilityStatus(this);\n }\n\n /**\n * Used to calculate the compatibility status of a given studio application.\n * Optionally if you've resolved the version elsewhere provide that value to\n * get the new compatibility status without mutating the application.\n */\n static resolveCompatibilityStatus(\n application: StudioApplication,\n version: string | null = application.version,\n ): CompatibilityStatus {\n if (\n version === null ||\n lt(version, StudioApplication.MinimumStudioVersion)\n ) {\n return StudioApplication.CompatibilityStatuses.UNKNOWN;\n }\n\n if (\n !application.hasSchema ||\n !application.hasManifest ||\n StudioApplication.resolveIssues(application, version).length > 0\n ) {\n return StudioApplication.CompatibilityStatuses.PARTIALLY_COMPATIBLE;\n }\n\n return StudioApplication.CompatibilityStatuses.FULLY_COMPATIBLE;\n }\n\n get isAutoRedirecting(): boolean {\n return StudioApplication.resolveIsAutoRedirecting(this);\n }\n\n /**\n * Mirrors the `isRedirectable` function from Saison defined in\n * https://github.com/sanity-io/saison/blob/83556405d23e07f6d3a71c76249c67e33fe1101f/src/utils/applications.ts\n *\n * Returns whether a studio application is auto-redirecting, meaning it can only be accessed in the context of\n * Dashboard.\n */\n static resolveIsAutoRedirecting(\n application: StudioApplication,\n versionArg = application.version,\n ) {\n let version: string | SemVer | null = versionArg;\n\n if (application.get(\"urlType\") === \"external\" || !version) {\n return false;\n }\n\n if (!application.get(\"activeDeployment\")?.isAutoUpdating) {\n // If the studio is not auto-updating, we need to check if the version supports\n // workspace switcher (3.92.0+) otherwise it would not be redirected.\n return gt(version, \"3.92.0\");\n }\n\n const autoUpdatingVersion = application.get(\"autoUpdatingVersion\");\n\n if (autoUpdatingVersion) {\n if ([\"next\", \"stable\", \"latest\"].includes(autoUpdatingVersion)) {\n return true;\n }\n\n const autoUpdatingVersionPinnedVersion = coerce(autoUpdatingVersion);\n\n if (autoUpdatingVersionPinnedVersion) {\n version = autoUpdatingVersionPinnedVersion;\n }\n }\n\n return gt(version, StudioApplication.MinimumStudioVersion);\n }\n\n /**\n * Returns a list of issues that prevent the studio from functioning properly in the Dashboard.\n * This static value depends on the version of the studio that comes from the `activeDeployment` property.\n * As such, if the studio is auto-updating, this list will be incorrect & instead you should use\n * the static method `resolveIssues` to get the correct issues by passing the resolved version.\n */\n get issues(): StudioIssues {\n return StudioApplication.resolveIssues(this);\n }\n\n static resolveIssues(\n application: StudioApplication,\n version: string | null = application.version,\n ): StudioIssues {\n const issues: StudioIssues = StudioApplication.Features.filter(\n (feature) => {\n return !application.isFeatureSupported(feature.id, version);\n },\n );\n\n if (!application.hasManifest) {\n issues.push({\n id: StudioApplication.StudioIssues.ISSUE_MANIFEST,\n });\n }\n\n return issues;\n }\n\n protected isFeatureSupported(\n feature: StudioDashboardIssue,\n version = this.version,\n ) {\n const featureVersion = StudioApplication.Features.find(\n (_) => _.id === feature,\n )?.version;\n\n if (!featureVersion || !version) {\n return false;\n }\n\n return gte(version, featureVersion);\n }\n\n toProtocolResource(): never {\n throw new Error(\n \"Studio application resources cannot be converted to protocol resources\",\n );\n }\n\n static CompatibilityStatuses = {\n UNKNOWN: \"unknown\",\n PARTIALLY_COMPATIBLE: \"partially-compatible\",\n FULLY_COMPATIBLE: \"fully-compatible\",\n } as const;\n\n static StudioIssues = {\n ISSUE_ACTIVITY: \"ACTIVITY\",\n ISSUE_AGENT: \"AGENT\",\n ISSUE_FAVORITES: \"FAVORITES\",\n ISSUE_URL_SYNCING: \"URL_SYNCING\",\n ISSUE_UI_ADJUSTMENT: \"UI_ADJUSTMENT\",\n ISSUE_CONTENT_MAPPING: \"CONTENT_MAPPING\",\n ISSUE_LOGIN: \"LOGIN\",\n ISSUE_MANIFEST: \"MANIFEST\",\n } as const;\n\n static Features = [\n {\n id: StudioApplication.StudioIssues.ISSUE_AGENT,\n version: \"5.1.0\",\n },\n {\n id: StudioApplication.StudioIssues.ISSUE_FAVORITES,\n version: \"3.88.1\",\n },\n {\n id: StudioApplication.StudioIssues.ISSUE_ACTIVITY,\n version: \"3.88.1\",\n },\n {\n id: StudioApplication.StudioIssues.ISSUE_URL_SYNCING,\n version: \"3.75.0\",\n },\n {\n id: StudioApplication.StudioIssues.ISSUE_UI_ADJUSTMENT,\n version: \"3.78.1\",\n },\n {\n id: StudioApplication.StudioIssues.ISSUE_CONTENT_MAPPING,\n version: \"3.68.0\",\n },\n {\n id: StudioApplication.StudioIssues.ISSUE_LOGIN,\n version: \"2.28.0\",\n },\n ] satisfies StudioIssues;\n\n static MinimumStudioVersion = \"2.28.0\" as const;\n\n static MinimumStudioVersionWithNoIssues = rsort(\n StudioApplication.Features.map((feature) => feature.version),\n ).at(0);\n}\n\ntype CompatibilityStatus =\n (typeof StudioApplication.CompatibilityStatuses)[keyof typeof StudioApplication.CompatibilityStatuses];\n\ntype StudioDashboardIssue =\n (typeof StudioApplication.StudioIssues)[keyof typeof StudioApplication.StudioIssues];\n\ntype StudioIssues = Array<{\n id: StudioDashboardIssue;\n version?: string;\n}>;\n\ntype Workspace = Omit<WorkspaceManifest, \"dataset\" | \"schema\" | \"projectId\"> & {\n projectId: ProjectId;\n dataset?: string;\n schema?: string;\n};\n\n/**\n * @internal\n */\nexport class StudioWorkspace extends AbstractApplication<\n \"workspace\",\n ProtocolStudioResource\n> {\n /**\n * Workspaces always belong to a studio application.\n * They do not exist on their own & therefore can access\n * information about the studio they're in via this property.\n */\n private readonly studioApplication: StudioApplication;\n private readonly workspace: Workspace;\n readonly project: Project<false, false>;\n private readonly isDefaultWorkspace: boolean;\n\n constructor(\n studioApplication: StudioApplication,\n workspace: Workspace,\n project: Project<false, false>,\n isDefaultWorkspace: boolean,\n ) {\n super(\"workspace\");\n\n this.studioApplication = studioApplication;\n this.workspace = workspace;\n this.project = project;\n this.isDefaultWorkspace = isDefaultWorkspace;\n }\n\n /**\n * The studio application that this workspace belongs to.\n */\n get studio() {\n return this.studioApplication;\n }\n\n get id() {\n return StudioWorkspace.makeId(this.studio.id, this.workspace.name);\n }\n\n get href() {\n return joinUrlPaths(this.studio.href, this.workspace.name);\n }\n\n get title() {\n /**\n * If there's no manifest we will have created a single workspace for the application.\n * In this circumstance we won't have a meaningful title, so instead we use the hostname of the appHost.\n */\n if (this.isDefaultWorkspace) {\n return this.project.displayName;\n }\n\n return this.workspace.title;\n }\n\n get subtitle() {\n if (this.isDefaultWorkspace) {\n const isValidAppHost = URL.canParse(this.studio.get(\"appHost\"));\n const url = isValidAppHost\n ? new URL(this.studio.get(\"appHost\"))\n : this.studio.url;\n\n return url.hostname;\n }\n\n return this.get(\"subtitle\");\n }\n\n get<TKey extends Exclude<keyof Workspace, \"id\" | \"icon\" | \"title\">>(\n attr: TKey,\n ): Workspace[TKey] {\n return this.workspace[attr];\n }\n\n /**\n * With comlink, studio-applications were not considered applications at all, only workspaces. This is partially why\n * we create default workspaces when the application has no manifest or the manifest has no workspaces.\n *\n * Thereby, to create it we depend on a lot of information from the parent application even if it's duplicated across\n * different workspaces.\n */\n toProtocolResource(): ProtocolStudioResource {\n return {\n ...this.workspace,\n type: \"studio\",\n userApplicationId: this.studio.id,\n activeDeployment: this.studio.get(\"activeDeployment\"),\n autoUpdatingVersion: this.studio.get(\"autoUpdatingVersion\"),\n dashboardStatus: this.studio.get(\"dashboardStatus\"),\n url: this.studio.url.toString(),\n href: this.href,\n id: this.id,\n hasManifest: true,\n hasSchema: Boolean(this.workspace.schema),\n manifest: this.studio.get(\"manifestData\")?.value ?? null,\n updatedAt: this.studio.get(\"updatedAt\"),\n version: this.studio.get(\"activeDeployment\")?.version,\n urlType: this.studio.get(\"urlType\"),\n config: this.studio.get(\"config\"),\n } satisfies ProtocolStudioResource;\n }\n\n /**\n * @returns the URL to the workspace of a studio application.\n */\n get url(): URL {\n const studioUrl = new URL(this.studio.url);\n const normalizedUrlPath = normalizePath(studioUrl.pathname);\n\n let finalBasePath = normalizePath(this.get(\"basePath\"));\n\n // the appHost may already contain the basepath for externally hosted studios\n // or embedded studios, so we deduplicate the segments\n if (finalBasePath.startsWith(normalizedUrlPath)) {\n finalBasePath = finalBasePath.slice(normalizedUrlPath.length);\n }\n\n studioUrl.pathname = joinUrlPaths(normalizedUrlPath, finalBasePath);\n\n return studioUrl;\n }\n\n static makeId(applicationId: UserApplicationId, workspaceName: string) {\n return `${applicationId}-${workspaceName}`;\n }\n\n static splitId(id: string): [string, string] {\n return id.split(new RegExp(/-(.*)/)).slice(0, 2) as [string, string];\n }\n}\n"],"names":["ProjectIdSchema","project"],"mappings":";;;AAeO,MAAe,oBAMpB;AAAA,EACS;AAAA,EAET,YAAY,MAAa;AACvB,SAAK,OAAO;AAAA,EACd;AAAA,EAQA,IAAI,WAAmB;AACrB,UAAM,UAAU,sCACV,aAAa,IAAA,OAAC,qBAAiB,GAAC,GAChC,wBAAwB,IAAA,OAAC,yBAAoB,IAAE,GAC/C,aAAa,IAAA,OAAC,a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AAK,OAAO;AAAA,MAC/B,kBAAkB,KAAK,OAAO,IAAI,kBAAkB;AAAA,MACpD,qBAAqB,KAAK,OAAO,IAAI,qBAAqB;AAAA,MAC1D,iBAAiB,KAAK,OAAO,IAAI,iBAAiB;AAAA,MAClD,KAAK,KAAK,OAAO,IAAI,SAAA;AAAA,MACrB,MAAM,KAAK;AAAA,MACX,IAAI,KAAK;AAAA,MACT,aAAa;AAAA,MACb,WAAW,CAAA,CAAQ,KAAK,UAAU;AAAA,MAClC,UAAU,KAAK,OAAO,IAAI,cAAc,GAAG,SAAS;AAAA,MACpD,WAAW,KAAK,OAAO,IAAI,WAAW;AAAA,MACtC,SAAS,KAAK,OAAO,IAAI,kBAAkB,GAAG;AAAA,MAC9C,SAAS,KAAK,OAAO,IAAI,SAAS;AAAA,MAClC,QAAQ,KAAK,OAAO,IAAI,QAAQ;AAAA,IAAA;AAAA,EAEpC;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,MAAW;AACb,UAAM,YAAY,IAAI,IAAI,KAAK,OAAO,GAAG,GACnC,oBAAoB,cAAc,UAAU,QAAQ;AAE1D,QAAI,gBAAgB,cAAc,KAAK,IAAI,UAAU,CAAC;AAItD,WAAI,cAAc,WAAW,iBAAiB,MAC5C,gBAAgB,cAAc,MAAM,kBAAkB,MAAM,IAG9D,UAAU,WAAW,aAAa,mBAAmB,aAAa,GAE3D;AAAA,EACT;AAAA,EAEA,OAAO,OAAO,eAAkC,eAAuB;AACrE,WAAO,GAAG,aAAa,IAAI,aAAa;AAAA,EAC1C;AAAA,EAEA,OAAO,QAAQ,IAA8B;AAC3C,WAAO,GAAG,MAAM,IAAI,OAAO,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC;AAAA,EACjD;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/workbench",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.7",
4
4
  "description": "Workbench component for the Sanity Content Operating System",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/sanity-io/workbench/packages/@sanity/workbench#readme",
@@ -24,18 +24,24 @@
24
24
  "source": "./src/_exports/_internal.ts",
25
25
  "default": "./dist/_internal.js"
26
26
  },
27
- "./log": {
28
- "source": "./src/_exports/log.ts",
29
- "default": "./dist/log.js"
27
+ "./core": {
28
+ "source": "./src/_exports/core.ts",
29
+ "default": "./dist/core.js"
30
30
  },
31
31
  "./package.json": "./package.json"
32
32
  },
33
33
  "dependencies": {
34
- "@sanity/federation": "0.1.0-alpha.4"
34
+ "@sanity/message-protocol": "^0.23.0",
35
+ "rxjs": "^7.8.2",
36
+ "semver": "^7.7.4",
37
+ "zod": "^4.3.6",
38
+ "@sanity/federation": "0.1.0-alpha.5"
35
39
  },
36
40
  "devDependencies": {
37
41
  "@sanity/pkg-utils": "^9.2.3",
42
+ "@types/semver": "^7.7.1",
38
43
  "typescript": "^6.0.2",
44
+ "vite": "^7.3.1",
39
45
  "@repo/oxc-config": "0.0.0",
40
46
  "@repo/tsconfig": "0.0.1"
41
47
  },
@@ -0,0 +1 @@
1
+ export * from "../core";
@@ -1,2 +1,3 @@
1
1
  export { renderWorkbench } from "./render";
2
- export type { Config, RenderWorkbenchOptions } from "./render";
2
+ export type { Config } from "../core/config";
3
+ export type { RenderWorkbenchOptions } from "./render";
@@ -1,8 +1,20 @@
1
- import { describe, expect, it } from "vitest";
1
+ import { BehaviorSubject } from "rxjs";
2
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
3
 
3
4
  import { renderWorkbench } from "./render";
4
5
 
6
+ const mockLoadRemote = vi.fn();
7
+
8
+ vi.mock("@sanity/federation/runtime", () => ({
9
+ createInstance: () => ({ loadRemote: mockLoadRemote }),
10
+ }));
11
+
5
12
  describe("renderWorkbench", () => {
13
+ afterEach(() => {
14
+ vi.unstubAllEnvs();
15
+ vi.restoreAllMocks();
16
+ });
17
+
6
18
  it("throws when rootElement is missing", async () => {
7
19
  await expect(
8
20
  renderWorkbench(null as unknown as HTMLElement),
@@ -15,4 +27,47 @@ describe("renderWorkbench", () => {
15
27
  "SANITY_INTERNAL_WORKBENCH_REMOTE_URL is not set",
16
28
  );
17
29
  });
30
+
31
+ it("throws when remote module is null", async () => {
32
+ vi.stubEnv("SANITY_INTERNAL_WORKBENCH_REMOTE_URL", "http://localhost:3001");
33
+ mockLoadRemote.mockResolvedValue(null);
34
+
35
+ const el = document.createElement("div");
36
+ await expect(renderWorkbench(el)).rejects.toThrow(
37
+ 'Remote module "workbench-remote/App" did not expose a render function',
38
+ );
39
+ });
40
+
41
+ it("throws when remote module does not expose a render function", async () => {
42
+ vi.stubEnv("SANITY_INTERNAL_WORKBENCH_REMOTE_URL", "http://localhost:3001");
43
+ mockLoadRemote.mockResolvedValue({ notRender: true });
44
+
45
+ const el = document.createElement("div");
46
+ await expect(renderWorkbench(el)).rejects.toThrow(
47
+ 'Remote module "workbench-remote/App" did not expose a render function',
48
+ );
49
+ });
50
+
51
+ it("calls render on the remote module and returns the cleanup function", async () => {
52
+ vi.stubEnv("SANITY_INTERNAL_WORKBENCH_REMOTE_URL", "http://localhost:3001");
53
+ const cleanup = vi.fn();
54
+ const render = vi.fn().mockReturnValue(cleanup);
55
+ mockLoadRemote.mockResolvedValue({ render });
56
+
57
+ const el = document.createElement("div");
58
+ const config = {};
59
+ const options = { reactStrictMode: true };
60
+
61
+ const result = await renderWorkbench(el, config, options);
62
+
63
+ expect(render).toHaveBeenCalledWith(
64
+ el,
65
+ { config, localApplications: expect.any(BehaviorSubject) },
66
+ options,
67
+ );
68
+
69
+ expect(result).toBeTypeOf("function");
70
+ result();
71
+ expect(cleanup).toHaveBeenCalled();
72
+ });
18
73
  });
@@ -1,32 +1,24 @@
1
+ /// <reference types="vite/client" />
2
+
1
3
  import { createInstance } from "@sanity/federation/runtime";
2
4
  import { log } from "@sanity/federation/runtime/plugins/log";
3
- import { createLogger } from "../log";
5
+ import { BehaviorSubject, type Observable } from "rxjs";
6
+
7
+ import type { LocalApplicationData } from "../core/applications/local-application";
8
+ import type { Config, RemoteModuleRenderOptions } from "../core/config";
9
+ import { createLogger } from "../core/log";
4
10
 
5
11
  const logger = createLogger({
6
12
  namespace: "sanity-workbench",
7
13
  logLevel: "debug",
8
14
  });
9
15
 
10
- /**
11
- * Workbench configuration.
12
- *
13
- * @public
14
- */
15
- export type Config = {
16
- /**
17
- * The organization ID to use when rendering the workbench.
18
- */
19
- organizationId: string | undefined;
20
- };
21
-
22
16
  /**
23
17
  * Options for rendering the workbench.
24
18
  *
25
19
  * @public
26
20
  */
27
- export interface RenderWorkbenchOptions {
28
- reactStrictMode?: boolean;
29
- }
21
+ export interface RenderWorkbenchOptions extends RemoteModuleRenderOptions {}
30
22
 
31
23
  declare global {
32
24
  interface ImportMetaEnv {
@@ -37,23 +29,30 @@ declare global {
37
29
  }
38
30
  }
39
31
 
32
+ type RemoteModule<TProps extends any> = {
33
+ render: (
34
+ rootElement: HTMLElement,
35
+ props: TProps,
36
+ options?: RenderWorkbenchOptions,
37
+ ) => () => void;
38
+ };
39
+
40
40
  /**
41
41
  * Module defining the remote workbench application.
42
42
  *
43
43
  * @internal
44
44
  */
45
- interface WorkbenchRemoteModule {
46
- setup: (
47
- config?: Config,
48
- options?: RenderWorkbenchOptions,
49
- ) => {
50
- render(rootElement: HTMLElement): () => void;
51
- };
52
- }
45
+ type WorkbenchRemoteModule = RemoteModule<{
46
+ config?: Config;
47
+ localApplications?: Observable<LocalApplicationData[]>;
48
+ }>;
53
49
 
54
50
  const REMOTE_NAME = "workbench-remote";
55
51
  const REMOTE_MODULE = "App";
56
52
 
53
+ const LOCAL_APPS_HMR_EVENT = "sanity:workbench:local-applications";
54
+ const LOCAL_APPS_HMR_REQUEST = "sanity:workbench:get-local-applications";
55
+
57
56
  /**
58
57
  * Creates a Module Federation instance, loads a remote workbench
59
58
  * application, and renders it into the provided root element.
@@ -96,13 +95,38 @@ export async function renderWorkbench(
96
95
  `${REMOTE_NAME}/${REMOTE_MODULE}`,
97
96
  );
98
97
 
99
- if (!remoteModule || typeof remoteModule.setup !== "function") {
98
+ if (!remoteModule || typeof remoteModule.render !== "function") {
100
99
  throw new Error(
101
- `Remote module "${REMOTE_NAME}/${REMOTE_MODULE}" did not expose a setup function`,
100
+ `Remote module "${REMOTE_NAME}/${REMOTE_MODULE}" did not expose a render function`,
102
101
  );
103
102
  }
104
103
 
105
- const instance = remoteModule.setup(config, options);
104
+ let localApplications = undefined;
105
+ let cleanupHmr = () => {};
106
+
107
+ if (import.meta.hot) {
108
+ const localApps$ = new BehaviorSubject<LocalApplicationData[]>([]);
109
+
110
+ const handler = (payload: { applications: LocalApplicationData[] }) => {
111
+ localApps$.next(payload.applications);
112
+ };
113
+
114
+ import.meta.hot.on(LOCAL_APPS_HMR_EVENT, handler);
115
+ import.meta.hot.send(LOCAL_APPS_HMR_REQUEST);
116
+
117
+ localApplications = localApps$;
118
+
119
+ cleanupHmr = () => import.meta.hot?.off(LOCAL_APPS_HMR_EVENT, handler);
120
+ }
121
+
122
+ const unmount = remoteModule.render(
123
+ rootElement,
124
+ { config, localApplications },
125
+ options,
126
+ );
106
127
 
107
- return instance.render(rootElement);
128
+ return () => {
129
+ cleanupHmr();
130
+ unmount();
131
+ };
108
132
  }