import {z} from 'zod' export type UpdateApiV1OpportunitiesOpportunityIdArgs = {opportunity_id: string, body: {center_id: string, opportunity_title?: string | undefined, opportunity_description?: string | undefined, opportunity_owner_id?: string | undefined, guest_id?: string | undefined, created_by_id?: string | undefined, priority_type_id?: string | undefined, status_id?: string | undefined, type?: string | undefined, followup_date?: string | undefined, expected_close_date?: string | undefined, listed_amount?: number | undefined, offered_amount?: number | undefined, optional_field1?: string | undefined, optional_field2?: string | undefined, optional_field3?: string | undefined, ticket_id?: string | undefined, change_guest_center?: boolean | undefined, disposition_id?: string | undefined, custom_fields?: string | undefined, lead_source?: ({id?: string | undefined, code?: string | undefined}) | undefined}}; export type UpdateApiV1OpportunitiesOpportunityIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV1OpportunitiesOpportunityIdResponse = z.object({success: z.boolean().optional(), message: 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 }; /** * Edit an opportunity * * PUT /v1/opportunities/{opportunity_id} */ export const updateApiV1OpportunitiesOpportunityId = async (args: UpdateApiV1OpportunitiesOpportunityIdArgs, options?: UpdateApiV1OpportunitiesOpportunityIdOptions) => { 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/opportunities/${encodeURIComponent(String(args.opportunity_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(updateApiV1OpportunitiesOpportunityIdResponse, await res.json()) };