import { z } from "zod"; import { AbstractApplication, type AbstractApplicationType, } from "../applications/applications"; import { ApplicationId } from "../applications/brett-applications"; import { OrganizationId } from "../organizations"; import { ActiveConfig } from "./config"; /** * Installation ID schema, branded to keep it distinct from the application id * an installation points at. * @public */ export const InstallationId = z.string().nonempty().brand("InstallationId"); /** * Installation ID type, branded for type safety. * @public */ export type InstallationId = z.output; const InstallationSchema = z.object({ id: InstallationId, applicationId: ApplicationId, organizationId: OrganizationId, application: z.object({ title: z.string(), // Stable identity + qualified handle of the installed singleton. Server-computed // (SDK-2333); the parse below defaults them during rollout. name: z.string(), reference: z.string(), slug: z.string().nullable(), }), access: z.array( z.object({ resourceType: z.string(), resourceId: z.string() }), ), // `null` when requested but nothing is deployed. activeConfig: ActiveConfig.nullable().optional(), }); /** * An organization's active installation of a singleton application, as returned * from `GET /installations?organizationId=&include=activeConfig,access`. * @public */ export type Installation = z.output; /** * Validates and parses a raw `/installations` record into a branded * Installation. * @public */ export function parseInstalledApplication(data: unknown): Installation { return InstallationSchema.parse(data); } /** * @public */ export abstract class InstalledApplication< TType extends AbstractApplicationType, > extends AbstractApplication { readonly id: ApplicationId; readonly organizationId: OrganizationId; readonly slug: string; /** Stable identity of the installed singleton — what config matching keys on. */ readonly name: string; /** Qualified, globally-unique handle of the installed singleton. */ readonly reference: string; constructor({ type, slug, name, reference, id, organizationId, }: { type: TType; slug: string; name: string; reference: string; id: ApplicationId; organizationId: OrganizationId; }) { super(type); this.slug = slug; this.name = name; this.reference = reference; this.id = id; this.organizationId = organizationId; } get isFederated(): boolean { return true; } }