import {z} from 'zod' export type MobileAppConfig = {tech_full_schedule_enabled?: boolean | undefined, messages_tab_enabled?: boolean | undefined, phonebook_tab_enabled?: boolean | undefined, sms_forwarding_enabled?: boolean | undefined, proposal_modules?: Array | undefined, envision_enabled?: boolean | undefined}; export type UpdateApiConfigurationsMobileAppOrganizationIdArgs = {organization_id: string, body: MobileAppConfig}; export type UpdateApiConfigurationsMobileAppOrganizationIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const mobileAppConfig = z.object({tech_full_schedule_enabled: z.boolean().optional(), messages_tab_enabled: z.boolean().optional(), phonebook_tab_enabled: z.boolean().optional(), sms_forwarding_enabled: z.boolean().optional(), proposal_modules: z.array(z.string()).optional(), envision_enabled: 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 }; /** * Update Mobile App Config * * PUT /configurations/mobile-app/{organization_id} */ export const updateApiConfigurationsMobileAppOrganizationId = async (args: UpdateApiConfigurationsMobileAppOrganizationIdArgs, options: UpdateApiConfigurationsMobileAppOrganizationIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/configurations/mobile-app/${encodeURIComponent(String(args.organization_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(mobileAppConfig, await res.json()) };