import {z} from 'zod' export type CreateApiV1GuestsGuestIdNotesArgs = {guest_id: string, body: {id?: string | undefined, name?: string | undefined, alert?: boolean | undefined, created_date?: string | undefined, entity_name?: string | undefined, entity_pk?: number | undefined, is_private?: boolean | undefined, note_type?: ('0' | '2' | '3' | '4' | '8' | '10') | undefined, notes?: string | undefined, privacy_type?: ('2' | '3') | undefined}}; export type CreateApiV1GuestsGuestIdNotesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1GuestsGuestIdNotesResponse = z.object({id: z.string().optional(), is_private: z.boolean().optional(), alert: z.boolean().optional(), note_type: z.number().int().optional(), notes: z.string().optional(), center: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), added_by: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), created_date: z.string().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 a guest note * * POST /v1/guests/{guest_id}/notes */ export const createApiV1GuestsGuestIdNotes = async (args: CreateApiV1GuestsGuestIdNotesArgs, options?: CreateApiV1GuestsGuestIdNotesOptions) => { const {baseUrl = "https://api.zenoti.com", 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(/\/+$/, '')}/v1/guests/${encodeURIComponent(String(args.guest_id))}/notes${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(createApiV1GuestsGuestIdNotesResponse, await res.json()) };