// TEMPORARY: remove after brett migration (SDK-1909). // // Parses the legacy `/user-applications` responses so demo orgs stay populated // while brett's `/applications` + `/installations` roll out. The shapes are the // pre-migration workbench schemas, copied verbatim so this module is // self-contained and deletes cleanly once the endpoint is gone. import { z } from "zod"; import { ApplicationId } from "../applications/brett-applications"; import { OrganizationId } from "../organizations"; import { ProjectId } from "../projects"; const UserWorkspace = z.object({ name: z.string(), title: z.string(), subtitle: z.string().optional(), basePath: z.string(), projectId: ProjectId, dataset: z.string().optional(), icon: z.string().nullable().optional(), }); const UserServerManifest = z.object({ buildId: z.string().optional(), bundleVersion: z.string().optional(), version: z.string().optional(), group: z.string().optional(), priority: z.number().optional(), workspaces: z .array( UserWorkspace.extend({ dataset: z.string(), schemaDescriptorId: z.string(), }), ) .optional(), }); /** @internal */ export type UserServerManifest = z.output; const UserClientManifest = z.object({ version: z.number(), createdAt: z.string(), studioVersion: z.string().optional(), group: z.string().optional(), priority: z.number().optional(), workspaces: z.array( UserWorkspace.extend({ schema: z.string(), tools: z.string().optional(), }), ), }); /** @internal */ export type UserClientManifest = z.output; const UserCoreApplicationManifest = z.object({ version: z.string(), icon: z.string().optional(), title: z.string().optional(), group: z.string().optional(), priority: z.number().optional(), }); const UserApplicationBase = z.object({ id: ApplicationId, appHost: z.string(), urlType: z.enum(["internal", "external"]), createdAt: z.string(), updatedAt: z.string(), dashboardStatus: z.enum(["default", "disabled"]), }); const UserActiveDeployment = z.object({ id: z.string(), version: z.string(), isActiveDeployment: z.boolean(), userApplicationId: z.string(), isAutoUpdating: z.boolean().nullable(), size: z.number().nullable(), deployedAt: z.string(), deployedBy: z.string(), createdAt: z.string(), updatedAt: z.string(), }); const UserStudioBase = UserApplicationBase.extend({ title: z.string().nullable(), projectId: ProjectId, type: z.literal("studio"), manifest: UserClientManifest.nullable(), manifestData: z.object({ value: UserClientManifest }).nullable(), autoUpdatingVersion: z.string().nullable(), config: z.object({ "live-manifest": z .object({ createdAt: z.string(), updatedAt: z.string(), updatedBy: z.string(), value: UserServerManifest, }) .optional(), }), }); const UserStudioDeployment = UserActiveDeployment.extend({ manifest: UserServerManifest.nullable(), }).nullable(); const UserStudio = z.discriminatedUnion("urlType", [ UserStudioBase.extend({ urlType: z.literal("internal"), activeDeployment: UserStudioDeployment, }), UserStudioBase.extend({ urlType: z.literal("external"), activeDeployment: UserStudioDeployment, }), ]); /** @internal */ export type UserStudio = z.output; const UserCoreBase = UserApplicationBase.extend({ title: z.string(), organizationId: OrganizationId, type: z.literal("coreApp"), }); const UserCoreDeployment = UserActiveDeployment.extend({ manifest: UserCoreApplicationManifest.nullable(), }).nullable(); const UserCoreApp = z.discriminatedUnion("urlType", [ UserCoreBase.extend({ urlType: z.literal("internal"), activeDeployment: UserCoreDeployment, }), UserCoreBase.extend({ urlType: z.literal("external"), activeDeployment: UserCoreDeployment, }), ]); /** @internal */ export type UserCoreApp = z.output; export function parseUserStudio(data: unknown): UserStudio { return UserStudio.parse(data); } export function parseUserCoreApp(data: unknown): UserCoreApp { return UserCoreApp.parse(data); }