import {z} from 'zod' export type BannerSettingGRADIENT = 'GRADIENT'; export type BannerSettingMINIMAL = 'MINIMAL'; export type ApiSelectableBannerSetting = BannerSettingGRADIENT | BannerSettingMINIMAL; export type UpdateTrustCenterInput = {title?: (string | null) | undefined, companyDescription?: (string | null) | undefined, bannerSetting?: ({endColor?: string | undefined, startColor?: string | undefined, setting: ApiSelectableBannerSetting}) | undefined, customTheme?: ({secondary?: (string | null) | undefined, primary?: (string | null) | undefined}) | undefined, privacyPolicy?: (string | null) | undefined, awsMarketplaceListing?: (string | null) | undefined, isPublic?: boolean | undefined, contactEmail?: (string | null) | undefined, customHeading?: (string | null) | undefined}; export type PatchApiTrustCentersSlugIdArgs = {slugId: string, body: UpdateTrustCenterInput}; export type PatchApiTrustCentersSlugIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const bannerSetting = z.enum(["CUSTOM_IMAGE", "GRADIENT", "MINIMAL", "VANTA"]); export const trustCenter = z.object({id: z.string(), title: z.string().nullable(), companyDescription: z.string().nullable(), privacyPolicy: z.string().nullable(), awsMarketplaceListing: z.string().nullable(), customDomain: z.string().nullable(), isPublic: z.boolean(), bannerSetting: z.object({endColor: z.string().nullable(), startColor: z.string().nullable(), setting: bannerSetting.nullable()}), customTheme: z.object({secondary: z.string().nullable(), primary: z.string().nullable()}), contactEmail: z.string().nullable(), customHeading: z.string().nullable(), creationDate: z.string(), updatedDate: z.string()}); 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 }; /** * Update Trust Center * * PATCH /trust-centers/{slugId} */ export const patchApiTrustCentersSlugId = async (args: PatchApiTrustCentersSlugIdArgs, options?: PatchApiTrustCentersSlugIdOptions) => { const {baseUrl = "https://api.vanta.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/trust-centers/${encodeURIComponent(String(args.slugId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(trustCenter, await res.json()) };