import {z} from 'zod' export type GetApiV2PortalsPortalIdAppearanceArgs = {portalId: string}; export type GetApiV2PortalsPortalIdAppearanceOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const v2AppearanceColorVariable = z.object({value: z.string().max(255), description: z.string().max(512).nullable().optional()}); export const v2AppearanceThemeColorVariables = z.object({section: z.object({header: v2AppearanceColorVariable, body: v2AppearanceColorVariable, hero: v2AppearanceColorVariable, accent: v2AppearanceColorVariable, tertiary: v2AppearanceColorVariable, stroke: v2AppearanceColorVariable, footer: v2AppearanceColorVariable}), text: z.object({header: v2AppearanceColorVariable, hero: v2AppearanceColorVariable, headings: v2AppearanceColorVariable, primary: v2AppearanceColorVariable, secondary: v2AppearanceColorVariable, accent: v2AppearanceColorVariable, link: v2AppearanceColorVariable, footer: v2AppearanceColorVariable}), button: z.object({primary_fill: v2AppearanceColorVariable, primary_text: v2AppearanceColorVariable})}); export const v2AppearanceFontName = z.enum(["Roboto", "Inter", "Open Sans", "Lato", "Slabo 27px", "Slabo 13px", "Oswald", "Source Sans Pro", "Montserrat", "Raleway", "PT Sans", "Lora", "Roboto Mono", "Inconsolata", "Source Code Pro", "PT Mono", "Ubuntu Mono", "IBM Plex Mono"]); export const portalAppearanceImageDataUri = z.string(); export const v2AppearanceImage = z.object({data: portalAppearanceImageDataUri, filename: z.string().max(512).nullable().optional()}).nullable(); export const v2GetPortalAppearanceResponse = z.object({theme_name: z.enum(["mint_rocket", "dark_mode", "custom"]), custom_theme: z.object({colors: v2AppearanceThemeColorVariables}).nullable(), custom_fonts: z.object({base: v2AppearanceFontName, code: v2AppearanceFontName, headings: v2AppearanceFontName}).nullable(), use_custom_fonts: z.boolean(), text: z.object({catalog: z.object({welcome_message: z.string().max(512), primary_header: z.string().max(512)})}).nullable(), images: z.object({logo: v2AppearanceImage.optional(), favicon: v2AppearanceImage.optional(), catalog_cover: v2AppearanceImage.optional()}).nullable()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Appearance Configuration * * GET /v2/portals/{portalId}/appearance * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV2PortalsPortalIdAppearance = async (args: GetApiV2PortalsPortalIdAppearanceArgs, options?: GetApiV2PortalsPortalIdAppearanceOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/portals/${encodeURIComponent(String(args.portalId))}/appearance${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(v2GetPortalAppearanceResponse, await res.json()) };