import {z} from 'zod' export type Address = {country?: unknown | undefined, name_line?: string | undefined, premise?: string | undefined, sub_premise?: string | undefined, thoroughfare?: string | undefined, administrative_area?: unknown | undefined, sub_administrative_area?: string | undefined, locality?: string | undefined, dependent_locality?: string | undefined, postal_code?: string | undefined}; export type PatchApiOrganizationsOrganizationIdAddressArgs = {organization_id: unknown, body: Address}; export type PatchApiOrganizationsOrganizationIdAddressOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({country: z.string().optional(), name_line: z.string().optional(), premise: z.string().optional(), sub_premise: z.string().optional(), thoroughfare: z.string().optional(), administrative_area: z.string().optional(), sub_administrative_area: z.string().optional(), locality: z.string().optional(), dependent_locality: z.string().optional(), postal_code: 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 }; /** * Update address * * PATCH /organizations/{organization_id}/address */ export const patchApiOrganizationsOrganizationIdAddress = async (args: PatchApiOrganizationsOrganizationIdAddressArgs, options?: PatchApiOrganizationsOrganizationIdAddressOptions) => { const {baseUrl = "https://api.upsun.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(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.organization_id))}/address${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(address, await res.json()) };