import {z} from 'zod' export type MasterTemplateSettingsInputModel = {headerLogoHeight?: (string | null) | undefined, footerLogoHeight?: (string | null) | undefined, headerLogoPadding?: (string | null) | undefined, footerLogoPadding?: (string | null) | undefined, emailBackgroundColor?: (string | null) | undefined, emailColor?: (string | null) | undefined, emailLinkColor?: (string | null) | undefined, panelBackgroundColor?: (string | null) | undefined, panelColor?: (string | null) | undefined, panelLinkColor?: (string | null) | undefined, contentBackgroundColor?: (string | null) | undefined, contentColor?: (string | null) | undefined, contentLinkColor?: (string | null) | undefined, showHeaderLogo?: (boolean | null) | undefined, showFooterLogo?: (boolean | null) | undefined, footerFontSize?: (string | null) | undefined, privacyPolicyLink?: (string | null) | undefined, showHeaderPanel?: (boolean | null) | undefined, showFooterPanel?: (boolean | null) | undefined, showContentPanel?: (boolean | null) | undefined, centerEmailContent?: (boolean | null) | undefined, centerEmailContentPanel?: (boolean | null) | undefined, centerEmailFooter?: (boolean | null) | undefined, footerPanelEmailContact?: (boolean | null) | undefined, footerPanelPhoneContact?: (boolean | null) | undefined, footerPanelWebsiteContact?: (boolean | null) | undefined}; export type CreateApiSetupV1LocationsIdEmailTemplatesMasterArgs = {id: string, body: MasterTemplateSettingsInputModel}; export type CreateApiSetupV1LocationsIdEmailTemplatesMasterOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const masterEmailTemplateSettingsViewModel = z.object({version: z.string().nullable().optional(), headerLogoHeight: z.string().nullable().optional(), footerLogoHeight: z.string().nullable().optional(), headerLogoPadding: z.string().nullable().optional(), footerLogoPadding: z.string().nullable().optional(), emailBackgroundColor: z.string().nullable().optional(), emailColor: z.string().nullable().optional(), emailLinkColor: z.string().nullable().optional(), panelBackgroundColor: z.string().nullable().optional(), panelColor: z.string().nullable().optional(), panelLinkColor: z.string().nullable().optional(), contentBackgroundColor: z.string().nullable().optional(), contentColor: z.string().nullable().optional(), contentLinkColor: z.string().nullable().optional(), showHeaderLogo: z.boolean().optional(), showFooterLogo: z.boolean().optional(), footerFontSize: z.string().nullable().optional(), privacyPolicyLink: z.string().nullable().optional(), showHeaderPanel: z.boolean().optional(), showFooterPanel: z.boolean().optional(), showContentPanel: z.boolean().optional(), centerEmailContent: z.boolean().optional(), centerEmailContentPanel: z.boolean().optional(), centerEmailFooter: z.boolean().optional(), footerPanelEmailContact: z.boolean().optional(), footerPanelPhoneContact: z.boolean().optional(), footerPanelWebsiteContact: z.boolean().optional()}); 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 }; /** * Create Master Template Settings * * POST /setup/v1/locations/{id}/email/templates/master */ export const createApiSetupV1LocationsIdEmailTemplatesMaster = async (args: CreateApiSetupV1LocationsIdEmailTemplatesMasterArgs, options?: CreateApiSetupV1LocationsIdEmailTemplatesMasterOptions) => { const {baseUrl = "https://sandbox-api.onsched.com", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/setup/v1/locations/${encodeURIComponent(String(args.id))}/email/templates/master${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(masterEmailTemplateSettingsViewModel, await res.json()) };