import {z} from 'zod' export type AddressType = 0 | 1 | 2; export type GetApiApiV1OrganizationsOrganizationIdAddressesArgs = {organizationId: number, type?: AddressType | undefined}; export type GetApiApiV1OrganizationsOrganizationIdAddressesOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const objectReference = z.object({id: z.number().int().optional(), name: z.string().nullable().optional()}); export const addressType = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const address = z.object({id: z.string().nullable().optional(), organization: objectReference.optional(), name: z.string().nullable().optional(), completeAddress: z.string().nullable().optional(), street: z.string().nullable().optional(), zipCode: z.string().nullable().optional(), city: z.string().nullable().optional(), county: z.string().nullable().optional(), state: z.string().nullable().optional(), countryCode: z.string().nullable().optional(), primary: z.boolean().optional(), addressType: addressType.optional()}); export const getApiApiV1OrganizationsOrganizationIdAddressesResponse = z.array(address); 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 }; /** * GET /api/v1/organizations/{organizationId}/Addresses */ export const getApiApiV1OrganizationsOrganizationIdAddresses = async (args: GetApiApiV1OrganizationsOrganizationIdAddressesArgs, options: GetApiApiV1OrganizationsOrganizationIdAddressesOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/organizations/${encodeURIComponent(String(args.organizationId))}/Addresses${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV1OrganizationsOrganizationIdAddressesResponse, await res.json()) };