import {z} from 'zod' export type CompanyUpdateModel = {name?: (string | null) | undefined, registrationEmail?: (string | null) | undefined, addressLine1?: (string | null) | undefined, addressLine2?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, postalCode?: (string | null) | undefined, country?: (string | null) | undefined, phone?: (string | null) | undefined, fax?: (string | null) | undefined, email?: (string | null) | undefined, website?: (string | null) | undefined, timezoneName?: (string | null) | undefined, notificationFromEmailAddress?: (string | null) | undefined, notificationFromName?: (string | null) | undefined, bookingWebhookUrl?: (string | null) | undefined, customerWebhookUrl?: (string | null) | undefined, reminderWebhookUrl?: (string | null) | undefined, resourceWebhookUrl?: (string | null) | undefined, webhookSignatureHash?: (string | null) | undefined, disableEmailAndSmsNotifications?: (boolean | null) | undefined}; export type UpdateApiSetupV1CompaniesArgs = {body: CompanyUpdateModel}; export type UpdateApiSetupV1CompaniesOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const companyViewModel = z.object({object: z.string().nullable().optional(), id: z.string().nullable().optional(), name: z.string().nullable().optional(), registrationDate: z.string().nullable().optional(), registrationEmail: z.string().nullable().optional(), deletedStatus: z.boolean().optional(), deletedTime: z.string().nullable().optional(), addressLine1: z.string().nullable().optional(), addressLine2: z.string().nullable().optional(), city: z.string().nullable().optional(), state: z.string().nullable().optional(), postalCode: z.string().nullable().optional(), country: z.string().nullable().optional(), phone: z.string().nullable().optional(), fax: z.string().nullable().optional(), email: z.string().nullable().optional(), website: z.string().nullable().optional(), timezoneId: z.string().nullable().optional(), timezoneName: z.string().nullable().optional(), notificationFromEmailAddress: z.string().nullable().optional(), notificationFromName: z.string().nullable().optional(), clientId: z.string().nullable().optional(), clientSecret: z.string().nullable().optional(), bookingWebhookUrl: z.string().nullable().optional(), customerWebhookUrl: z.string().nullable().optional(), reminderWebhookUrl: z.string().nullable().optional(), resourceWebhookUrl: z.string().nullable().optional(), webhookSignatureHash: z.string().nullable().optional(), disableEmailAndSmsNotifications: 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 Company * * PUT /setup/v1/companies */ export const updateApiSetupV1Companies = async (args: UpdateApiSetupV1CompaniesArgs, options?: UpdateApiSetupV1CompaniesOptions) => { 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/companies${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(companyViewModel, await res.json()) };