@sanity/workbench 0.1.0-alpha.11 → 0.1.0-alpha.13
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.
- package/dist/_chunks-es/index.js +6 -1
- package/dist/_chunks-es/index.js.map +1 -1
- package/dist/_chunks-es/studio.js +798 -0
- package/dist/_chunks-es/studio.js.map +1 -0
- package/dist/core.d.ts +135 -35
- package/dist/core.js +3 -722
- package/dist/core.js.map +1 -1
- package/dist/system.d.ts +456 -0
- package/dist/system.js +436 -0
- package/dist/system.js.map +1 -0
- package/package.json +12 -1
- package/src/_exports/system.ts +1 -0
- package/src/core/log/index.ts +33 -0
- package/src/core/projects.ts +1 -1
- package/src/core/user-applications/core-app.ts +19 -6
- package/src/core/user-applications/studios/schemas.ts +12 -1
- package/src/core/user-applications/studios/studio.ts +92 -77
- package/src/core/user-applications/studios/workspace.ts +5 -0
- package/src/core/user-applications/user-application.ts +24 -1
- package/src/system/auth.machine.ts +223 -0
- package/src/system/index.ts +6 -0
- package/src/system/inspect.ts +40 -0
- package/src/system/root.machine.ts +165 -0
- package/src/system/telemetry.machine.ts +179 -0
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sources":["../src/core/applications/application.ts","../src/core/applications/application-list.ts","../src/core/env.ts","../src/core/organizations.ts","../src/core/canvases.ts","../src/core/media-libraries.ts","../src/core/projects.ts","../src/core/shared/urls.ts","../src/core/user-applications/user-application.ts","../src/core/user-applications/core-app.ts","../src/core/user-applications/studios/schemas.ts","../src/core/user-applications/studios/workspace.ts","../src/core/user-applications/studios/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 /**\n * Whether the application is federated or not. This is used to determine\n * if the application should be rendered in an iframe or not.\n */\n abstract get isFederated(): boolean;\n\n /**\n * Whether the application is served by a local CLI dev server rather than a\n * deployed remote. Defaults to `false`; user applications flip this when\n * constructed from a `LocalUserApplication` payload.\n */\n get isLocal(): boolean {\n return false;\n }\n\n abstract get url(): URL;\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 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/studios\";\nimport type { UserApplicationId } from \"../user-applications/user-application\";\n\n/**\n * @public\n */\nexport type Application =\n | CoreAppApplication\n | StudioApplication\n | StudioWorkspace\n | CanvasApplication\n | MediaLibraryApplication;\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.isLocal) 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","declare const __SANITY_STAGING__: boolean | undefined;\n\n/**\n * Returns the Sanity domain based on the `__SANITY_STAGING__` runtime-time flag.\n * If the flag is set to `true`, the staging domain is returned.\n * Otherwise, the production domain is returned.\n *\n * @public\n */\nexport function getSanityDomain(): string {\n if (getSanityEnv() === \"staging\") {\n return \"sanity.work\";\n }\n return \"sanity.io\";\n}\n\n/**\n * Returns the API host based on the `__SANITY_STAGING__` runtime-time flag.\n * If the flag is set to `true`, the staging API host is returned.\n * Otherwise, the production API host is returned.\n *\n * @public\n */\nexport function getApiHost(): string | undefined {\n return `https://api.${getSanityDomain()}`;\n}\n\n/**\n * Returns the current Sanity environment based on the `__SANITY_STAGING__` runtime-time flag.\n * If the flag is set to `true`, \"staging\" is returned.\n * Otherwise, \"production\" is returned.\n *\n * @public\n */\nexport function getSanityEnv(): \"staging\" | \"production\" {\n if (\n typeof __SANITY_STAGING__ !== \"undefined\" &&\n __SANITY_STAGING__ === true\n ) {\n return \"staging\";\n }\n return \"production\";\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 { getSanityDomain } from \"./env\";\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 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 get url(): URL {\n return new URL(\n `https://canvas.${getSanityDomain()}/o/${this.canvas.organizationId}`,\n );\n }\n\n get isFederated(): boolean {\n return false;\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 { getSanityDomain } from \"./env\";\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 */\nexport class MediaLibraryApplication extends AbstractApplication<\"media-library\"> {\n 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 get isFederated(): boolean {\n return false;\n }\n\n get url(): URL {\n return new URL(\n `https://media.${getSanityDomain()}/${this.library.organizationId}`,\n );\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","/**\n * Joins multiple path segments into a single path string.\n * Handles null, undefined, and URL objects gracefully.\n *\n * @public\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","// eslint-disable-next-line no-restricted-imports\nimport type { Resource as ProtocolResource } from \"@sanity/message-protocol\";\nimport { z } from \"zod\";\n\nimport {\n AbstractApplication,\n type AbstractApplicationType,\n} from \"../applications/application\";\nimport { getSanityDomain, getSanityEnv } from \"../env\";\nimport type { CoreAppUserApplicationManifest } from \"./core-app\";\nimport type { ClientManifest } from \"./studios/schemas\";\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\nconst LocalUserApplicationBase = z.object({\n host: z.string(),\n port: z.number(),\n /** The `deployment.appId` from the application's `sanity.cli.ts`, when set. */\n id: z.string().optional(),\n});\n\n/**\n * Raw data for a local application discovered by the CLI dev server.\n *\n * The CLI forwards the full studio or app manifest so the workbench can\n * derive icons, titles, workspaces and schema references the same way it\n * does for deployed applications. The manifest shape is discriminated on\n * `type`: studios receive a `ClientManifest`, core apps a `CoreAppUserApplicationManifest`.\n *\n * When set on a `UserApplication`, `isLocal` is `true` and `url`/`isFederated`\n * honour the local dev-server instead of the deployed application's host.\n *\n * @public\n */\nexport const LocalUserApplication = z.discriminatedUnion(\"type\", [\n LocalUserApplicationBase.extend({\n type: z.literal(\"studio\"),\n manifest: z.custom<ClientManifest>().optional(),\n }),\n LocalUserApplicationBase.extend({\n type: z.literal(\"coreApp\"),\n manifest: z.custom<CoreAppUserApplicationManifest>().optional(),\n }),\n]);\n\n/**\n * @public\n */\nexport type LocalUserApplication = z.output<typeof LocalUserApplication>;\n\n/**\n * @public\n */\nexport const UserApplicationBase = z.object({\n id: UserApplicationId,\n appHost: z.string(),\n urlType: z.enum([\"internal\", \"external\"]),\n createdAt: z.string(),\n updatedAt: z.string(),\n dashboardStatus: z.enum([\"default\", \"disabled\"]),\n});\n\n/**\n * @public\n */\nexport type UserApplicationBase = z.output<typeof UserApplicationBase>;\n\n/**\n * @public\n */\nexport const ActiveDeployment = z.object({\n id: z.string(),\n version: z.string(),\n isActiveDeployment: z.boolean(),\n userApplicationId: z.string(),\n isAutoUpdating: z.boolean(),\n size: z.number(),\n deployedAt: z.string(),\n deployedBy: z.string(),\n createdAt: z.string(),\n updatedAt: z.string(),\n});\n\n/**\n * @public\n */\nexport abstract class UserApplication<\n TUserApplication extends UserApplicationBase,\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 /**\n * For local applications (`isLocal === true`), the deployed application\n * that shares the same `id` — if one was passed at construction. `null`\n * for deployed applications or when no remote twin was provided.\n */\n readonly remoteApplication: this | null;\n\n readonly #isLocal: boolean;\n\n constructor(\n application: TUserApplication,\n type: TType,\n options: {\n isLocal?: boolean;\n remoteApplication?: UserApplication<\n TUserApplication,\n TType,\n TProtocolResource\n > | null;\n } = {},\n ) {\n super(type);\n this.application = application;\n this.id = brandUserApplicationId(application.id);\n this.#isLocal = options.isLocal ?? false;\n this.remoteApplication =\n (options.remoteApplication as this | undefined) ?? null;\n }\n\n abstract get subtitle(): string | undefined;\n\n /**\n * Local dev servers are rendered as federated remotes; deployed applications\n * are rendered in an iframe.\n */\n get isFederated(): boolean {\n return this.isLocal;\n }\n\n override get isLocal(): boolean {\n return this.#isLocal;\n }\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 (including local dev servers), returns the\n * provided app host as a URL.\n */\n get url(): URL {\n if (this.application.urlType === \"internal\") {\n if (getSanityEnv() === \"production\") {\n return new URL(`https://${this.application.appHost}.sanity.studio`);\n }\n return new URL(\n `https://${this.application.appHost}.studio.${getSanityDomain()}`,\n );\n }\n\n return new URL(this.application.appHost);\n }\n}\n","// eslint-disable-next-line no-restricted-imports\nimport type { ApplicationResource as ProtocolApplicationResource } from \"@sanity/message-protocol\";\nimport { z } from \"zod\";\n\nimport { OrganizationId } from \"../organizations\";\nimport {\n UserApplication,\n UserApplicationBase,\n ActiveDeployment,\n} from \"./user-application\";\n\n/**\n * @public\n */\nexport const CoreAppUserApplicationManifest = z.object({\n version: z.string(),\n icon: z.string().optional(),\n title: z.string().optional(),\n});\n\n/**\n * @public\n */\nexport type CoreAppUserApplicationManifest = z.output<\n typeof CoreAppUserApplicationManifest\n>;\n\nconst CoreAppUserApplicationBase = UserApplicationBase.extend({\n title: z.string(),\n organizationId: OrganizationId,\n type: z.literal(\"coreApp\"),\n manifest: CoreAppUserApplicationManifest.nullable().optional(),\n});\n\nconst InternalCoreAppUserApplication = CoreAppUserApplicationBase.extend({\n urlType: z.literal(\"internal\"),\n activeDeployment: ActiveDeployment.extend({\n manifest: CoreAppUserApplicationManifest.nullable().optional(),\n }).nullable(),\n});\n\nconst ExternalCoreAppUserApplication = CoreAppUserApplicationBase.extend({\n urlType: z.literal(\"external\"),\n activeDeployment: z.null(),\n});\n\n/**\n * Core application schema — validates and brands API\n * responses from the `/user-applications?appType=coreApp`\n * endpoint. Uses a discriminated union on `urlType`.\n * @public\n */\nconst CoreAppUserApplication = z.discriminatedUnion(\"urlType\", [\n InternalCoreAppUserApplication,\n ExternalCoreAppUserApplication,\n]);\n\n/**\n * @public\n */\nexport type CoreAppUserApplication = z.output<typeof CoreAppUserApplication>;\n\n/**\n * Validates and parses a raw API response into a branded\n * CoreAppUserApplicationData.\n * @public\n */\nexport function parseCoreApplication(data: unknown): CoreAppUserApplication {\n return CoreAppUserApplication.parse(data);\n}\n\n/**\n * @public\n */\nexport class CoreAppApplication extends UserApplication<\n CoreAppUserApplication,\n \"coreApp\",\n ProtocolApplicationResource\n> {\n readonly activeDeployment: CoreAppUserApplication[\"activeDeployment\"];\n\n constructor(\n application: CoreAppUserApplication,\n options: {\n isLocal?: boolean;\n remoteApplication?: CoreAppApplication | null;\n } = {},\n ) {\n super(application, \"coreApp\", options);\n\n this.activeDeployment = application.activeDeployment;\n }\n\n get href() {\n return this.isLocal\n ? `/local/${this.id}`\n : `/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 CoreAppUserApplication>(\n attr: TKey,\n ): CoreAppUserApplication[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 } as ProtocolApplicationResource;\n }\n}\n","import { z } from \"zod\";\n\nimport { ProjectId } from \"../../projects\";\nimport { ActiveDeployment, UserApplicationBase } from \"../user-application\";\n\nconst Workspace = z.object({\n name: z.string(),\n title: z.string(),\n subtitle: z.string().optional(),\n basePath: z.string(),\n projectId: ProjectId,\n dataset: z.string().optional(),\n icon: z.string().nullable().optional(),\n});\n\n/**\n * @public\n */\nexport type Workspace = z.output<typeof Workspace>;\n\nconst ServerManifest = z.object({\n buildId: z.string().optional(),\n bundleVersion: z.string().optional(),\n version: z.string().optional(),\n workspaces: z\n .array(\n Workspace.extend({\n dataset: z.string(),\n schemaDescriptorId: z.string(),\n }),\n )\n .optional(),\n});\n\n/**\n * @public\n */\nexport const ClientManifest = z.object({\n version: z.number(),\n createdAt: z.string(),\n studioVersion: z.string().optional(),\n workspaces: z.array(\n Workspace.extend({\n schema: z.string(),\n tools: z.string().optional(),\n }),\n ),\n});\n\n/**\n * @public\n */\nexport type ClientManifest = z.output<typeof ClientManifest>;\n\nconst StudioUserApplicationBase = UserApplicationBase.extend({\n title: z.string().nullable(),\n projectId: ProjectId,\n type: z.literal(\"studio\"),\n manifest: ClientManifest.nullable(),\n manifestData: z.object({ value: ClientManifest }).nullable(),\n autoUpdatingVersion: z.string().nullable(),\n config: z.object({\n \"live-manifest\": z\n .object({\n createdAt: z.string(),\n updatedAt: z.string(),\n updatedBy: z.string(),\n value: ServerManifest,\n })\n .optional(),\n }),\n});\n\nconst InternalStudioUserApplication = StudioUserApplicationBase.extend({\n urlType: z.literal(\"internal\"),\n activeDeployment: ActiveDeployment.extend({\n manifest: ServerManifest.nullable(),\n }),\n});\n\nconst ExternalStudioUserApplication = StudioUserApplicationBase.extend({\n urlType: z.literal(\"external\"),\n activeDeployment: z.null(),\n});\n\n/**\n * Studio user application schema — validates and brands API\n * responses from the `/user-applications?appType=studio`\n * endpoint. Uses a discriminated union on `urlType`.\n * @public\n */\nexport const StudioUserApplication = z.discriminatedUnion(\"urlType\", [\n InternalStudioUserApplication,\n ExternalStudioUserApplication,\n]);\n\n/**\n * @public\n */\nexport type StudioUserApplication = z.output<typeof StudioUserApplication>;\n\n/**\n * Validates and parses a raw API response into a branded\n * StudioUserApplication.\n * @public\n */\nexport function parseStudioUserApplication(\n data: unknown,\n): StudioUserApplication {\n return StudioUserApplication.parse(data);\n}\n","import type { StudioResource as ProtocolStudioResource } from \"@sanity/message-protocol\";\n\nimport { AbstractApplication } from \"../../applications/application\";\nimport type { Project } from \"../../projects\";\nimport { joinUrlPaths, normalizePath } from \"../../shared/urls\";\nimport type { UserApplicationId } from \"../user-application\";\nimport type { Workspace } from \"./schemas\";\nimport type { StudioApplication } from \"./studio\";\n\n/**\n * @public\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 get isFederated() {\n return this.studio.isFederated;\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(\"schema\" in this.workspace && this.workspace.schema),\n manifest: (this.studio.get(\"manifestData\")?.value ??\n null) as ProtocolStudioResource[\"manifest\"],\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","import type { SemVer } from \"semver\";\nimport { coerce, gt, gte, lt, rsort, valid } from \"semver\";\n\nimport type { Project } from \"../../projects\";\nimport { UserApplication } from \"../user-application\";\nimport {\n type Workspace,\n type StudioUserApplication,\n ClientManifest as ClientManifestSchema,\n} from \"./schemas\";\nimport { StudioWorkspace } from \"./workspace\";\n\nconst ClientManifest = ClientManifestSchema.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 Omit<Workspace, \"projectId\">;\n\n/**\n * @public\n */\nexport class StudioApplication extends UserApplication<\n StudioUserApplication,\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 * The projects actually referenced by this studio — the application's own\n * project plus any project used by a workspace. Preserved so the instance\n * can be re-constructed (e.g. by dock wrappers) without having to thread\n * the full organization project list through again.\n */\n readonly projects: 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: StudioUserApplication,\n projects: Project<false, false>[],\n options: {\n isLocal?: boolean;\n remoteApplication?: StudioApplication | null;\n } = {},\n ) {\n super(application, \"studio\", options);\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 = ClientManifest.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;\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 project = projects.find((p) => p.id === application.projectId);\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: application.projectId,\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 // Collect only the projects actually referenced by this studio — the\n // application's own project plus any project used by a workspace.\n const usedProjects = new Set<Project<false, false>>([project]);\n for (const workspace of this.workspaces) {\n usedProjects.add(workspace.project);\n }\n this.projects = Array.from(usedProjects);\n }\n\n get href() {\n return this.isLocal\n ? `/local/${this.id}`\n : `/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 StudioUserApplication>(\n attr: TKey,\n ): StudioUserApplication[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"],"names":["ClientManifest","ClientManifestSchema","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ACR;"}
|
|
1
|
+
{"version":3,"file":"core.js","sources":["../src/core/applications/application-list.ts"],"sourcesContent":["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/studios\";\nimport type { UserApplicationId } from \"../user-applications/user-application\";\n\n/**\n * @public\n */\nexport type Application =\n | CoreAppApplication\n | StudioApplication\n | StudioWorkspace\n | CanvasApplication\n | MediaLibraryApplication;\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.isLocal) 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"],"names":[],"mappings":";;AAwBO,MAAM,gBAAgE;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA,EAKT,YAAY,cAA8B;AACxC,SAAK,eAAe,CAAC,GAAG,YAAY;AAAA,EACtC;AAAA,EAQA,uBACE,OACgB;AAChB,UAAM,QAAQ,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;AAEnD,WAAO,KAAK,aAAa,OAAO,CAAC,MAAM,MAAM,SAAS,EAAE,IAAI,CAAC;AAAA,EAC/D;AAAA,EAoBA,gBACE,MACA,IAC0B;AAC1B,YAAQ,MAAA;AAAA,MACN,KAAK;AAAA,MACL,KAAK;AACH,eAAO,KAAK,aAAa,KAAK,CAAC,MAAM,EAAE,SAAS,IAAI;AAAA,MACtD,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AACH,eAAO,KAAK,aAAa,KAAK,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,OAAO,EAAE;AAAA,IAAA;AAAA,EAGzE;AAAA,EAEA,sBAAsB;AACpB,WAAO,KAAK,aAAa,OAA2B,CAAC,KAAK,MACpD,EAAE,SAAS,YAAY,EAAE,UAAgB,MACtC,CAAC,GAAG,KAAK,EAAE,oBAAoB,GACrC,EAAE;AAAA,EACP;AAAA,EAEA,OAAO,qBACL,cACA,cACS;AACT,WACE,CAAC,gBACD,CAAC,gBACD,aAAa,SAAS,aAAa,OAE5B,KAGF,aAAa,OAAO,aAAa;AAAA,EAC1C;AACF;"}
|
package/dist/system.d.ts
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import { ActorRefFromLogic } from "xstate";
|
|
2
|
+
import { AuthState } from "@sanity/sdk";
|
|
3
|
+
import { AuthStateType } from "@sanity/sdk";
|
|
4
|
+
import { ConsentStatus } from "@sanity/telemetry";
|
|
5
|
+
import { CurrentUser } from "@sanity/sdk";
|
|
6
|
+
import { EventObject } from "xstate";
|
|
7
|
+
import { InspectionEvent } from "xstate";
|
|
8
|
+
import { MetaObject } from "xstate";
|
|
9
|
+
import { NonReducibleUnknown } from "xstate";
|
|
10
|
+
import { ObservableActorLogic } from "xstate";
|
|
11
|
+
import { PromiseActorLogic } from "xstate";
|
|
12
|
+
import { SanityInstance } from "@sanity/sdk";
|
|
13
|
+
import { StateMachine } from "xstate";
|
|
14
|
+
import { TelemetryStore } from "@sanity/telemetry";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare interface AuthInput extends OSBaseInput {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates a set of default options for the OS machine, including passing
|
|
23
|
+
* the sanity configuration for the internal instance.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare function createOSOptions(input: OSInput): {
|
|
27
|
+
id: string;
|
|
28
|
+
input: WorkbenchUserProperties;
|
|
29
|
+
inspect: (event: InspectionEvent) => void;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export declare interface LogoutInput extends OSBaseInput {}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The sanity OS machine, responsible for managing the global state of the OS.
|
|
39
|
+
* @public
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { os, createOSOptions } from "@sanity/workbench/system";
|
|
43
|
+
* import { useActor } from "@xstate/react";
|
|
44
|
+
*
|
|
45
|
+
* const [state, send] = useActor(os, createOSOptions());
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare const os: StateMachine<
|
|
49
|
+
OSContext,
|
|
50
|
+
| {
|
|
51
|
+
type: "boot.auth.ready";
|
|
52
|
+
}
|
|
53
|
+
| {
|
|
54
|
+
type: "boot.auth.failed";
|
|
55
|
+
}
|
|
56
|
+
| {
|
|
57
|
+
type: "boot.telemetry.ready";
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
telemetry?:
|
|
61
|
+
| ActorRefFromLogic<
|
|
62
|
+
StateMachine<
|
|
63
|
+
{
|
|
64
|
+
instance: SanityInstance;
|
|
65
|
+
store: TelemetryStore<WorkbenchUserProperties> | null;
|
|
66
|
+
userProperties: WorkbenchUserProperties;
|
|
67
|
+
},
|
|
68
|
+
| {
|
|
69
|
+
type: "telemetry.start";
|
|
70
|
+
}
|
|
71
|
+
| {
|
|
72
|
+
type: "telemetry.stop";
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
[x: string]:
|
|
76
|
+
| ActorRefFromLogic<
|
|
77
|
+
PromiseActorLogic<
|
|
78
|
+
{
|
|
79
|
+
status: ConsentStatus;
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
instance: SanityInstance;
|
|
83
|
+
},
|
|
84
|
+
EventObject
|
|
85
|
+
>
|
|
86
|
+
>
|
|
87
|
+
| undefined;
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
src: "checkConsent";
|
|
91
|
+
logic: PromiseActorLogic<
|
|
92
|
+
{
|
|
93
|
+
status: ConsentStatus;
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
instance: SanityInstance;
|
|
97
|
+
},
|
|
98
|
+
EventObject
|
|
99
|
+
>;
|
|
100
|
+
id: string | undefined;
|
|
101
|
+
},
|
|
102
|
+
| {
|
|
103
|
+
type: "createStore";
|
|
104
|
+
params: NonReducibleUnknown;
|
|
105
|
+
}
|
|
106
|
+
| {
|
|
107
|
+
type: "teardownStore";
|
|
108
|
+
params: unknown;
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
type: "isConsentGranted";
|
|
112
|
+
params: {
|
|
113
|
+
status: ConsentStatus;
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
never,
|
|
117
|
+
"active" | "stopped" | "denied" | "idle" | "checkingConsent",
|
|
118
|
+
string,
|
|
119
|
+
TelemetryInput,
|
|
120
|
+
NonReducibleUnknown,
|
|
121
|
+
EventObject,
|
|
122
|
+
MetaObject,
|
|
123
|
+
{
|
|
124
|
+
id: "telemetry";
|
|
125
|
+
states: {
|
|
126
|
+
readonly idle: {};
|
|
127
|
+
readonly checkingConsent: {};
|
|
128
|
+
readonly active: {};
|
|
129
|
+
readonly stopped: {};
|
|
130
|
+
readonly denied: {};
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
>
|
|
134
|
+
>
|
|
135
|
+
| undefined;
|
|
136
|
+
auth?:
|
|
137
|
+
| ActorRefFromLogic<
|
|
138
|
+
StateMachine<
|
|
139
|
+
{
|
|
140
|
+
instance: SanityInstance;
|
|
141
|
+
token: string | null;
|
|
142
|
+
currentUser: CurrentUser | null;
|
|
143
|
+
error: unknown;
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
type: "auth.logout";
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
[x: string]:
|
|
150
|
+
| ActorRefFromLogic<
|
|
151
|
+
ObservableActorLogic<AuthState, AuthInput, EventObject>
|
|
152
|
+
>
|
|
153
|
+
| ActorRefFromLogic<
|
|
154
|
+
PromiseActorLogic<void, LogoutInput, EventObject>
|
|
155
|
+
>
|
|
156
|
+
| undefined;
|
|
157
|
+
},
|
|
158
|
+
| {
|
|
159
|
+
src: "authState";
|
|
160
|
+
logic: ObservableActorLogic<AuthState, AuthInput, EventObject>;
|
|
161
|
+
id: string | undefined;
|
|
162
|
+
}
|
|
163
|
+
| {
|
|
164
|
+
src: "logoutActor";
|
|
165
|
+
logic: PromiseActorLogic<void, LogoutInput, EventObject>;
|
|
166
|
+
id: string | undefined;
|
|
167
|
+
},
|
|
168
|
+
| {
|
|
169
|
+
type: "setLoggedIn";
|
|
170
|
+
params: {
|
|
171
|
+
token: string;
|
|
172
|
+
currentUser: CurrentUser;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
| {
|
|
176
|
+
type: "clearAuth";
|
|
177
|
+
params: NonReducibleUnknown;
|
|
178
|
+
}
|
|
179
|
+
| {
|
|
180
|
+
type: "setError";
|
|
181
|
+
params: {
|
|
182
|
+
error: unknown;
|
|
183
|
+
};
|
|
184
|
+
},
|
|
185
|
+
| {
|
|
186
|
+
type: "isLoggedInComplete";
|
|
187
|
+
params: {
|
|
188
|
+
state: AuthState | undefined;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
| {
|
|
192
|
+
type: "isAuthState";
|
|
193
|
+
params: {
|
|
194
|
+
state: AuthState | undefined;
|
|
195
|
+
type: AuthStateType;
|
|
196
|
+
};
|
|
197
|
+
},
|
|
198
|
+
"authTimeout",
|
|
199
|
+
"init" | AuthStateType | "logging-out",
|
|
200
|
+
"error" | "authenticating" | "authenticated",
|
|
201
|
+
AuthInput,
|
|
202
|
+
NonReducibleUnknown,
|
|
203
|
+
EventObject,
|
|
204
|
+
MetaObject,
|
|
205
|
+
{
|
|
206
|
+
id: "auth";
|
|
207
|
+
states: {
|
|
208
|
+
readonly init: {};
|
|
209
|
+
readonly "logging-in": {};
|
|
210
|
+
readonly "logged-in": {};
|
|
211
|
+
readonly "logging-out": {};
|
|
212
|
+
readonly "logged-out": {};
|
|
213
|
+
readonly error: {};
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
>
|
|
217
|
+
>
|
|
218
|
+
| undefined;
|
|
219
|
+
},
|
|
220
|
+
| {
|
|
221
|
+
src: "telemetry";
|
|
222
|
+
logic: StateMachine<
|
|
223
|
+
{
|
|
224
|
+
instance: SanityInstance;
|
|
225
|
+
store: TelemetryStore<WorkbenchUserProperties> | null;
|
|
226
|
+
userProperties: WorkbenchUserProperties;
|
|
227
|
+
},
|
|
228
|
+
| {
|
|
229
|
+
type: "telemetry.start";
|
|
230
|
+
}
|
|
231
|
+
| {
|
|
232
|
+
type: "telemetry.stop";
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
[x: string]:
|
|
236
|
+
| ActorRefFromLogic<
|
|
237
|
+
PromiseActorLogic<
|
|
238
|
+
{
|
|
239
|
+
status: ConsentStatus;
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
instance: SanityInstance;
|
|
243
|
+
},
|
|
244
|
+
EventObject
|
|
245
|
+
>
|
|
246
|
+
>
|
|
247
|
+
| undefined;
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
src: "checkConsent";
|
|
251
|
+
logic: PromiseActorLogic<
|
|
252
|
+
{
|
|
253
|
+
status: ConsentStatus;
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
instance: SanityInstance;
|
|
257
|
+
},
|
|
258
|
+
EventObject
|
|
259
|
+
>;
|
|
260
|
+
id: string | undefined;
|
|
261
|
+
},
|
|
262
|
+
| {
|
|
263
|
+
type: "createStore";
|
|
264
|
+
params: NonReducibleUnknown;
|
|
265
|
+
}
|
|
266
|
+
| {
|
|
267
|
+
type: "teardownStore";
|
|
268
|
+
params: unknown;
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
type: "isConsentGranted";
|
|
272
|
+
params: {
|
|
273
|
+
status: ConsentStatus;
|
|
274
|
+
};
|
|
275
|
+
},
|
|
276
|
+
never,
|
|
277
|
+
"active" | "stopped" | "denied" | "idle" | "checkingConsent",
|
|
278
|
+
string,
|
|
279
|
+
TelemetryInput,
|
|
280
|
+
NonReducibleUnknown,
|
|
281
|
+
EventObject,
|
|
282
|
+
MetaObject,
|
|
283
|
+
{
|
|
284
|
+
id: "telemetry";
|
|
285
|
+
states: {
|
|
286
|
+
readonly idle: {};
|
|
287
|
+
readonly checkingConsent: {};
|
|
288
|
+
readonly active: {};
|
|
289
|
+
readonly stopped: {};
|
|
290
|
+
readonly denied: {};
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
>;
|
|
294
|
+
id: "telemetry";
|
|
295
|
+
}
|
|
296
|
+
| {
|
|
297
|
+
src: "auth";
|
|
298
|
+
logic: StateMachine<
|
|
299
|
+
{
|
|
300
|
+
instance: SanityInstance;
|
|
301
|
+
token: string | null;
|
|
302
|
+
currentUser: CurrentUser | null;
|
|
303
|
+
error: unknown;
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
type: "auth.logout";
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
[x: string]:
|
|
310
|
+
| ActorRefFromLogic<
|
|
311
|
+
ObservableActorLogic<AuthState, AuthInput, EventObject>
|
|
312
|
+
>
|
|
313
|
+
| ActorRefFromLogic<
|
|
314
|
+
PromiseActorLogic<void, LogoutInput, EventObject>
|
|
315
|
+
>
|
|
316
|
+
| undefined;
|
|
317
|
+
},
|
|
318
|
+
| {
|
|
319
|
+
src: "authState";
|
|
320
|
+
logic: ObservableActorLogic<AuthState, AuthInput, EventObject>;
|
|
321
|
+
id: string | undefined;
|
|
322
|
+
}
|
|
323
|
+
| {
|
|
324
|
+
src: "logoutActor";
|
|
325
|
+
logic: PromiseActorLogic<void, LogoutInput, EventObject>;
|
|
326
|
+
id: string | undefined;
|
|
327
|
+
},
|
|
328
|
+
| {
|
|
329
|
+
type: "setLoggedIn";
|
|
330
|
+
params: {
|
|
331
|
+
token: string;
|
|
332
|
+
currentUser: CurrentUser;
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
| {
|
|
336
|
+
type: "clearAuth";
|
|
337
|
+
params: NonReducibleUnknown;
|
|
338
|
+
}
|
|
339
|
+
| {
|
|
340
|
+
type: "setError";
|
|
341
|
+
params: {
|
|
342
|
+
error: unknown;
|
|
343
|
+
};
|
|
344
|
+
},
|
|
345
|
+
| {
|
|
346
|
+
type: "isLoggedInComplete";
|
|
347
|
+
params: {
|
|
348
|
+
state: AuthState | undefined;
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
| {
|
|
352
|
+
type: "isAuthState";
|
|
353
|
+
params: {
|
|
354
|
+
state: AuthState | undefined;
|
|
355
|
+
type: AuthStateType;
|
|
356
|
+
};
|
|
357
|
+
},
|
|
358
|
+
"authTimeout",
|
|
359
|
+
"init" | AuthStateType | "logging-out",
|
|
360
|
+
"error" | "authenticating" | "authenticated",
|
|
361
|
+
AuthInput,
|
|
362
|
+
NonReducibleUnknown,
|
|
363
|
+
EventObject,
|
|
364
|
+
MetaObject,
|
|
365
|
+
{
|
|
366
|
+
id: "auth";
|
|
367
|
+
states: {
|
|
368
|
+
readonly init: {};
|
|
369
|
+
readonly "logging-in": {};
|
|
370
|
+
readonly "logged-in": {};
|
|
371
|
+
readonly "logging-out": {};
|
|
372
|
+
readonly "logged-out": {};
|
|
373
|
+
readonly error: {};
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
>;
|
|
377
|
+
id: "auth";
|
|
378
|
+
},
|
|
379
|
+
| {
|
|
380
|
+
type: "raiseAuthReady";
|
|
381
|
+
params: NonReducibleUnknown;
|
|
382
|
+
}
|
|
383
|
+
| {
|
|
384
|
+
type: "raiseAuthFailed";
|
|
385
|
+
params: NonReducibleUnknown;
|
|
386
|
+
}
|
|
387
|
+
| {
|
|
388
|
+
type: "raiseTelemetryReady";
|
|
389
|
+
params: NonReducibleUnknown;
|
|
390
|
+
}
|
|
391
|
+
| {
|
|
392
|
+
type: "startTelemetry";
|
|
393
|
+
params: NonReducibleUnknown;
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
type: "hasTag";
|
|
397
|
+
params: {
|
|
398
|
+
hasTag: boolean;
|
|
399
|
+
};
|
|
400
|
+
},
|
|
401
|
+
never,
|
|
402
|
+
| "running"
|
|
403
|
+
| {
|
|
404
|
+
booting: "error" | "done" | "telemetry" | "auth";
|
|
405
|
+
},
|
|
406
|
+
string,
|
|
407
|
+
WorkbenchUserProperties,
|
|
408
|
+
NonReducibleUnknown,
|
|
409
|
+
EventObject,
|
|
410
|
+
MetaObject,
|
|
411
|
+
{
|
|
412
|
+
id: "os";
|
|
413
|
+
states: {
|
|
414
|
+
readonly booting: {
|
|
415
|
+
states: {
|
|
416
|
+
readonly auth: {};
|
|
417
|
+
readonly telemetry: {};
|
|
418
|
+
readonly error: {};
|
|
419
|
+
readonly done: {};
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
readonly running: {};
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
>;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* The base inputs for the OS machine.
|
|
429
|
+
* @internal
|
|
430
|
+
*/
|
|
431
|
+
declare interface OSBaseInput extends Pick<OSContext, "instance"> {}
|
|
432
|
+
|
|
433
|
+
declare type OSContext = {
|
|
434
|
+
instance: SanityInstance;
|
|
435
|
+
userProperties: WorkbenchUserProperties;
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
declare type OSInput = WorkbenchUserProperties;
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* @internal
|
|
442
|
+
*/
|
|
443
|
+
export declare interface TelemetryInput
|
|
444
|
+
extends OSBaseInput, WorkbenchUserProperties {}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* @public
|
|
448
|
+
*/
|
|
449
|
+
export declare type WorkbenchUserProperties = {
|
|
450
|
+
version: string;
|
|
451
|
+
organizationId: string;
|
|
452
|
+
environment: string;
|
|
453
|
+
userAgent: string;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
export {};
|