import {z} from 'zod' export type GetApiPublicTenantSlugVacancyPortalBrandingArgs = {publicTenantSlug: string}; export type GetApiPublicTenantSlugVacancyPortalBrandingOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const tenantBrandingLogoDto = z.object({light: z.string().nullable(), dark: z.string().nullable()}); export const tenantBrandingColorsDto = z.object({accent: z.string(), primary: z.string(), secondary: z.string()}); export const tenantBrandingTopbarLinkDto = z.object({name: z.string().min(1), url: z.string()}); export const tenantBrandingTopbarCtaButtonDto = z.object({name: z.string().min(1), url: z.string()}); export const tenantBrandingFooterSocialsDto = z.object({linkedinUrl: z.string().nullable(), twitterUrl: z.string().nullable(), facebookUrl: z.string().nullable(), instagramUrl: z.string().nullable(), githubUrl: z.string().nullable()}); export const tenantBrandingFooterPrivacyPolicyDto = z.object({label: z.string().min(1), url: z.string()}); export const tenantBrandingFooterDto = z.object({socials: tenantBrandingFooterSocialsDto, privacyPolicy: tenantBrandingFooterPrivacyPolicyDto.nullable()}); export const tenantBrandingStyleDto = z.object({name: z.string().min(1), companyUrl: z.string().nullable(), companyDescription: z.string().nullable(), logoUrl: tenantBrandingLogoDto.nullable(), faviconUrl: z.string().nullable(), colors: tenantBrandingColorsDto, topbarLinks: z.array(tenantBrandingTopbarLinkDto), topbarCtaButton: tenantBrandingTopbarCtaButtonDto.nullable(), footer: tenantBrandingFooterDto}); export const tenantBrandingConsentDto = z.object({disclaimer: z.string().nullable()}); export const tenantBrandingDto = z.object({branding: tenantBrandingStyleDto, consent: tenantBrandingConsentDto}); 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 job portal branding * * GET /{publicTenantSlug}/vacancy-portal/branding */ export const getApiPublicTenantSlugVacancyPortalBranding = async (args: GetApiPublicTenantSlugVacancyPortalBrandingArgs, options: GetApiPublicTenantSlugVacancyPortalBrandingOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.publicTenantSlug))}/vacancy-portal/branding${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(tenantBrandingDto, await res.json()) };